promql: error if all label matchers are empty.
This commit is contained in:
parent
5da5ea3ee2
commit
94cd321be1
|
@ -883,6 +883,25 @@ func (p *parser) vectorSelector(name string) *VectorSelector {
|
|||
if len(matchers) == 0 {
|
||||
p.errorf("vector selector must contain label matchers or metric name")
|
||||
}
|
||||
// A vector selector must contain at least one non-empty matcher to prevent
|
||||
// implicit selection of all metrics (e.g. by a typo).
|
||||
notEmpty := false
|
||||
for _, lm := range matchers {
|
||||
// Matching changes the inner state of the regex and causes reflect.DeepEqual
|
||||
// to return false, which break tests.
|
||||
// Thus, we create a new label matcher for this testing.
|
||||
lm, err := metric.NewLabelMatcher(lm.Type, lm.Name, lm.Value)
|
||||
if err != nil {
|
||||
p.error(err)
|
||||
}
|
||||
if !lm.Match("") {
|
||||
notEmpty = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !notEmpty {
|
||||
p.errorf("vector selector must contain at least one non-empty matcher")
|
||||
}
|
||||
|
||||
var err error
|
||||
var offset time.Duration
|
||||
|
|
|
@ -587,6 +587,22 @@ var testExpr = []struct {
|
|||
input: `{}`,
|
||||
fail: true,
|
||||
errMsg: "vector selector must contain label matchers or metric name",
|
||||
}, {
|
||||
input: `{x=""}`,
|
||||
fail: true,
|
||||
errMsg: "vector selector must contain at least one non-empty matcher",
|
||||
}, {
|
||||
input: `{x=~".*"}`,
|
||||
fail: true,
|
||||
errMsg: "vector selector must contain at least one non-empty matcher",
|
||||
}, {
|
||||
input: `{x!~".+"}`,
|
||||
fail: true,
|
||||
errMsg: "vector selector must contain at least one non-empty matcher",
|
||||
}, {
|
||||
input: `{x!="a"}`,
|
||||
fail: true,
|
||||
errMsg: "vector selector must contain at least one non-empty matcher",
|
||||
}, {
|
||||
input: `foo{__name__="bar"}`,
|
||||
fail: true,
|
||||
|
|
|
@ -378,7 +378,7 @@ eval instant at 50m drop_common_labels(http_requests{group="production",job="api
|
|||
http_requests{instance="0"} 100
|
||||
http_requests{instance="1"} 200
|
||||
|
||||
eval instant at 50m {__name__=~".*"}
|
||||
eval instant at 50m {__name__=~".+"}
|
||||
http_requests{group="canary", instance="0", job="api-server"} 300
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
http_requests{group="canary", instance="1", job="api-server"} 400
|
||||
|
|
|
@ -277,7 +277,7 @@ func TestEndpoints(t *testing.T) {
|
|||
}, {
|
||||
endpoint: api.dropSeries,
|
||||
query: url.Values{
|
||||
"match[]": []string{`{__name__=~".*"}`},
|
||||
"match[]": []string{`{__name__=~".+"}`},
|
||||
},
|
||||
response: struct {
|
||||
NumDeleted int `json:"numDeleted"`
|
||||
|
|
Loading…
Reference in New Issue