Api: Verify that at every matcher in api/v1/series is not empty (#8288)

Fixed #8286

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2020-12-15 18:24:57 +01:00 committed by GitHub
parent 0dd6e0cb76
commit 8dc53c2218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -587,6 +587,19 @@ func (api *API) series(r *http.Request) (result apiFuncResult) {
matcherSets = append(matcherSets, matchers)
}
for _, ms := range matcherSets {
var nonEmpty bool
for _, lm := range ms {
if lm != nil && !lm.Matches("") {
nonEmpty = true
break
}
}
if !nonEmpty {
return apiFuncResult{nil, &apiError{errorBadData, errors.New("match[] must contain at least one non-empty matcher")}, nil, nil}
}
}
q, err := api.Queryable.Querier(r.Context(), timestamp.FromTime(start), timestamp.FromTime(end))
if err != nil {
return apiFuncResult{nil, &apiError{errorExec, err}, nil, nil}

View File

@ -727,6 +727,13 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, testLabelAPI
labels.FromStrings("__name__", "test_metric2", "foo", "boo"),
},
},
{
endpoint: api.series,
query: url.Values{
"match[]": []string{`{foo=""}`},
},
errType: errorBadData,
},
{
endpoint: api.series,
query: url.Values{