Skip to content

Commit

Permalink
Modify round to drop series name
Browse files Browse the repository at this point in the history
Signed-off-by: Arve Knudsen <[email protected]>
  • Loading branch information
aknuds1 committed Nov 12, 2024
1 parent 78fd61e commit bf278d7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
7 changes: 2 additions & 5 deletions pkg/streamingpromql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,8 @@ func RoundFunctionOperatorFactory() InstantVectorFunctionOperatorFactory {
}

f := functions.FunctionOverInstantVectorDefinition{
SeriesDataFunc: functions.Round,
// TODO(jhesketh): With the version of Prometheus vendored at the time of writing, round does not drop the
// __name__ label, and this is verified by our tests.
// We match this for consistency, but will need to drop them once prometheus 3.0 is vendored in.
SeriesMetadataFunction: functions.SeriesMetadataFunctionDefinition{},
SeriesDataFunc: functions.Round,
SeriesMetadataFunction: functions.DropSeriesName,
}

return functions.NewFunctionOverInstantVector(inner, []types.ScalarOperator{toNearest}, memoryConsumptionTracker, f, expressionPosition), nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ eval range from 0 to 5m step 1m clamp_max(mixed_metric, 2)
# Prometheus currently returns 0 instead of no value as per the documentation
# https://github.com/prometheus/prometheus/pull/15176
eval range from 0 to 5m step 1m round(mixed_metric)
mixed_metric _ 1 2 3
{} _ 1 2 3
4 changes: 2 additions & 2 deletions pkg/streamingpromql/testdata/ours/functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ load 6m
series{a="b"} -5.5 2.75 _ _ 6.87

eval range from 0 to 24m step 6m round(series, scalar(toNearest))
series{a="b"} -5 NaN _ _ 6.9
{a="b"} -5 NaN _ _ 6.9

clear

Expand All @@ -459,4 +459,4 @@ load 6m
series{a="b"} -5.5 2.75 0.25 15.5 9.999 3.14159 -0.999999 1000.01 0.49999999 -1e6 10 20 NaN NaN _ _ 10.5

eval range from 0 to 96m step 6m round(series, scalar(toNearest))
series{a="b"} -5 2.7 0.5 20 10 3.25 0 1000.01 0 -1000000 NaN NaN NaN NaN _ _ 10
{a="b"} -5 2.7 0.5 20 10 3.25 0 1000.01 0 -1000000 NaN NaN NaN NaN _ _ 10
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ eval instant at 15m metric * 2
eval instant at 15m clamp(metric, 0, 100)
{env="1"} 100

# Drops __name__ for round function
eval instant at 15m round(metric)
{env="1"} 120

# Drops __name__ for range-vector functions
eval instant at 15m rate(metric{env="1"}[10m])
{env="1"} 0.2
Expand Down

0 comments on commit bf278d7

Please sign in to comment.