Skip to content

Commit

Permalink
Intern strings in discovery components to reduce memory consumption.
Browse files Browse the repository at this point in the history
  • Loading branch information
thampiotr committed Jan 13, 2025
1 parent 5f5c09e commit 2ca8a4e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/component/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 2ca8a4e

Please sign in to comment.