Browse Source

Label name check for 'count_values' (#4585)

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
pull/4617/merge
Ganesh Vernekar 6 years ago committed by Goutham Veeramachaneni
parent
commit
576ee4d309
  1. 4
      promql/engine.go
  2. 10
      promql/engine_test.go

4
promql/engine.go

@ -29,6 +29,7 @@ import (
"github.com/go-kit/kit/log/level"
opentracing "github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/pkg/timestamp"
"github.com/prometheus/prometheus/pkg/value"
@ -1494,6 +1495,9 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
var valueLabel string
if op == itemCountValues {
valueLabel = param.(string)
if !model.LabelName(valueLabel).IsValid() {
ev.errorf("invalid label name %q", valueLabel)
}
if !without {
grouping = append(grouping, valueLabel)
}

10
promql/engine_test.go

@ -23,6 +23,7 @@ import (
"github.com/go-kit/kit/log"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/util/testutil"
)
func TestQueryConcurrency(t *testing.T) {
@ -272,6 +273,7 @@ load 10s
Start time.Time
End time.Time
Interval time.Duration
ShouldError bool
}{
// Instant queries.
{
@ -326,6 +328,10 @@ load 10s
End: time.Unix(10, 0),
Interval: 5 * time.Second,
},
{
Query: `count_values("wrong label!", metric)`,
ShouldError: true,
},
}
for _, c := range cases {
@ -340,6 +346,10 @@ load 10s
t.Fatalf("unexpected error creating query: %q", err)
}
res := qry.Exec(test.Context())
if c.ShouldError {
testutil.NotOk(t, res.Err, "expected error for the query %q", c.Query)
continue
}
if res.Err != nil {
t.Fatalf("unexpected error running query: %q", res.Err)
}

Loading…
Cancel
Save