From 8dc53c2218b08350df677897df1bed3e03d0690b Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Tue, 15 Dec 2020 18:24:57 +0100 Subject: [PATCH] Api: Verify that at every matcher in api/v1/series is not empty (#8288) Fixed #8286 Signed-off-by: Julien Pivotto --- web/api/v1/api.go | 13 +++++++++++++ web/api/v1/api_test.go | 7 +++++++ 2 files changed, 20 insertions(+) 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{