@@ -58,6 +58,7 @@ type Discoverer struct {
58
58
log logr.Logger
59
59
manager * discovery.Manager
60
60
close chan struct {}
61
+ mtxScrape sync.Mutex // Guards the fields below.
61
62
configsMap map [allocatorWatcher.EventSource ][]* promconfig.ScrapeConfig
62
63
hook discoveryHook
63
64
scrapeConfigsHash hash.Hash
@@ -139,7 +140,9 @@ func (m *Discoverer) Run() error {
139
140
140
141
// UpdateTsets updates the target sets to be scraped.
141
142
func (m * Discoverer ) UpdateTsets (tsets map [string ][]* targetgroup.Group ) {
143
+ m .mtxScrape .Lock ()
142
144
m .targetSets = tsets
145
+ m .mtxScrape .Unlock ()
143
146
}
144
147
145
148
// reloader triggers a reload of the scrape configs at regular intervals.
@@ -169,13 +172,13 @@ func (m *Discoverer) reloader() {
169
172
// Reload triggers a reload of the scrape configs.
170
173
// This will process the target groups and update the targets concurrently.
171
174
func (m * Discoverer ) Reload () {
172
- targetSets := m . targetSets
175
+ m . mtxScrape . Lock ()
173
176
var wg sync.WaitGroup
174
177
targets := map [string ]* Item {}
175
178
timer := prometheus .NewTimer (processTargetsDuration )
176
179
defer timer .ObserveDuration ()
177
180
178
- for jobName , groups := range targetSets {
181
+ for jobName , groups := range m . targetSets {
179
182
wg .Add (1 )
180
183
// Run the sync in parallel as these take a while and at high load can't catch up.
181
184
go func (jobName string , groups []* targetgroup.Group ) {
@@ -188,6 +191,7 @@ func (m *Discoverer) Reload() {
188
191
wg .Done ()
189
192
}(jobName , groups )
190
193
}
194
+ m .mtxScrape .Unlock ()
191
195
wg .Wait ()
192
196
m .processTargetsCallBack (targets )
193
197
}
0 commit comments