mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -1197,6 +1197,14 @@ var (
|
||||
Stage: FeatureStageExperimental,
|
||||
Owner: identityAccessTeam,
|
||||
},
|
||||
{
|
||||
Name: "disableNumericMetricsSortingInExpressions",
|
||||
Description: "In server-side expressions, disable the sorting of numeric-kind metrics by their metric name or labels.",
|
||||
Stage: FeatureStageExperimental,
|
||||
FrontendOnly: false,
|
||||
Owner: grafanaObservabilityMetricsSquad,
|
||||
RequiresRestart: true,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -159,3 +159,4 @@ oauthRequireSubClaim,experimental,@grafana/identity-access-team,false,false,fals
|
||||
newDashboardWithFiltersAndGroupBy,experimental,@grafana/dashboards-squad,false,false,false
|
||||
cloudWatchNewLabelParsing,GA,@grafana/aws-datasources,false,false,false
|
||||
accessActionSets,experimental,@grafana/identity-access-team,false,false,false
|
||||
disableNumericMetricsSortingInExpressions,experimental,@grafana/observability-metrics,false,true,false
|
||||
|
||||
|
@@ -646,4 +646,8 @@ const (
|
||||
// FlagAccessActionSets
|
||||
// Introduces action sets for resource permissions
|
||||
FlagAccessActionSets = "accessActionSets"
|
||||
|
||||
// FlagDisableNumericMetricsSortingInExpressions
|
||||
// In server-side expressions, disable the sorting of numeric-kind metrics by their metric name or labels.
|
||||
FlagDisableNumericMetricsSortingInExpressions = "disableNumericMetricsSortingInExpressions"
|
||||
)
|
||||
|
||||
@@ -2120,6 +2120,19 @@
|
||||
"stage": "experimental",
|
||||
"codeowner": "@grafana/identity-access-team"
|
||||
}
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"name": "disableNumericMetricsSortingInExpressions",
|
||||
"resourceVersion": "1713208725143",
|
||||
"creationTimestamp": "2024-04-15T19:18:45Z"
|
||||
},
|
||||
"spec": {
|
||||
"description": "In server-side expressions, disable the sorting of numeric-kind metrics by their metric name or labels.",
|
||||
"stage": "experimental",
|
||||
"codeowner": "@grafana/observability-metrics",
|
||||
"requiresRestart": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user