Documentation
¶
Index ¶
- Constants
- func GenerateQuery(metric *Metric) (interface{}, error)
- func GetGroupValues(grpInfos []MetricDataGroup) []string
- func RegisterDerivedAggregation(aggregation DerivedAggregation)
- type BucketLabel
- type DerivedAggregation
- type Function
- type GroupSort
- type Metric
- type MetricData
- type MetricDataGroup
- type MetricDataItem
- type MetricGroupItem
- type MetricItem
- type PercentageAggregation
Constants ¶
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 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 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 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 ¶
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 (*Metric) GetDerivedAggregations ¶
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 ¶
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 ¶
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 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 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