mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Fix processing of percentiles on backend (#64540)
* Elasticsearch: Fix processing of percentiles on backend * Remove redundant logic as we do this in addMetricValue * Refactor for less cyclomatic complexity * Remove changes in createFieldsFromPropKeys
This commit is contained in:
parent
972e611f76
commit
a416235e8f
@ -599,13 +599,7 @@ func processAggregationDocs(esAgg *simplejson.Json, aggDef *BucketAgg, target *Q
|
||||
}
|
||||
sort.Strings(propKeys)
|
||||
frames := data.Frames{}
|
||||
var fields []*data.Field
|
||||
|
||||
if queryResult.Frames == nil {
|
||||
for _, propKey := range propKeys {
|
||||
fields = append(fields, data.NewField(propKey, nil, []*string{}))
|
||||
}
|
||||
}
|
||||
fields := createFieldsFromPropKeys(queryResult.Frames, propKeys)
|
||||
|
||||
addMetricValue := func(values []interface{}, metricName string, value *float64) {
|
||||
index := -1
|
||||
@ -631,22 +625,22 @@ func processAggregationDocs(esAgg *simplejson.Json, aggDef *BucketAgg, target *Q
|
||||
var values []interface{}
|
||||
|
||||
found := false
|
||||
for _, e := range fields {
|
||||
for _, field := range fields {
|
||||
for _, propKey := range propKeys {
|
||||
if e.Name == propKey {
|
||||
e.Append(props[propKey])
|
||||
if field.Name == propKey {
|
||||
field.Append(props[propKey])
|
||||
}
|
||||
}
|
||||
if e.Name == aggDef.Field {
|
||||
if field.Name == aggDef.Field {
|
||||
found = true
|
||||
if key, err := bucket.Get("key").String(); err == nil {
|
||||
e.Append(&key)
|
||||
field.Append(&key)
|
||||
} else {
|
||||
f, err := bucket.Get("key").Float64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
e.Append(&f)
|
||||
field.Append(&f)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -697,6 +691,12 @@ func processAggregationDocs(esAgg *simplejson.Json, aggDef *BucketAgg, target *Q
|
||||
addMetricValue(values, getMetricName(metric.Type), value)
|
||||
break
|
||||
}
|
||||
case percentilesType:
|
||||
percentiles := bucket.GetPath(metric.ID, "values")
|
||||
for percentileName := range percentiles.MustMap() {
|
||||
percentileValue := percentiles.Get(percentileName).MustFloat64()
|
||||
addMetricValue(values, fmt.Sprintf("p%v %v", percentileName, metric.Field), &percentileValue)
|
||||
}
|
||||
default:
|
||||
metricName := getMetricName(metric.Type)
|
||||
otherMetrics := make([]*MetricAgg, 0)
|
||||
@ -1119,3 +1119,13 @@ func setSearchWords(frame *data.Frame, searchWords map[string]bool) {
|
||||
"searchWords": searchWordsList,
|
||||
}
|
||||
}
|
||||
|
||||
func createFieldsFromPropKeys(frames data.Frames, propKeys []string) []*data.Field {
|
||||
var fields []*data.Field
|
||||
if frames == nil {
|
||||
for _, propKey := range propKeys {
|
||||
fields = append(fields, data.NewField(propKey, nil, []*string{}))
|
||||
}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
@ -1055,24 +1055,24 @@ func TestPercentilesWithoutDateHistogram(t *testing.T) {
|
||||
require.Len(t, frames, 1)
|
||||
requireFrameLength(t, frames[0], 2)
|
||||
|
||||
// require.Len(t, frames[0].Fields, 3) // FIXME
|
||||
require.Len(t, frames[0].Fields, 3)
|
||||
|
||||
// f1 := frames[0].Fields[0] // FIXME
|
||||
// f2 := frames[0].Fields[1] // FIXME
|
||||
// f3 := frames[0].Fields[2] // FIXME
|
||||
f1 := frames[0].Fields[0]
|
||||
f2 := frames[0].Fields[1]
|
||||
f3 := frames[0].Fields[2]
|
||||
|
||||
// require.Equal(t, "id", f1.Name) // FIXME
|
||||
// require.Equal(t, "p75 value", f2.Name) // FIXME
|
||||
// require.Equal(t, "p90 value", f3.Name) // FIXME
|
||||
require.Equal(t, "id", f1.Name)
|
||||
require.Equal(t, "p75 value", f2.Name)
|
||||
require.Equal(t, "p90 value", f3.Name)
|
||||
|
||||
// requireStringAt(t, "id1", f1, 0) // FIXME
|
||||
// requireStringAt(t, "id2", f1, 1) // FIXME
|
||||
requireStringAt(t, "id1", f1, 0)
|
||||
requireStringAt(t, "id2", f1, 1)
|
||||
|
||||
// requireFloatAt(t, 3.3, f2, 0) // FIXME
|
||||
// requireFloatAt(t, 2.3, f2, 1) // FIXME
|
||||
requireFloatAt(t, 3.3, f2, 0)
|
||||
requireFloatAt(t, 2.3, f2, 1)
|
||||
|
||||
// requireFloatAt(t, 5.5, f3, 0) // FIXME
|
||||
// requireFloatAt(t, 4.5, f3, 1) // FIXME
|
||||
requireFloatAt(t, 5.5, f3, 0)
|
||||
requireFloatAt(t, 4.5, f3, 1)
|
||||
}
|
||||
|
||||
func TestMultipleMetricsOfTheSameType(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user