Skip to content

Commit 42ae8d0

Browse files
[CHORE] adding mutex back
Signed-off-by: Nicolas Takashi <[email protected]>
1 parent 3e5ae20 commit 42ae8d0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cmd/otel-allocator/target/discovery.go

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

140141
// UpdateTsets updates the target sets to be scraped.
141142
func (m *Discoverer) UpdateTsets(tsets map[string][]*targetgroup.Group) {
143+
m.mtxScrape.Lock()
142144
m.targetSets = tsets
145+
m.mtxScrape.Unlock()
143146
}
144147

145148
// reloader triggers a reload of the scrape configs at regular intervals.
@@ -169,13 +172,13 @@ func (m *Discoverer) reloader() {
169172
// Reload triggers a reload of the scrape configs.
170173
// This will process the target groups and update the targets concurrently.
171174
func (m *Discoverer) Reload() {
172-
targetSets := m.targetSets
175+
m.mtxScrape.Lock()
173176
var wg sync.WaitGroup
174177
targets := map[string]*Item{}
175178
timer := prometheus.NewTimer(processTargetsDuration)
176179
defer timer.ObserveDuration()
177180

178-
for jobName, groups := range targetSets {
181+
for jobName, groups := range m.targetSets {
179182
wg.Add(1)
180183
// Run the sync in parallel as these take a while and at high load can't catch up.
181184
go func(jobName string, groups []*targetgroup.Group) {
@@ -188,6 +191,7 @@ func (m *Discoverer) Reload() {
188191
wg.Done()
189192
}(jobName, groups)
190193
}
194+
m.mtxScrape.Unlock()
191195
wg.Wait()
192196
m.processTargetsCallBack(targets)
193197
}

0 commit comments

Comments
 (0)