insight

package
v1.30.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AggFuncCount                      = "count"
	AggFuncAvg                        = "avg"
	AggFuncSum                        = "sum"
	AggFuncMin                        = "min"
	AggFuncMax                        = "max"
	AggFuncMedium                     = "medium"
	AggFuncValueCount                 = "value_count"
	AggFuncCardinality                = "cardinality"
	AggFuncDerivative                 = "derivative"
	AggFuncRate                       = "rate"
	AggFuncPercent99                  = "p99"
	AggFuncPercent95                  = "p95"
	AggFuncPercent90                  = "p90"
	AggFuncPercent80                  = "p80"
	AggFuncPercent50                  = "p50"
	AggFuncLatest                     = "latest"
	AggFuncLatency                    = "latency"
	AggFuncSumFuncValueInGroup        = "sum_func_value_in_group"
	AggFuncRateSumFuncValueInGroup    = "rate_sum_func_value_in_group"
	AggFuncLatencySumFuncValueInGroup = "latency_sum_func_value_in_group"
	AggFuncPercentage                 = "percentage"
)

Variables

This section is empty.

Functions

func GenerateQuery

func GenerateQuery(metric *Metric) (interface{}, error)

func GetGroupValues

func GetGroupValues(grpInfos []MetricDataGroup) []string

func RegisterDerivedAggregation

func RegisterDerivedAggregation(aggregation DerivedAggregation)

RegisterDerivedAggregation registers a new derived aggregation in the registry. If an aggregation with the same name already exists, it panics. This is to ensure that each derived aggregation has a unique name. It is recommended to call this function during the initialization phase of the application. This function should be called only once for each derived aggregation.

Types

type BucketLabel

type BucketLabel struct {
	Enabled  bool   `json:"enabled"`
	Template string `json:"template,omitempty"`
}

type DerivedAggregation

type DerivedAggregation interface {
	// GetName returns the name of the derived aggregation.
	GetName() string
	// Calculate performs the aggregation calculation.
	// It takes a Metric and a search result map, and appends the results to the
	// provided metricData slice.
	// Returns an error if the calculation fails.
	Calculate(metric *Metric, searchResult map[string]interface{}, metricData *[]MetricData) error
}

func GetDerivedAggregation

func GetDerivedAggregation(name string) (DerivedAggregation, bool)

GetDerivedAggregation retrieves a derived aggregation by its name.

type Function

type Function interface {
	//GenerateAggregation generates aggregation for specify function, e.g. rate, latency ...
	//
	// metricName: The name of the metric to be calculated (used as an identifier in the aggregation).
	GenerateAggregation(metricName string) (map[string]interface{}, error)
}

type GroupSort

type GroupSort struct {
	Key       string `json:"key"`
	Direction string `json:"direction"`
}

type Metric

type Metric struct {
	AggTypes     []string          `json:"agg_types,omitempty"`
	IndexPattern string            `json:"index_pattern,omitempty"`
	TimeField    string            `json:"time_field,omitempty"`
	BucketSize   string            `json:"bucket_size,omitempty"`
	Filter       interface{}       `json:"filter,omitempty"`
	Groups       []MetricGroupItem `json:"groups,omitempty"` //bucket group
	Sort         []GroupSort       `json:"sort,omitempty"`
	ClusterId    string            `json:"cluster_id,omitempty"`
	Formula      string            `json:"formula,omitempty"`
	//array of formula for new version
	Formulas        []string     `json:"formulas,omitempty"`
	Items           []MetricItem `json:"items"`
	FormatType      string       `json:"format,omitempty"`
	TimeFilter      interface{}  `json:"time_filter,omitempty"`
	TimeBeforeGroup bool         `json:"time_before_group,omitempty"`
	BucketLabel     *BucketLabel `json:"bucket_label,omitempty"`
	// number of buckets to return, used for aggregation auto_date_histogram when bucket size equals 'auto'
	Buckets uint   `json:"buckets,omitempty"`
	Unit    string `json:"unit,omitempty"`
}

func (*Metric) AutoTimeBeforeGroup

func (m *Metric) AutoTimeBeforeGroup() bool

AutoTimeBeforeGroup determines if date aggregation should be applied before terms aggregation. Returns false if the metric uses any of the specified aggregation functions.

func (*Metric) GenerateExpression

func (m *Metric) GenerateExpression() (string, error)

func (*Metric) GetDerivedAggregations

func (m *Metric) GetDerivedAggregations() []string

GetDerivedAggregations returns a list of derived aggregation names that are supported by the metric. It checks the metric items against a predefined set of derived aggregation types. The derived aggregation types are defined in the constant AggFuncPercentage.

func (*Metric) UseBucketSort

func (m *Metric) UseBucketSort() bool

UseBucketSort determines whether bucket sorting should be used for aggregation. Returns false if the metric contains specific aggregation functions that require alternative handling.

func (*Metric) ValidateSortKey

func (m *Metric) ValidateSortKey() error

type MetricData

type MetricData struct {
	Groups     []MetricDataGroup `json:"groups,omitempty"`
	Data       map[string][]MetricDataItem
	GroupLabel string `json:"group_label,omitempty"`
}

func CollectMetricData

func CollectMetricData(metric *Metric, searchResult map[string]interface{}) ([]MetricData, string)

CollectMetricData collects metric data from the search result based on the metric definition. It processes the aggregations and returns a slice of MetricData along with the interval string.

func MergeGroupValues

func MergeGroupValues(metricData []MetricData) []MetricData

type MetricDataGroup

type MetricDataGroup struct {
	Value    string `json:"value"`
	DocCount uint32 `json:"doc_count,omitempty"`
}

type MetricDataItem

type MetricDataItem struct {
	Timestamp interface{} `json:"timestamp,omitempty"`
	Value     interface{} `json:"value"`
	// legacy group values
	// Groups is a list of group values for this item, used for legacy support
	Groups     []string          `json:"groups,omitempty"`
	GroupInfos []MetricDataGroup `json:"-"`
	GroupLabel string            `json:"group_label,omitempty"`
	// DocCount is the count of documents in the bucket
	DocCount uint32 `json:"doc_count,omitempty"`
	// TimeBucketDocCount is the count of documents in the time bucket
	TimeBucketDocCount uint32 `json:"time_bucket_doc_count,omitempty"`
}

func (*MetricDataItem) MarshalJSON

func (m *MetricDataItem) MarshalJSON() ([]byte, error)

type MetricGroupItem

type MetricGroupItem struct {
	Field string `json:"field"`
	Limit int    `json:"limit"`
}

type MetricItem

type MetricItem struct {
	Name      string `json:"name,omitempty"`
	Field     string `json:"field"`
	FieldType string `json:"field_type,omitempty"`
	Statistic string `json:"statistic,omitempty"`

	//Function specifies the calculation details for the metric,
	//including the aggregation type and any associated parameters.
	Function map[string]interface{} `json:"function,omitempty"`
}

type PercentageAggregation

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

func (*PercentageAggregation) Calculate

func (p *PercentageAggregation) Calculate(metric *Metric, searchResult map[string]interface{}, metricData *[]MetricData) error

Calculate implements the PercentageAggregation calculation. It calculates the percentage of each item in the metric data based on the total document count. It updates the metric data with the calculated percentage values. The calculation is based on the document count of each item relative to the total document count. If the metric has a time field and is grouped by time, it uses the document count of the parent time bucket as the total document count. The percentage is calculated as (item's doc_count / total_doc_count) * 100. The result is stored in the Value field of each MetricDataItem in the metric data. The percentage is rounded to two decimal places. It returns an error if the calculation fails.

func (*PercentageAggregation) GetName

func (p *PercentageAggregation) GetName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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