mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-12 16:44:05 -08:00
Merge pull request #4905 from simonpasquier/cherrypick-4840
Cherrypick 4840
This commit is contained in:
commit
f9c93b3686
|
@ -573,6 +573,15 @@ func (api *API) targets(r *http.Request) (interface{}, *apiError, func()) {
|
||||||
return res, nil, nil
|
return res, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func matchLabels(lset labels.Labels, matchers []*labels.Matcher) bool {
|
||||||
|
for _, m := range matchers {
|
||||||
|
if !m.Matches(lset.Get(m.Name)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) targetMetadata(r *http.Request) (interface{}, *apiError, func()) {
|
func (api *API) targetMetadata(r *http.Request) (interface{}, *apiError, func()) {
|
||||||
limit := -1
|
limit := -1
|
||||||
if s := r.FormValue("limit"); s != "" {
|
if s := r.FormValue("limit"); s != "" {
|
||||||
|
@ -590,17 +599,14 @@ func (api *API) targetMetadata(r *http.Request) (interface{}, *apiError, func())
|
||||||
metric := r.FormValue("metric")
|
metric := r.FormValue("metric")
|
||||||
|
|
||||||
var res []metricMetadata
|
var res []metricMetadata
|
||||||
Outer:
|
|
||||||
for _, tt := range api.targetRetriever.TargetsActive() {
|
for _, tt := range api.targetRetriever.TargetsActive() {
|
||||||
for _, t := range tt {
|
for _, t := range tt {
|
||||||
if limit >= 0 && len(res) >= limit {
|
if limit >= 0 && len(res) >= limit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for _, m := range matchers {
|
// Filter targets that don't satisfy the label matchers.
|
||||||
// Filter targets that don't satisfy the label matchers.
|
if !matchLabels(t.Labels(), matchers) {
|
||||||
if !m.Matches(t.Labels().Get(m.Name)) {
|
continue
|
||||||
continue Outer
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// If no metric is specified, get the full list for the target.
|
// If no metric is specified, get the full list for the target.
|
||||||
if metric == "" {
|
if metric == "" {
|
||||||
|
|
Loading…
Reference in a new issue