Skip to content

Commit

Permalink
Merge pull request prometheus#15176 from jhesketh/jhesketh/round
Browse files Browse the repository at this point in the history
Round function should ignore native histograms
  • Loading branch information
beorn7 authored Oct 22, 2024
2 parents aa81210 + 14ef1ce commit 7c7116f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions promql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ func funcRound(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper
toNearestInverse := 1.0 / toNearest

for _, el := range vec {
if el.H != nil {
// Process only float samples.
continue
}
f := math.Floor(el.F*toNearestInverse+0.5) / toNearestInverse
enh.Out = append(enh.Out, Sample{
Metric: el.Metric,
Expand Down
9 changes: 9 additions & 0 deletions promql/promqltest/testdata/functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1258,3 +1258,12 @@ load 1m
# We expect the value to be 0 for t=0s to t=59s (inclusive), then 60 for t=60s and t=61s.
eval range from 0 to 61s step 1s timestamp(metric)
{} 0x59 60 60

clear

# Check round with mixed data types
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]}}

eval range from 0 to 5m step 1m round(mixed_metric)
{} _ 1 2 3

0 comments on commit 7c7116f

Please sign in to comment.