From 2eb09bbe28f32fa39b6d8012523aeb70a2dfe9ef Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Thu, 9 Jan 2025 21:33:54 -0500 Subject: [PATCH] MQE: Pull new functions test and fix _over_time functions Same fix as https://github.com/prometheus/prometheus/pull/15711 and similar to what was done during the last sync: https://github.com/grafana/mimir/pull/10383 --- .../operators/functions/range_vectors.go | 24 ++++-- .../testdata/ours/functions.test | 4 +- .../testdata/upstream/functions.test | 86 ++++++++++++++++--- .../testdata/upstream/native_histograms.test | 36 ++++++++ 4 files changed, 131 insertions(+), 19 deletions(-) diff --git a/pkg/streamingpromql/operators/functions/range_vectors.go b/pkg/streamingpromql/operators/functions/range_vectors.go index f1270146064..c6bd99b6dc7 100644 --- a/pkg/streamingpromql/operators/functions/range_vectors.go +++ b/pkg/streamingpromql/operators/functions/range_vectors.go @@ -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:] @@ -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:] diff --git a/pkg/streamingpromql/testdata/ours/functions.test b/pkg/streamingpromql/testdata/ours/functions.test index 9105bc01848..cf34b33cad6 100644 --- a/pkg/streamingpromql/testdata/ours/functions.test +++ b/pkg/streamingpromql/testdata/ours/functions.test @@ -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]) @@ -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]) diff --git a/pkg/streamingpromql/testdata/upstream/functions.test b/pkg/streamingpromql/testdata/upstream/functions.test index 004ef8d1995..02db575da97 100644 --- a/pkg/streamingpromql/testdata/upstream/functions.test +++ b/pkg/streamingpromql/testdata/upstream/functions.test @@ -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 @@ -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]) @@ -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. @@ -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 @@ -1233,6 +1274,12 @@ 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 @@ -1240,12 +1287,29 @@ eval instant at 1m max_over_time(data[2m]) {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 diff --git a/pkg/streamingpromql/testdata/upstream/native_histograms.test b/pkg/streamingpromql/testdata/upstream/native_histograms.test index 3616d455911..61123239cec 100644 --- a/pkg/streamingpromql/testdata/upstream/native_histograms.test +++ b/pkg/streamingpromql/testdata/upstream/native_histograms.test @@ -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