Elasticsearch: Fix processing of duplicated metric types and field (#66973)

* Elasticsearch: Fix processing of duplicated metric types and field

* Fix lint

* Fix linting
This commit is contained in:
Ivana Huckova
2023-04-24 17:26:04 +02:00
committed by GitHub
parent 3c655821e8
commit e2e243d1b6
2 changed files with 61 additions and 2 deletions

View File

@@ -1255,13 +1255,24 @@ func addOtherMetricsToFields(fields *[]*data.Field, bucket *simplejson.Json, met
otherMetrics := make([]*MetricAgg, 0)
for _, m := range target.Metrics {
if m.Type == metric.Type {
// To other metrics we add metric of the same type that are not the current metric
if m.ID != metric.ID && m.Type == metric.Type {
otherMetrics = append(otherMetrics, m)
}
}
if len(otherMetrics) > 1 {
if len(otherMetrics) > 0 {
metricName += " " + metric.Field
// We check if we have metric with the same type and same field name
// If so, append metric.ID to the metric name
for _, m := range otherMetrics {
if m.Field == metric.Field {
metricName += " " + metric.ID
break
}
}
if metric.Type == "bucket_script" {
// Use the formula in the column name
metricName = metric.Settings.Get("script").MustString("")