From 2ca8a4e58ed37b1140d8d71b48eea1b2a396b71e Mon Sep 17 00:00:00 2001 From: Piotr <17101802+thampiotr@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:58:06 +0000 Subject: [PATCH] Intern strings in discovery components to reduce memory consumption. --- internal/component/discovery/discovery.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/component/discovery/discovery.go b/internal/component/discovery/discovery.go index 03670814e1..5a081cc536 100644 --- a/internal/component/discovery/discovery.go +++ b/internal/component/discovery/discovery.go @@ -9,6 +9,7 @@ import ( "sync" "time" + "github.com/josharian/intern" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/discovery" "github.com/prometheus/prometheus/discovery/targetgroup" @@ -274,10 +275,10 @@ func toAlloyTargets(cache map[string]*targetgroup.Group) []Target { // first add the group labels, and then the // target labels, so that target labels take precedence. for k, v := range group.Labels { - tLabels[string(k)] = string(v) + tLabels[intern.String(string(k))] = intern.String(string(v)) } for k, v := range target { - tLabels[string(k)] = string(v) + tLabels[intern.String(string(k))] = intern.String(string(v)) } allTargets = append(allTargets, tLabels) }