promql: fix double quoting in invalid label name error from count_values (#16054)

promql: fix double quoting in invalid label name error from `count_values`

---------

Signed-off-by: Charles Korn <charles.korn@grafana.com>
Signed-off-by: Charles Korn <charleskorn@users.noreply.github.com>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
This commit is contained in:
Charles Korn 2025-02-21 10:37:04 +11:00 committed by GitHub
parent 8c8b83ed4e
commit 8356990709
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View file

@ -1604,7 +1604,7 @@ func (ev *evaluator) eval(ctx context.Context, expr parser.Expr) (parser.Value,
if e.Op == parser.COUNT_VALUES {
valueLabel := param.(*parser.StringLiteral)
if !model.LabelName(valueLabel.Val).IsValid() {
ev.errorf("invalid label name %q", valueLabel)
ev.errorf("invalid label name %s", valueLabel)
}
if !e.Without {
sortedGrouping = append(sortedGrouping, valueLabel.Val)

View file

@ -430,6 +430,10 @@ eval instant at 1m count_values by (job, group)("job", version)
{job="7", group="canary"} 2
{job="{count:20, sum:10, [-2,-1):2, [-1,-0.5):1, [-0.001,0.001]:2, (0.5,1]:1, (1,2]:2}", group="canary"} 2
# Test an invalid label value.
eval_fail instant at 0 count_values("a\xc5z", version)
expected_fail_message invalid label name "a\xc5z"
# Tests for quantile.
clear