Skip to content

Commit

Permalink
MQE: Pull new functions test and fix _over_time functions
Browse files Browse the repository at this point in the history
Same fix as prometheus/prometheus#15711 and similar to what was done during the last sync: #10383
  • Loading branch information
julienduchesne committed Jan 10, 2025
1 parent 2298266 commit 2eb09bb
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 19 deletions.
24 changes: 18 additions & 6 deletions pkg/streamingpromql/operators/functions/range_vectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,23 @@ func presentOverTime(step *types.RangeVectorStepData, _ float64, _ types.EmitAnn
}

var MaxOverTime = FunctionOverRangeVectorDefinition{
SeriesMetadataFunction: DropSeriesName,
StepFunc: maxOverTime,
SeriesMetadataFunction: DropSeriesName,
StepFunc: maxOverTime,
NeedsSeriesNamesForAnnotations: true,
}

func maxOverTime(step *types.RangeVectorStepData, _ float64, _ types.EmitAnnotationFunc) (float64, bool, *histogram.FloatHistogram, error) {
func maxOverTime(step *types.RangeVectorStepData, _ float64, emitAnnotation types.EmitAnnotationFunc) (float64, bool, *histogram.FloatHistogram, error) {
head, tail := step.Floats.UnsafePoints()

if len(head) == 0 && len(tail) == 0 {
return 0, false, nil, nil
}

hHead, hTail := step.Histograms.UnsafePoints()
if len(hHead) > 0 || len(hTail) > 0 {
emitAnnotation(annotations.NewHistogramIgnoredInMixedRangeInfo)
}

maxSoFar := head[0].F
head = head[1:]

Expand All @@ -97,17 +103,23 @@ func maxOverTime(step *types.RangeVectorStepData, _ float64, _ types.EmitAnnotat
}

var MinOverTime = FunctionOverRangeVectorDefinition{
SeriesMetadataFunction: DropSeriesName,
StepFunc: minOverTime,
SeriesMetadataFunction: DropSeriesName,
StepFunc: minOverTime,
NeedsSeriesNamesForAnnotations: true,
}

func minOverTime(step *types.RangeVectorStepData, _ float64, _ types.EmitAnnotationFunc) (float64, bool, *histogram.FloatHistogram, error) {
func minOverTime(step *types.RangeVectorStepData, _ float64, emitAnnotation types.EmitAnnotationFunc) (float64, bool, *histogram.FloatHistogram, error) {
head, tail := step.Floats.UnsafePoints()

if len(head) == 0 && len(tail) == 0 {
return 0, false, nil, nil
}

hHead, hTail := step.Histograms.UnsafePoints()
if len(hHead) > 0 || len(hTail) > 0 {
emitAnnotation(annotations.NewHistogramIgnoredInMixedRangeInfo)
}

minSoFar := head[0].F
head = head[1:]

Expand Down
4 changes: 2 additions & 2 deletions pkg/streamingpromql/testdata/ours/functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ eval range from 0 to 7m step 1m present_over_time(some_metric_count[3m1s])
eval range from 0 to 7m step 1m present_over_time(some_metric_count[6s])
{foo="bar"} 1 1 1 1 _ _ 1 1

eval range from 0 to 7m step 1m min_over_time(some_metric_count[3m1s])
eval_info range from 0 to 7m step 1m min_over_time(some_metric_count[3m1s])
{foo="bar"} 0 0 0 0 1 2 3 _

eval range from 0 to 7m step 1m min_over_time(some_metric_count[6s])
Expand All @@ -117,7 +117,7 @@ eval range from 0 to 7m step 1m min_over_time(some_metric_count[6s])
eval range from 0 to 16m step 1m min_over_time(some_inf_and_nan_metric[3m1s])
{foo="baz"} 0 0 0 0 1 2 3 Inf Inf Inf NaN 8 7 6 6 6 6

eval range from 0 to 7m step 1m max_over_time(some_metric_count[3m1s])
eval_info range from 0 to 7m step 1m max_over_time(some_metric_count[3m1s])
{foo="bar"} 0 1 2 3 3 3 3 _

eval range from 0 to 7m step 1m max_over_time(some_metric_count[6s])
Expand Down
86 changes: 75 additions & 11 deletions pkg/streamingpromql/testdata/upstream/functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -979,41 +979,70 @@ eval instant at 1m avg_over_time(metric[2m])
# Tests for stddev_over_time and stdvar_over_time.
clear
load 10s
metric 0 8 8 2 3
metric 0 8 8 2 3
metric_histogram{type="only_histogram"} {{schema:1 sum:2 count:3}}x5
metric_histogram{type="mix"} 1 1 1 {{schema:1 sum:2 count:3}} {{schema:1 sum:2 count:3}}

# Unsupported by streaming engine.
# eval instant at 1m stdvar_over_time(metric[2m])
# {} 10.56
# {} 10.56

# Unsupported by streaming engine.
# eval instant at 1m stddev_over_time(metric[2m])
# {} 3.249615
# {} 3.249615

# Unsupported by streaming engine.
# eval instant at 1m stddev_over_time((metric[2m]))
# {} 3.249615
# {} 3.249615

# Tests for stddev_over_time and stdvar_over_time with histograms.
# Unsupported by streaming engine.
# eval instant at 1m stddev_over_time(metric_histogram{type="only_histogram"}[2m])
# #empty

# Unsupported by streaming engine.
# eval_info instant at 1m stddev_over_time(metric_histogram{type="mix"}[2m])
# {type="mix"} 0

# Unsupported by streaming engine.
# eval instant at 1m stdvar_over_time(metric_histogram{type="only_histogram"}[2m])
# #empty

# Unsupported by streaming engine.
# eval_info instant at 1m stdvar_over_time(metric_histogram{type="mix"}[2m])
# {type="mix"} 0

# Tests for stddev_over_time and stdvar_over_time #4927.
clear
load 10s
metric 1.5990505637277868 1.5990505637277868 1.5990505637277868
metric 1.5990505637277868 1.5990505637277868 1.5990505637277868

# Unsupported by streaming engine.
# eval instant at 1m stdvar_over_time(metric[1m])
# {} 0
# {} 0

# Unsupported by streaming engine.
# eval instant at 1m stddev_over_time(metric[1m])
# {} 0
# {} 0

# Tests for mad_over_time.
clear
load 10s
metric 4 6 2 1 999 1 2
metric 4 6 2 1 999 1 2
metric_histogram{type="only_histogram"} {{schema:1 sum:2 count:3}}x5
metric_histogram{type="mix"} 1 1 1 {{schema:1 sum:2 count:3}} {{schema:1 sum:2 count:3}}

# Unsupported by streaming engine.
# eval instant at 70s mad_over_time(metric[70s])
# {} 1
# {} 1

# Unsupported by streaming engine.
# eval instant at 70s mad_over_time(metric_histogram{type="only_histogram"}[70s])
# #empty

# Unsupported by streaming engine.
# eval_info instant at 70s mad_over_time(metric_histogram{type="mix"}[70s])
# {type="mix"} 0

# Tests for quantile_over_time
clear
Expand All @@ -1022,6 +1051,8 @@ load 10s
data{test="two samples"} 0 1
data{test="three samples"} 0 1 2
data{test="uneven samples"} 0 1 4
data_histogram{test="only histogram samples"} {{schema:0 sum:1 count:2}}x4
data_histogram{test="mix samples"} 0 1 2 {{schema:0 sum:1 count:2}}x2

# Unsupported by streaming engine.
# eval instant at 1m quantile_over_time(0, data[2m])
Expand Down Expand Up @@ -1071,6 +1102,14 @@ load 10s
# {test="three samples"} +Inf
# {test="uneven samples"} +Inf

# Unsupported by streaming engine.
# eval instant at 1m quantile_over_time(0.5, data_histogram{test="only histogram samples"}[2m])
# #empty

# Unsupported by streaming engine.
# eval_info instant at 1m quantile_over_time(0.5, data_histogram{test="mix samples"}[2m])
# {test="mix samples"} 1

clear

# Test time-related functions.
Expand Down Expand Up @@ -1216,15 +1255,17 @@ load 5m

eval_fail instant at 0m changes({__name__=~'testmetric1|testmetric2'}[5m])

# Tests for *_over_time
clear

# Tests for *_over_time
load 10s
data{type="numbers"} 2 0 3
data{type="some_nan"} 2 0 NaN
data{type="some_nan2"} 2 NaN 1
data{type="some_nan3"} NaN 0 1
data{type="only_nan"} NaN NaN NaN
data_histogram{type="only_histogram"} {{schema:0 sum:1 count:2}} {{schema:0 sum:2 count:3}} {{schema:0 sum:3 count:4}}
data_histogram{type="mix_samples"} 0 1 {{schema:0 sum:1 count:2}} {{schema:0 sum:2 count:3}}

eval instant at 1m min_over_time(data[2m])
{type="numbers"} 0
Expand All @@ -1233,19 +1274,42 @@ eval instant at 1m min_over_time(data[2m])
{type="some_nan3"} 0
{type="only_nan"} NaN

eval instant at 1m min_over_time(data_histogram{type="only_histogram"}[2m])
#empty

eval_info instant at 1m min_over_time(data_histogram{type="mix_samples"}[2m])
{type="mix_samples"} 0

eval instant at 1m max_over_time(data[2m])
{type="numbers"} 3
{type="some_nan"} 2
{type="some_nan2"} 2
{type="some_nan3"} 1
{type="only_nan"} NaN

eval instant at 1m last_over_time(data[2m])
eval instant at 1m max_over_time(data_histogram{type="only_histogram"}[2m])
#empty

eval_info instant at 1m max_over_time(data_histogram{type="mix_samples"}[2m])
{type="mix_samples"} 1

eval instant at 1m last_over_time({__name__=~"data(_histogram)?"}[2m])
data{type="numbers"} 3
data{type="some_nan"} NaN
data{type="some_nan2"} 1
data{type="some_nan3"} 1
data{type="only_nan"} NaN
data_histogram{type="only_histogram"} {{schema:0 sum:3 count:4}}
data_histogram{type="mix_samples"} {{schema:0 sum:2 count:3}}

eval instant at 1m count_over_time({__name__=~"data(_histogram)?"}[2m])
{type="numbers"} 3
{type="some_nan"} 3
{type="some_nan2"} 3
{type="some_nan3"} 3
{type="only_nan"} 3
{type="only_histogram"} 3
{type="mix_samples"} 4

clear

Expand Down
36 changes: 36 additions & 0 deletions pkg/streamingpromql/testdata/upstream/native_histograms.test
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,42 @@ eval_warn range from 0 to 12m step 6m sum(metric)
eval_warn range from 0 to 12m step 6m avg(metric)
{} _ {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}} _

# Test incompatible schemas with additional aggregation operators
eval range from 0 to 12m step 6m count(metric)
{} 2 2 3

eval range from 0 to 12m step 6m group(metric)
{} 1 1 1

# Unsupported by streaming engine.
# eval range from 0 to 12m step 6m count(limitk(1, metric))
# {} 1 1 1

# Unsupported by streaming engine.
# eval range from 0 to 12m step 6m limitk(3, metric)
# metric{series="1"} _ {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}} {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}}
# metric{series="2"} {{schema:-53 sum:1 count:1 custom_values:[2] buckets:[1]}} _ {{schema:-53 sum:1 count:1 custom_values:[2] buckets:[1]}}
# metric{series="3"} {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}} {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}} {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}}

# Unsupported by streaming engine.
# eval range from 0 to 12m step 6m limit_ratio(1, metric)
# metric{series="1"} _ {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}} {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}}
# metric{series="2"} {{schema:-53 sum:1 count:1 custom_values:[2] buckets:[1]}} _ {{schema:-53 sum:1 count:1 custom_values:[2] buckets:[1]}}
# metric{series="3"} {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}} {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}} {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}}

# Test incompatible schemas with and/or
eval range from 0 to 12m step 6m metric{series="1"} and ignoring(series) metric{series="2"}
metric{series="1"} _ _ {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}}

eval range from 0 to 12m step 6m metric{series="1"} or ignoring(series) metric{series="2"}
metric{series="1"} _ {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}} {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}}
metric{series="2"} {{schema:-53 sum:1 count:1 custom_values:[2] buckets:[1]}} _ _

# Test incompatible schemas with arithmetic binary operators
eval_warn range from 0 to 12m step 6m metric{series="2"} + ignoring (series) metric{series="3"}

eval_warn range from 0 to 12m step 6m metric{series="2"} - ignoring (series) metric{series="3"}

clear

load 1m
Expand Down

0 comments on commit 2eb09bb

Please sign in to comment.