Expressions: sort numeric metrics behind feature toggle (#85911)

* feat: sort numeric metrics behind feature toggle

* chore: upgrade `dataplane/sdata` to latest tag

* chore: `go work sync`
This commit is contained in:
Nick Richmond
2024-04-16 10:52:47 -04:00
committed by GitHub
parent 036f826b87
commit d3fee607e2
12 changed files with 46 additions and 12 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ func (c *ResultConverter) Convert(ctx context.Context,
dt, useDataplane, _ := shouldUseDataplane(frames, logger, c.Features.IsEnabled(ctx, featuremgmt.FlagDisableSSEDataplane))
if useDataplane {
logger.Debug("Handling SSE data source query through dataplane", "datatype", dt)
result, err := handleDataplaneFrames(ctx, c.Tracer, dt, frames)
result, err := handleDataplaneFrames(ctx, c.Tracer, c.Features, dt, frames)
return fmt.Sprintf("dataplane-%s", dt), result, err
}
+8 -3
View File
@@ -13,6 +13,7 @@ import (
"github.com/grafana/grafana/pkg/expr/mathexp"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"go.opentelemetry.io/otel/attribute"
)
@@ -58,7 +59,7 @@ func shouldUseDataplane(frames data.Frames, logger log.Logger, disable bool) (dt
return dt, true, nil
}
func handleDataplaneFrames(ctx context.Context, tracer tracing.Tracer, t data.FrameType, frames data.Frames) (mathexp.Results, error) {
func handleDataplaneFrames(ctx context.Context, tracer tracing.Tracer, features featuremgmt.FeatureToggles, t data.FrameType, frames data.Frames) (mathexp.Results, error) {
_, span := tracer.Start(ctx, "SSE.HandleDataPlaneData")
defer span.End()
span.SetAttributes(attribute.String("dataplane.type", string(t)))
@@ -69,7 +70,8 @@ func handleDataplaneFrames(ctx context.Context, tracer tracing.Tracer, t data.Fr
case data.KindTimeSeries:
return handleDataplaneTimeseries(frames)
case data.KindNumeric:
return handleDataplaneNumeric(frames)
sortMetrics := !features.IsEnabled(ctx, featuremgmt.FlagDisableNumericMetricsSortingInExpressions)
return handleDataplaneNumeric(frames, sortMetrics)
default:
return mathexp.Results{}, fmt.Errorf("kind %s (type %s) not supported by server side expressions", t.Kind(), t)
}
@@ -105,7 +107,7 @@ func handleDataplaneTimeseries(frames data.Frames) (mathexp.Results, error) {
return res, nil
}
func handleDataplaneNumeric(frames data.Frames) (mathexp.Results, error) {
func handleDataplaneNumeric(frames data.Frames, sortMetrics bool) (mathexp.Results, error) {
dn, err := numeric.CollectionReaderFromFrames(frames)
if err != nil {
return mathexp.Results{}, err
@@ -122,6 +124,9 @@ func handleDataplaneNumeric(frames data.Frames) (mathexp.Results, error) {
}
return mathexp.Results{Values: mathexp.Values{noData}}, nil
}
if sortMetrics {
numeric.SortNumericMetricRef(nc.Refs)
}
res := mathexp.Results{}
res.Values = make([]mathexp.Value, 0, len(nc.Refs))
for _, n := range nc.Refs {
+2 -2
View File
@@ -192,7 +192,7 @@ func TestHandleDataplaneNumeric(t *testing.T) {
for _, example := range validNoDataNumericExamples.AsSlice() {
t.Run(example.Info().ID, func(t *testing.T) {
res, err := handleDataplaneNumeric(example.Frames("A"))
res, err := handleDataplaneNumeric(example.Frames("A"), false)
require.NoError(t, err)
require.Len(t, res.Values, 1)
})
@@ -213,7 +213,7 @@ func TestHandleDataplaneNumeric(t *testing.T) {
for _, example := range numericExamples.AsSlice() {
t.Run(example.Info().ID, func(t *testing.T) {
res, err := handleDataplaneNumeric(example.Frames("A"))
res, err := handleDataplaneNumeric(example.Frames("A"), false)
require.NoError(t, err)
require.Len(t, res.Values, example.Info().ItemCount)
})