Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix round function not honoring delayed name removal flag #748

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions promql/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3928,3 +3928,65 @@ func (s mockSeries) Iterator(it chunkenc.Iterator) chunkenc.Iterator {
}
return storage.ChainSampleIteratorFromIterators(it, iterables)
}

func TestEvaluationWithDelayedNameRemovalDisabled(t *testing.T) {
opts := promql.EngineOpts{
Logger: nil,
Reg: nil,
EnableAtModifier: true,
MaxSamples: 10000,
Timeout: 10 * time.Second,
EnableDelayedNameRemoval: false,
}
engine := promqltest.NewTestEngineWithOpts(t, opts)

promqltest.RunTest(t, `
load 5m
metric{env="1"} 0 60 120
another_metric{env="1"} 60 120 180

# Does not drop __name__ for vector selector
eval instant at 10m metric{env="1"}
metric{env="1"} 120

# Drops __name__ for unary operators
eval instant at 10m -metric
{env="1"} -120

# Drops __name__ for binary operators
eval instant at 10m metric + another_metric
{env="1"} 300

# Does not drop __name__ for binary comparison operators
eval instant at 10m metric <= another_metric
metric{env="1"} 120

# Drops __name__ for binary comparison operators with "bool" modifier
eval instant at 10m metric <= bool another_metric
{env="1"} 1

# Drops __name__ for vector-scalar operations
eval instant at 10m metric * 2
{env="1"} 240

# Drops __name__ for instant-vector functions
eval instant at 10m clamp(metric, 0, 100)
{env="1"} 100

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

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

# Does not drop __name__ for last_over_time function
eval instant at 10m last_over_time(metric{env="1"}[10m])
metric{env="1"} 120

# Drops name for other _over_time functions
eval instant at 10m max_over_time(metric{env="1"}[10m])
{env="1"} 120
`, engine)
}
3 changes: 3 additions & 0 deletions promql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@ func funcRound(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper
continue
}
f := math.Floor(el.F*toNearestInverse+0.5) / toNearestInverse
if !enh.enableDelayedNameRemoval {
el.Metric = el.Metric.DropMetricName()
}
enh.Out = append(enh.Out, Sample{
Metric: el.Metric,
F: f,
Expand Down
4 changes: 4 additions & 0 deletions promql/promqltest/testdata/name_label_dropping.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ eval instant at 10m metric * 2
eval instant at 10m clamp(metric, 0, 100)
{env="1"} 100

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

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