persistence

package
v0.0.0-...-d983439 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSortField        = "pub_timestamp"
	PublishedTimestampField = "pub_timestamp"
	FeedEntryID             = "entity_uuid"
)
View Source
const (
	IndexNameFeeds = "eventfeed-" + feedsIndicesVersion + "-feeds"
)

Variables

View Source
var AllMappings = []Mapping{
	Feeds,
}
View Source
var Feeds = Mapping{
	Index:      IndexNameFeeds,
	Timeseries: false,
	Properties: fmt.Sprintf(`{ %s }`, feedProps),
	Mapping: fmt.Sprintf(`
			{
				"settings":{
					"number_of_shards": 5,
					"analysis": {
						"analyzer": {
							"autocomplete": {
								"filter": [
									"lowercase"
								],
								"tokenizer": "autocomplete_tokenizer"
							}
						},
						"tokenizer": {
							"autocomplete_tokenizer": {
								"max_gram": 20,
								"min_gram": 2,
								"token_chars": [
									"letter",
									"digit"
								],
								"type": "edge_ngram"
							}
						},
						"normalizer": {
							"case_insensitive": {
								"type": "custom",
								"char_filter": [],
								"filter": ["lowercase", "asciifolding"]
							}
						}
					},
					"index":{
							"refresh_interval":"1s"
					}
				},
				"mappings":{
						%s
				}
			}
		`, feedProps),
}

Feeds mapping used to create the feeds-[version] index

Functions

This section is empty.

Types

type ElasticFeedStore

type ElasticFeedStore struct {
	// contains filtered or unexported fields
}

func NewElasticFeedStore

func NewElasticFeedStore(client *olivere.Client) *ElasticFeedStore

func (ElasticFeedStore) CancelProjectUpdateTask

func (efs ElasticFeedStore) CancelProjectUpdateTask(ctx context.Context,
	projectUpdateID string, id project_update_lib.SerializedProjectUpdateTaskID) error

func (ElasticFeedStore) CreateFeedEntry

func (efs ElasticFeedStore) CreateFeedEntry(entry *feed.FeedEntry) (bool, error)

func (ElasticFeedStore) DeleteIndex

func (efs ElasticFeedStore) DeleteIndex(ctx context.Context, index string) error

DeleteIndex - delete index with name 'index'

func (ElasticFeedStore) DoesIndexExists

func (efs ElasticFeedStore) DoesIndexExists(ctx context.Context, indexName string) (bool, error)

DoesIndexExists - does the index 'indexName' exists in elasticsearch

func (ElasticFeedStore) GetActionLine

func (efs ElasticFeedStore) GetActionLine(formattedFilters map[string][]string, startDate string, endDate string, timezone string, interval int, action string) (*feed.ActionLine, error)

GetActionLine event_type filters start = "2018-01-20T00:00:00-08:00" RFC3339 format end = "2018-01-26T23:59:59-08:00" RFC3339 format The time zone is needed to start the time bucketing on the hour requested. Bucketing every 3 hours the buckets start at the beginning of the day. 0 - 3, 3 - 6, 6 - 9, 9 - 12, 12 - 15, 15 - 18, 18 - 21, 21 - 0 One can not have 3 hour buckets start at 02:00 or any time within the above buckets This can be fixed by setting the time zone. The bucket will start at the beginning of the day in that timezone. The Elastic Search request

{
  "aggregations": {
    "dateHisto": {
      "aggregations": {
        "items": {
          "terms": {
            "field": "entity_type"
          }
        }
      },
      "date_histogram": {
        "extended_bounds": {
          "max": "2018-01-26T23:59:59-08:00",
          "min": "2018-01-20T00:00:00-08:00"
        },
        "field": "recorded_at",
        "format": "yyyy-MM-dd'T'HH:mm:ssZ",
        "interval": "3h",
        "min_doc_count": 0,
        "time_zone": "-08:00"
      }
    }
  },
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "task": "delete"
          }
        },
        {
          "range": {
            "recorded_at": {
              "format": "yyyy-MM-dd||yyyy-MM-dd-HH:mm:ss||yyyy-MM-dd'T'HH:mm:ssZ",
              "from": "2018-01-20T00:00:00-08:00",
              "include_lower": true,
              "include_upper": true,
              "to": "2018-01-26T23:59:59-08:00"
            }
          }
        }
      ]
    }
  }
}

interval - 24 must be divisible by this number For example 1, 2, 3, 4, 6, 8, 12, and 24 are valid. Where 5, 7, 9, 10, 11, and 13 are not valid values.

func (ElasticFeedStore) GetFeed

func (efs ElasticFeedStore) GetFeed(query *feed.FeedQuery) ([]*feed.FeedEntry, int64, error)

GetFeed - get event feed entries with the provided query constraints

func (ElasticFeedStore) GetFeedSummary

func (efs ElasticFeedStore) GetFeedSummary(query *feed.FeedSummaryQuery) (map[string]int64, error)

func (ElasticFeedStore) InitializeStore

func (efs ElasticFeedStore) InitializeStore(ctx context.Context) error

InitializeStore runs the necessary initialization processes to make elasticsearch usable by creating the indices and aliases for documents to be added

func (ElasticFeedStore) JobCancel

func (efs ElasticFeedStore) JobCancel(ctx context.Context, jobID string) error

func (ElasticFeedStore) JobStatus

func (ElasticFeedStore) ListProjectUpdateTasks

func (ElasticFeedStore) ReindexFeedsToLatest

func (efs ElasticFeedStore) ReindexFeedsToLatest(ctx context.Context, previousIndex string) (string, error)

ReindexFeedsToLatest reindex the feed index to the latest index

func (ElasticFeedStore) RunProjectUpdateTask

func (ElasticFeedStore) UpdateProjectTags

func (efs ElasticFeedStore) UpdateProjectTags(
	ctx context.Context, projectTaggingRules map[string]*authz.ProjectRules) ([]string, error)

type FeedStore

type FeedStore interface {
	// @param (context, indexName)
	DeleteIndex(ctx context.Context, index string) error
	// @param (context, jobID)
	JobStatus(context.Context, string) (project_update_lib.JobStatus, error)
	// @param (context, indexName)
	DoesIndexExists(context.Context, string) (bool, error)
	// @param (context, previousIndex)
	ReindexFeedsToLatest(context.Context, string) (string, error)
	// @param (context)
	InitializeStore(context.Context) error
	CreateFeedEntry(entry *feed.FeedEntry) (bool, error)
	GetFeed(query *feed.FeedQuery) ([]*feed.FeedEntry, int64, error)
	GetFeedSummary(query *feed.FeedSummaryQuery) (map[string]int64, error)
	GetActionLine(filters map[string][]string, startDate string, endDate string, timezone string, interval int, action string) (*feed.ActionLine, error)

	JobCancel(context.Context, string) error
	UpdateProjectTags(context.Context, map[string]*authz.ProjectRules) ([]string, error)

	//SerializedProjectUpdate
	ListProjectUpdateTasks(ctx context.Context) ([]project_update_lib.SerializedProjectUpdateTask, error)
	RunProjectUpdateTask(ctx context.Context, projectUpdateID string, params map[string]string, projectTaggingRules map[string]*authz.ProjectRules) (project_update_lib.SerializedProjectUpdateTaskID, project_update_lib.SerializedProjectUpdateTaskStatus, error)
	MonitorProjectUpdateTask(ctx context.Context, projectUpdateID string, id project_update_lib.SerializedProjectUpdateTaskID) (project_update_lib.SerializedProjectUpdateTaskStatus, error)
	CancelProjectUpdateTask(ctx context.Context, projectUpdateID string, id project_update_lib.SerializedProjectUpdateTaskID) error
}

func NewFeedStore

func NewFeedStore(esClient *olivere.Client) FeedStore

type Mapping

type Mapping struct {
	Index      string
	Alias      string
	Timeseries bool
	Mapping    string
	Properties string
}

Mapping type is the representation of an ES mapping, it contains all the necessary fields you need to create a mapping and to insert documents to it

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL