Skip to content

Commit 28880ab

Browse files
[REFACTORY] applying comments
Signed-off-by: Nicolas Takashi <[email protected]>
1 parent 2ef992e commit 28880ab

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

cmd/otel-allocator/target/discovery.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ type Discoverer struct {
5858
log logr.Logger
5959
manager *discovery.Manager
6060
close chan struct{}
61-
mtxScrape sync.Mutex // Guards the fields below.
6261
configsMap map[allocatorWatcher.EventSource][]*promconfig.ScrapeConfig
6362
hook discoveryHook
6463
scrapeConfigsHash hash.Hash
@@ -140,9 +139,7 @@ func (m *Discoverer) Run() error {
140139

141140
// UpdateTsets updates the target sets to be scraped.
142141
func (m *Discoverer) UpdateTsets(tsets map[string][]*targetgroup.Group) {
143-
m.mtxScrape.Lock()
144142
m.targetSets = tsets
145-
m.mtxScrape.Unlock()
146143
}
147144

148145
// reloader triggers a reload of the scrape configs at regular intervals.
@@ -172,13 +169,13 @@ func (m *Discoverer) reloader() {
172169
// Reload triggers a reload of the scrape configs.
173170
// This will process the target groups and update the targets concurrently.
174171
func (m *Discoverer) Reload() {
175-
m.mtxScrape.Lock()
172+
targetSets := m.targetSets
176173
var wg sync.WaitGroup
177174
targets := map[string]*Item{}
178175
timer := prometheus.NewTimer(processTargetsDuration)
179176
defer timer.ObserveDuration()
180177

181-
for jobName, groups := range m.targetSets {
178+
for jobName, groups := range targetSets {
182179
wg.Add(1)
183180
// Run the sync in parallel as these take a while and at high load can't catch up.
184181
go func(jobName string, groups []*targetgroup.Group) {
@@ -191,7 +188,6 @@ func (m *Discoverer) Reload() {
191188
wg.Done()
192189
}(jobName, groups)
193190
}
194-
m.mtxScrape.Unlock()
195191
wg.Wait()
196192
m.processTargetsCallBack(targets)
197193
}

0 commit comments

Comments
 (0)