From 31d19381f6e82fe0c428d8d13a54b7bd4b8c43c1 Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Wed, 16 Oct 2024 15:09:27 +1100 Subject: [PATCH 1/2] Clamp functions should ignore native histograms As per the documentation, native histograms are skipped. This is in line with other `simpleFunc`'s. Signed-off-by: Joshua Hesketh --- promql/functions.go | 12 ++++++++++++ promql/promqltest/testdata/functions.test | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/promql/functions.go b/promql/functions.go index 4333cb5ce..26ec31c5f 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -492,6 +492,10 @@ func funcClamp(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper return enh.Out, nil } for _, el := range vec { + if el.H != nil { + // Process only float samples. + continue + } if !enh.enableDelayedNameRemoval { el.Metric = el.Metric.DropMetricName() } @@ -509,6 +513,10 @@ func funcClampMax(vals []parser.Value, args parser.Expressions, enh *EvalNodeHel vec := vals[0].(Vector) maxVal := vals[1].(Vector)[0].F for _, el := range vec { + if el.H != nil { + // Process only float samples. + continue + } if !enh.enableDelayedNameRemoval { el.Metric = el.Metric.DropMetricName() } @@ -526,6 +534,10 @@ func funcClampMin(vals []parser.Value, args parser.Expressions, enh *EvalNodeHel vec := vals[0].(Vector) minVal := vals[1].(Vector)[0].F for _, el := range vec { + if el.H != nil { + // Process only float samples. + continue + } if !enh.enableDelayedNameRemoval { el.Metric = el.Metric.DropMetricName() } diff --git a/promql/promqltest/testdata/functions.test b/promql/promqltest/testdata/functions.test index c9af6c4c9..46a88cd94 100644 --- a/promql/promqltest/testdata/functions.test +++ b/promql/promqltest/testdata/functions.test @@ -452,6 +452,21 @@ eval instant at 0m clamp(test_clamp, NaN, 0) eval instant at 0m clamp(test_clamp, 5, -5) +clear + +load 1m + mixed_metric {{schema:0 sum:5 count:4 buckets:[1 2 1]}} 1 2 3 {{schema:0 sum:5 count:4 buckets:[1 2 1]}} {{schema:0 sum:8 count:6 buckets:[1 4 1]}} + +# clamp ignores any histograms +eval range from 0 to 5m step 1m clamp(mixed_metric, 2, 5) + {} _ 2 2 3 + +eval range from 0 to 5m step 1m clamp_min(mixed_metric, 2) + {} _ 2 2 3 + +eval range from 0 to 5m step 1m clamp_max(mixed_metric, 2) + {} _ 1 2 2 + # Test cases for sgn. clear load 5m From 2294712fe84c2efce8bf429e312f42a3206c3b7e Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Wed, 16 Oct 2024 15:11:01 +1100 Subject: [PATCH 2/2] Update CHANGELOG Signed-off-by: Joshua Hesketh --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8e762118..2a06785d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## unreleased +* [BUGFIX] Clamp functions: Ignore any points with native histograms. #15169 + ## 3.0.0-beta.1 / 2024-10-09 * [CHANGE] regexp `.` now matches all characters (performance improvement). #14505