mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
api: Serialize discovered and target labels into JSON directly (#13469)
Converted maps into labels.Labels to avoid a lot of copying of data which leads to very high memory consumption while opening the /service-discovery endpoint in the Prometheus UI Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
This commit is contained in:
parent
bdc3cfdd5d
commit
e3040bfabc
|
@ -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(),
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue