diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 45669f69c..68bcc6d8e 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -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} diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index c313a4633..f2834ea11 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -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{