Fix target metadata API for empty match_targets (#6303)
According to the documentation, the target metadata API accepts it, if no value for match_target has been provided. This was not the case in the implementation. This commit make the API behave as described in the docs. Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
This commit is contained in:
parent
12d347e4db
commit
be2bcc50a2
|
@ -674,10 +674,18 @@ func (api *API) targetMetadata(r *http.Request) apiFuncResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
matchers, err := promql.ParseMetricSelector(r.FormValue("match_target"))
|
matchTarget := r.FormValue("match_target")
|
||||||
|
|
||||||
|
var matchers []*labels.Matcher
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if matchTarget != "" {
|
||||||
|
matchers, err = promql.ParseMetricSelector(matchTarget)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
metric := r.FormValue("metric")
|
metric := r.FormValue("metric")
|
||||||
|
|
||||||
|
@ -688,7 +696,7 @@ func (api *API) targetMetadata(r *http.Request) apiFuncResult {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Filter targets that don't satisfy the label matchers.
|
// Filter targets that don't satisfy the label matchers.
|
||||||
if !matchLabels(t.Labels(), matchers) {
|
if matchTarget != "" && !matchLabels(t.Labels(), matchers) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// If no metric is specified, get the full list for the target.
|
// If no metric is specified, get the full list for the target.
|
||||||
|
|
Loading…
Reference in New Issue