elastic

package
v0.0.0-...-05bb4c1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Elasticsearch indexes
	IndexNodeState           = "node-state"
	IndexNodeAttribute       = "node-attribute"
	IndexConvergeHistoryBase = "converge-history-"
	IndexConvergeHistory     = "converge-history-*"

	// Elasticsearch fields we use within this package
	RunFieldTimestamp    = "start_time"
	RunFieldEndTimestamp = "end_time"
	ActionFieldTimestamp = "recorded_at"
	ActionFieldID        = "id"
	NodeFieldID          = "entity_uuid"
	RunFieldID           = "run_id"
	NodeCheckin          = "checkin"
	SuggestionSize       = 10
	SuggestionQuerySize  = 100
)

Variables

This section is empty.

Functions

func EmptyStringIfNil

func EmptyStringIfNil(attribute interface{}) string

EmptyStringIfNil asserts an interface as a string, and if that fails it returns empty string

func LogQueryPartMin

func LogQueryPartMin(indices string, partToPrint interface{}, name string)

Types

type Backend

type Backend struct {
	Url string `json:"url"`
	// contains filtered or unexported fields
}

Backend

The elasticsearch backend model that implements the 'backend.Client' interface

func Default

func Default() Backend

func New

func New(url string) *Backend

Initialize an Elastic instance

This verifies the connectivity with Elasticsearch; if we couldn't connect, we do not start the service and print an error message

func (Backend) GetAttribute

func (es Backend) GetAttribute(nodeID string) (backend.NodeAttribute, error)

GetAttribute Get request for the attribute using the Doc ID

func (Backend) GetCheckinCountsTimeSeries

func (es Backend) GetCheckinCountsTimeSeries(startTime, endTime time.Time,
	filters map[string][]string) ([]backend.CountPeroid, error)

GetCheckinCountsTimeSeries create a daily time series of unique nodes that have reported a runs between the startTime and endTime provided. The startTime and endTime must at least be 24 hours apart. When greater than 24 hours, it must be in multiples 24 hour blocks.

func (Backend) GetCreateCountsTimeSeries

func (es Backend) GetCreateCountsTimeSeries(startTime, endTime time.Time,
	filters map[string][]string) ([]backend.CountPeroid, error)

GetCreateCountsTimeSeries - creates a daily time series of the total amount of nodes that have been created within or before the time range. The time series is between the startTime and endTime provided. The startTime and endTime must at least be 24 hours apart. When greater than 24 hours, it must be in multiples 24 hour blocks.

func (Backend) GetDateOfOldestConvergeIndices

func (es Backend) GetDateOfOldestConvergeIndices() (time.Time, bool, error)

GetDateOfOldestConvergeIndices - Find the date of the oldest converge history index. If there is no converge history indices returns false on the second return value.

func (Backend) GetDeletedCountsTimeSeries

func (es Backend) GetDeletedCountsTimeSeries(
	startTime, endTime time.Time, filters map[string][]string) ([]backend.CountPeroid, error)

GetDeletedCountsTimeSeries - creates a daily time series of the total amount of nodes that have been deleted within or before the time range. The time series is between the startTime and endTime provided. The startTime and endTime must at least be 24 hours apart. When greater than 24 hours, it must be in multiples 24 hour blocks. A node is deleted if exists = false. The time the node was deleted is the "timestamp"

func (Backend) GetErrors

func (es Backend) GetErrors(size int32, filters map[string][]string) ([]*backend.ChefErrorCount, error)

func (Backend) GetInventoryNodes

func (es Backend) GetInventoryNodes(ctx context.Context, start time.Time,
	end time.Time, filters map[string][]string, cursorDate time.Time,
	cursorID string, pageSize int, _ string,
	ascending bool) ([]backend.InventoryNode, error)

GetInventoryNodes - Collect inventory nodes from elasticsearch. This function allows non-random access pagination and custom selection of how the docs are sorted.

TODO(ssd) 2019-04-23: The sortField argument is ignored in this call. The linter pointed out that it was previously ignored and an attempt to not ignore it caused multiple tests to fail.

func (Backend) GetLatestRunRolloutBreakdownCounts

func (es Backend) GetLatestRunRolloutBreakdownCounts() (*b.NodeSegmentRolloutProgress, error)

func (Backend) GetListForField

func (es Backend) GetListForField(searchTerm string, filters map[string][]string) ([]string, error)

GetListForField - collect a set of unique field values

Elasticsearch query example, with "organization_name":

{
	"query":
		{ "bool":
			{"filter":
				{"term":
					{"exists": "true"}
				}
			}
		},
	"aggs":
		{"grouping":
			{"terms":
				{"field": "organization_name"}
			}
		}
	}

func (Backend) GetMissingNodeDurationCounts

func (es Backend) GetMissingNodeDurationCounts(durations []string) ([]backend.CountedDuration, error)

func (Backend) GetNodeMetadataCounts

func (es Backend) GetNodeMetadataCounts(filters map[string][]string,
	types []string, startDate, endDate string) ([]backend.TypeCount, error)

GetNodeMetadataCounts - For each type of field provided return distinct values the amount for each. For example, if the 'platform' field is requested 'windows' 10, 'redhat' 5, and 'ubuntu' 8 could be returned. The number next to each represents the number of nodes with that type of platform.

Filters of the same type as the aggregation are removed. For example, if there is a filter of type platform:'windows' and the type 'platform' is requested the filter platform:'windows' will be removed.

func (Backend) GetNodeRunsDailyStatusTimeSeries

func (es Backend) GetNodeRunsDailyStatusTimeSeries(nodeID string, startTime,
	endTime time.Time) ([]backend.RunDurationStatus, error)

This function provides the status of runs for each 24-hour duration. For multiple runs in one 24-hour duration, the most recent failed run will be returned. If there are no failed runs the most recent successful run will be returned. If no runs are found in the 24-hour duration, the status will be "missing" and no run will be returned.

func (Backend) GetNodes

func (es Backend) GetNodes(page int, perPage int, sortField string,
	ascending bool, filters map[string][]string, startDate, endDate string) ([]backend.Node, error)

GetNodes This function implements pagination that is being handle by elasticsearch by passing the `from` & `size` parameters

@param [order] The sort order asc or desc @param [page] The page number to return @param [perPage] Number of nodes to return @param sort The field to sort on @param [filters] The filters to apply to our ES query @return An array of backend.Node

The ES query we use is:

{
  "sort": [{$sort:{"order":$order}}],
  "from": $start,
  "size": $perPage,
  "query":{
    "bool":{
      "filter":{
        "term":{
          "exists":"true"
        }
      }
    }
  }
}

func (Backend) GetNodesCounts

func (es Backend) GetNodesCounts(filters map[string][]string,
	startDate string, endDate string) (backend.NodesCounts, error)

GetNodesCounts - get the number of successful, failure, and missing nodes

func (Backend) GetNodesPageByCursor

func (es Backend) GetNodesPageByCursor(ctx context.Context, start time.Time,
	end time.Time, filters map[string][]string, cursorValue interface{},
	cursorID string, pageSize int, sortField string,
	ascending bool) ([]backend.Node, error)

func (Backend) GetRun

func (es Backend) GetRun(runID string, endTime time.Time) (backend.Run, error)

GetRun - Get a node's last run

@param [run_id] The id of the node's last run @param [last_ccr] The time of the node's last CCR, used for index determination @return The run object

The ES query we use is:

{
  "query":{
    "bool":{
      "must": {
        "term":{
          "run_id":"5ad11e7e-c185-4b80-8a16-167e257b30d1"
        }
      }
    }
  }
}

func (Backend) GetRuns

func (es Backend) GetRuns(nodeID string, page int, perPage int, filters map[string][]string, start string, end string) ([]backend.AbridgedConverge, error)

GetRuns - get a collection of abridged runs

func (Backend) GetRunsCounts

func (es Backend) GetRunsCounts(filters map[string][]string, nodeID string, start string,
	end string) (backend.RunsCounts, error)

GetRunsCounts returns a RunsCounts object that contains the number of success, failure, total runs for a node

func (Backend) GetRunsPageByCursor

func (es Backend) GetRunsPageByCursor(ctx context.Context, nodeID string, start time.Time,
	end time.Time, filters map[string][]string, cursorEndTime time.Time,
	cursorID string, pageSize int, ascending bool) ([]backend.Run, error)

func (Backend) GetSuggestions

func (es Backend) GetSuggestions(term string, text string, filters map[string][]string) ([]backend.Suggestion, error)

GetSuggestions - get a collection of suggestions

func (Backend) GetUniqueNodesCount

func (es Backend) GetUniqueNodesCount(daysSinceLastPost int64, lastTelemetryReportedAt time.Time) (int64, error)

GetUniqueNodesCount: Get the unique nodes count based on the lastTelemetryReportedAt

func (Backend) NodeExists

func (es Backend) NodeExists(nodeID string, filters map[string][]string) (bool, error)

NodeExists - Does a node with entity_uuid == 'nodeID' exists

type DateRangeAggregation

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

DateRangeAggregation is a range aggregation that is dedicated for date values. The main difference between this aggregation and the normal range aggregation is that the from and to values can be expressed in Date Math expressions, and it is also possible to specify a date format by which the from and to response fields will be returned. Note that this aggregation includes the from value and excludes the to value for each range. See: https://www.elastic.co/guide/en/elasticsearch/reference/7.0/search-aggregations-bucket-daterange-aggregation.html

func NewDateRangeAggregation

func NewDateRangeAggregation() *DateRangeAggregation

func (*DateRangeAggregation) AddRange

func (a *DateRangeAggregation) AddRange(from, to interface{}) *DateRangeAggregation

func (*DateRangeAggregation) AddRangeWithKey

func (a *DateRangeAggregation) AddRangeWithKey(key string, from, to interface{}) *DateRangeAggregation

func (*DateRangeAggregation) AddUnboundedFrom

func (a *DateRangeAggregation) AddUnboundedFrom(to interface{}) *DateRangeAggregation

func (*DateRangeAggregation) AddUnboundedFromWithKey

func (a *DateRangeAggregation) AddUnboundedFromWithKey(key string, to interface{}) *DateRangeAggregation

func (*DateRangeAggregation) AddUnboundedTo

func (a *DateRangeAggregation) AddUnboundedTo(from interface{}) *DateRangeAggregation

func (*DateRangeAggregation) AddUnboundedToWithKey

func (a *DateRangeAggregation) AddUnboundedToWithKey(key string, from interface{}) *DateRangeAggregation

func (*DateRangeAggregation) Between

func (a *DateRangeAggregation) Between(from, to interface{}) *DateRangeAggregation

func (*DateRangeAggregation) BetweenWithKey

func (a *DateRangeAggregation) BetweenWithKey(key string, from, to interface{}) *DateRangeAggregation

func (*DateRangeAggregation) Field

func (*DateRangeAggregation) Format

func (*DateRangeAggregation) Gt

func (a *DateRangeAggregation) Gt(from interface{}) *DateRangeAggregation

func (*DateRangeAggregation) GtWithKey

func (a *DateRangeAggregation) GtWithKey(key string, from interface{}) *DateRangeAggregation

func (*DateRangeAggregation) Keyed

func (*DateRangeAggregation) Lt

func (a *DateRangeAggregation) Lt(to interface{}) *DateRangeAggregation

func (*DateRangeAggregation) LtWithKey

func (a *DateRangeAggregation) LtWithKey(key string, to interface{}) *DateRangeAggregation

func (*DateRangeAggregation) Meta

func (a *DateRangeAggregation) Meta(metaData map[string]interface{}) *DateRangeAggregation

Meta sets the meta data to be included in the aggregation response.

func (*DateRangeAggregation) Missing

func (a *DateRangeAggregation) Missing(missing string) *DateRangeAggregation

custom addition

func (*DateRangeAggregation) Script

func (*DateRangeAggregation) Source

func (a *DateRangeAggregation) Source() (interface{}, error)

func (*DateRangeAggregation) SubAggregation

func (a *DateRangeAggregation) SubAggregation(name string, subAggregation elastic.Aggregation) *DateRangeAggregation

func (*DateRangeAggregation) TimeZone

func (a *DateRangeAggregation) TimeZone(timeZone string) *DateRangeAggregation

func (*DateRangeAggregation) Unmapped

func (a *DateRangeAggregation) Unmapped(unmapped bool) *DateRangeAggregation

type DateRangeAggregationEntry

type DateRangeAggregationEntry struct {
	Key  string
	From interface{}
	To   interface{}
}

type LatestStatusBucket

type LatestStatusBucket struct {
	Date   float64
	Status string
	RunID  string
}

Jump to

Keyboard shortcuts

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