2018-03-23 10:50:16 -05:00
|
|
|
package elasticsearch
|
|
|
|
|
|
|
|
import (
|
2018-03-26 06:48:57 -05:00
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2018-03-23 10:50:16 -05:00
|
|
|
)
|
|
|
|
|
2018-05-23 08:09:58 -05:00
|
|
|
// Query represents the time series query model of the datasource
|
|
|
|
type Query struct {
|
|
|
|
TimeField string `json:"timeField"`
|
|
|
|
RawQuery string `json:"query"`
|
|
|
|
BucketAggs []*BucketAgg `json:"bucketAggs"`
|
|
|
|
Metrics []*MetricAgg `json:"metrics"`
|
|
|
|
Alias string `json:"alias"`
|
|
|
|
Interval string
|
2021-07-15 09:45:59 -05:00
|
|
|
IntervalMs int64
|
2018-05-23 08:09:58 -05:00
|
|
|
RefID string
|
|
|
|
}
|
|
|
|
|
|
|
|
// BucketAgg represents a bucket aggregation of the time series query model of the datasource
|
2018-03-27 12:42:25 -05:00
|
|
|
type BucketAgg struct {
|
|
|
|
Field string `json:"field"`
|
|
|
|
ID string `json:"id"`
|
|
|
|
Settings *simplejson.Json `json:"settings"`
|
|
|
|
Type string `jsons:"type"`
|
|
|
|
}
|
|
|
|
|
2018-05-23 08:09:58 -05:00
|
|
|
// MetricAgg represents a metric aggregation of the time series query model of the datasource
|
|
|
|
type MetricAgg struct {
|
2018-11-16 09:54:25 -06:00
|
|
|
Field string `json:"field"`
|
|
|
|
Hide bool `json:"hide"`
|
|
|
|
ID string `json:"id"`
|
|
|
|
PipelineAggregate string `json:"pipelineAgg"`
|
|
|
|
PipelineVariables map[string]string `json:"pipelineVariables"`
|
|
|
|
Settings *simplejson.Json `json:"settings"`
|
|
|
|
Meta *simplejson.Json `json:"meta"`
|
|
|
|
Type string `json:"type"`
|
2018-03-27 12:42:25 -05:00
|
|
|
}
|
|
|
|
|
2018-05-23 08:09:58 -05:00
|
|
|
var metricAggType = map[string]string{
|
|
|
|
"count": "Count",
|
|
|
|
"avg": "Average",
|
|
|
|
"sum": "Sum",
|
|
|
|
"max": "Max",
|
|
|
|
"min": "Min",
|
|
|
|
"extended_stats": "Extended Stats",
|
|
|
|
"percentiles": "Percentiles",
|
2021-06-04 05:07:59 -05:00
|
|
|
"top_metrics": "Top Metrics",
|
2018-05-23 08:09:58 -05:00
|
|
|
"cardinality": "Unique Count",
|
|
|
|
"moving_avg": "Moving Average",
|
2020-11-11 11:42:28 -06:00
|
|
|
"moving_fn": "Moving Function",
|
2020-06-01 16:55:15 -05:00
|
|
|
"cumulative_sum": "Cumulative Sum",
|
2018-05-23 08:09:58 -05:00
|
|
|
"derivative": "Derivative",
|
2021-01-08 05:52:23 -06:00
|
|
|
"serial_diff": "Serial Difference",
|
2018-11-16 09:54:25 -06:00
|
|
|
"bucket_script": "Bucket Script",
|
2018-05-23 08:09:58 -05:00
|
|
|
"raw_document": "Raw Document",
|
2021-06-28 05:55:31 -05:00
|
|
|
"rate": "Rate",
|
2018-03-23 10:50:16 -05:00
|
|
|
}
|
|
|
|
|
2018-05-23 08:09:58 -05:00
|
|
|
var extendedStats = map[string]string{
|
|
|
|
"avg": "Avg",
|
|
|
|
"min": "Min",
|
|
|
|
"max": "Max",
|
|
|
|
"sum": "Sum",
|
|
|
|
"count": "Count",
|
|
|
|
"std_deviation": "Std Dev",
|
|
|
|
"std_deviation_bounds_upper": "Std Dev Upper",
|
|
|
|
"std_deviation_bounds_lower": "Std Dev Lower",
|
2018-03-23 10:50:16 -05:00
|
|
|
}
|
|
|
|
|
2018-05-23 08:09:58 -05:00
|
|
|
var pipelineAggType = map[string]string{
|
2020-06-01 16:55:15 -05:00
|
|
|
"moving_avg": "moving_avg",
|
2020-11-11 11:42:28 -06:00
|
|
|
"moving_fn": "moving_fn",
|
2020-06-01 16:55:15 -05:00
|
|
|
"cumulative_sum": "cumulative_sum",
|
|
|
|
"derivative": "derivative",
|
2021-01-08 05:52:23 -06:00
|
|
|
"serial_diff": "serial_diff",
|
2020-06-01 16:55:15 -05:00
|
|
|
"bucket_script": "bucket_script",
|
2018-11-16 09:54:25 -06:00
|
|
|
}
|
|
|
|
|
2021-05-14 05:50:15 -05:00
|
|
|
var scriptableAggType = map[string]string{
|
|
|
|
"avg": "avg",
|
|
|
|
"sum": "sum",
|
|
|
|
"max": "max",
|
|
|
|
"min": "min",
|
|
|
|
"extended_stats": "extended_stats",
|
|
|
|
"percentiles": "percentiles",
|
|
|
|
"bucket_script": "bucket_script",
|
|
|
|
}
|
|
|
|
|
2018-11-16 09:54:25 -06:00
|
|
|
var pipelineAggWithMultipleBucketPathsType = map[string]string{
|
|
|
|
"bucket_script": "bucket_script",
|
2018-03-23 10:50:16 -05:00
|
|
|
}
|
|
|
|
|
2018-05-23 08:09:58 -05:00
|
|
|
func isPipelineAgg(metricType string) bool {
|
|
|
|
if _, ok := pipelineAggType[metricType]; ok {
|
|
|
|
return true
|
2018-03-23 10:50:16 -05:00
|
|
|
}
|
2018-05-23 08:09:58 -05:00
|
|
|
return false
|
|
|
|
}
|
2018-03-23 10:50:16 -05:00
|
|
|
|
2021-05-14 05:50:15 -05:00
|
|
|
func isMetricAggregationWithInlineScriptSupport(metricType string) bool {
|
|
|
|
if _, ok := scriptableAggType[metricType]; ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-11-16 09:54:25 -06:00
|
|
|
func isPipelineAggWithMultipleBucketPaths(metricType string) bool {
|
|
|
|
if _, ok := pipelineAggWithMultipleBucketPathsType[metricType]; ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-05-23 08:09:58 -05:00
|
|
|
func describeMetric(metricType, field string) string {
|
|
|
|
text := metricAggType[metricType]
|
2018-11-15 12:06:47 -06:00
|
|
|
if metricType == countType {
|
|
|
|
return text
|
|
|
|
}
|
2018-05-23 08:09:58 -05:00
|
|
|
return text + " " + field
|
2018-03-23 10:50:16 -05:00
|
|
|
}
|