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

Label name check for 'count_values' #4585

Merged
merged 1 commit into from Sep 13, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions promql/engine.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
20 changes: 15 additions & 5 deletions promql/engine_test.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -267,11 +268,12 @@ load 10s
}

cases := []struct {
Query string
Result Value
Start time.Time
End time.Time
Interval time.Duration
Query string
Result Value
Start time.Time
End time.Time
Interval time.Duration
ShouldError bool
}{
// Instant queries.
{
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down