mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-28 23:19:41 -08:00
Merge pull request #1024 from prometheus/fix-updatetargets-busyloop
Fix busylooping in case of no target providers.
This commit is contained in:
commit
25a8bd50a5
|
@ -171,12 +171,15 @@ func (tm *TargetManager) Run() {
|
||||||
tm.running = true
|
tm.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleTargetUpdates receives target group updates and handles them in the
|
// handleUpdates receives target group updates and handles them in the
|
||||||
// context of the given job config.
|
// context of the given job config.
|
||||||
func (tm *TargetManager) handleUpdates(ch <-chan targetGroupUpdate, done <-chan struct{}) {
|
func (tm *TargetManager) handleUpdates(ch <-chan targetGroupUpdate, done <-chan struct{}) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case update := <-ch:
|
case update, ok := <-ch:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
if update.tg == nil {
|
if update.tg == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,3 +376,10 @@ func TestTargetManagerConfigUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHandleUpdatesReturnsWhenUpdateChanIsClosed(t *testing.T) {
|
||||||
|
tm := NewTargetManager(nopAppender{})
|
||||||
|
ch := make(chan targetGroupUpdate)
|
||||||
|
close(ch)
|
||||||
|
tm.handleUpdates(ch, make(chan struct{}))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue