Merge pull request #1024 from prometheus/fix-updatetargets-busyloop

Fix busylooping in case of no target providers.
This commit is contained in:
Julius Volz 2015-08-24 17:14:56 +02:00
commit 25a8bd50a5
2 changed files with 12 additions and 2 deletions

View file

@ -171,12 +171,15 @@ func (tm *TargetManager) Run() {
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.
func (tm *TargetManager) handleUpdates(ch <-chan targetGroupUpdate, done <-chan struct{}) {
for {
select {
case update := <-ch:
case update, ok := <-ch:
if !ok {
return
}
if update.tg == nil {
break
}

View file

@ -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{}))
}