diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 34abe80aa..671df7887 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -668,7 +668,7 @@ func (api *API) labelNames(r *http.Request) apiFuncResult { names []string warnings annotations.Annotations ) - if len(matcherSets) > 0 { + if len(matcherSets) > 1 { labelNamesSet := make(map[string]struct{}) for _, matchers := range matcherSets { @@ -690,7 +690,11 @@ func (api *API) labelNames(r *http.Request) apiFuncResult { } slices.Sort(names) } else { - names, warnings, err = q.LabelNames(r.Context()) + var matchers []*labels.Matcher + if len(matcherSets) == 1 { + matchers = matcherSets[0] + } + names, warnings, err = q.LabelNames(r.Context(), matchers...) if err != nil { return apiFuncResult{nil, &apiError{errorExec, err}, warnings, nil} } @@ -744,7 +748,7 @@ func (api *API) labelValues(r *http.Request) (result apiFuncResult) { vals []string warnings annotations.Annotations ) - if len(matcherSets) > 0 { + if len(matcherSets) > 1 { var callWarnings annotations.Annotations labelValuesSet := make(map[string]struct{}) for _, matchers := range matcherSets { @@ -763,7 +767,11 @@ func (api *API) labelValues(r *http.Request) (result apiFuncResult) { vals = append(vals, val) } } else { - vals, warnings, err = q.LabelValues(ctx, name) + var matchers []*labels.Matcher + if len(matcherSets) == 1 { + matchers = matcherSets[0] + } + vals, warnings, err = q.LabelValues(ctx, name, matchers...) if err != nil { return apiFuncResult{nil, &apiError{errorExec, err}, warnings, closer} }