diff --git a/web/api/v1/api.go b/web/api/v1/api.go index d9d4cfd1df..edbbe8d80b 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -879,9 +879,9 @@ func (api *API) dropSeries(_ *http.Request) apiFuncResult { // Target has the information for one target. type Target struct { // Labels before any processing. - DiscoveredLabels map[string]string `json:"discoveredLabels"` + DiscoveredLabels labels.Labels `json:"discoveredLabels"` // Any labels that are added to this target and its metrics. - Labels map[string]string `json:"labels"` + Labels labels.Labels `json:"labels"` ScrapePool string `json:"scrapePool"` ScrapeURL string `json:"scrapeUrl"` @@ -1024,8 +1024,8 @@ func (api *API) targets(r *http.Request) apiFuncResult { globalURL, err := getGlobalURL(target.URL(), api.globalURLOptions) res.ActiveTargets = append(res.ActiveTargets, &Target{ - DiscoveredLabels: target.DiscoveredLabels().Map(), - Labels: target.Labels().Map(), + DiscoveredLabels: target.DiscoveredLabels(), + Labels: target.Labels(), ScrapePool: key, ScrapeURL: target.URL().String(), GlobalURL: globalURL.String(), diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index c9ab84087e..9100a9ef90 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -1411,10 +1411,8 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E response: &TargetDiscovery{ ActiveTargets: []*Target{ { - DiscoveredLabels: map[string]string{}, - Labels: map[string]string{ - "job": "blackbox", - }, + DiscoveredLabels: labels.FromStrings(), + Labels: labels.FromStrings("job", "blackbox"), ScrapePool: "blackbox", ScrapeURL: "http://localhost:9115/probe?target=example.com", GlobalURL: "http://localhost:9115/probe?target=example.com", @@ -1426,10 +1424,8 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E ScrapeTimeout: "10s", }, { - DiscoveredLabels: map[string]string{}, - Labels: map[string]string{ - "job": "test", - }, + DiscoveredLabels: labels.FromStrings(), + Labels: labels.FromStrings("job", "test"), ScrapePool: "test", ScrapeURL: "http://example.com:8080/metrics", GlobalURL: "http://example.com:8080/metrics", @@ -1464,10 +1460,8 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E response: &TargetDiscovery{ ActiveTargets: []*Target{ { - DiscoveredLabels: map[string]string{}, - Labels: map[string]string{ - "job": "blackbox", - }, + DiscoveredLabels: labels.FromStrings(), + Labels: labels.FromStrings("job", "blackbox"), ScrapePool: "blackbox", ScrapeURL: "http://localhost:9115/probe?target=example.com", GlobalURL: "http://localhost:9115/probe?target=example.com", @@ -1479,10 +1473,8 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E ScrapeTimeout: "10s", }, { - DiscoveredLabels: map[string]string{}, - Labels: map[string]string{ - "job": "test", - }, + DiscoveredLabels: labels.FromStrings(), + Labels: labels.FromStrings("job", "test"), ScrapePool: "test", ScrapeURL: "http://example.com:8080/metrics", GlobalURL: "http://example.com:8080/metrics", @@ -1517,10 +1509,8 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E response: &TargetDiscovery{ ActiveTargets: []*Target{ { - DiscoveredLabels: map[string]string{}, - Labels: map[string]string{ - "job": "blackbox", - }, + DiscoveredLabels: labels.FromStrings(), + Labels: labels.FromStrings("job", "blackbox"), ScrapePool: "blackbox", ScrapeURL: "http://localhost:9115/probe?target=example.com", GlobalURL: "http://localhost:9115/probe?target=example.com", @@ -1532,10 +1522,8 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E ScrapeTimeout: "10s", }, { - DiscoveredLabels: map[string]string{}, - Labels: map[string]string{ - "job": "test", - }, + DiscoveredLabels: labels.FromStrings(), + Labels: labels.FromStrings("job", "test"), ScrapePool: "test", ScrapeURL: "http://example.com:8080/metrics", GlobalURL: "http://example.com:8080/metrics",