|
|
@ -274,19 +274,15 @@ func (ts *targetSet) runProviders(ctx context.Context, providers map[string]Targ |
|
|
|
updates := make(chan []*config.TargetGroup) |
|
|
|
updates := make(chan []*config.TargetGroup) |
|
|
|
|
|
|
|
|
|
|
|
go func(name string, prov TargetProvider) { |
|
|
|
go func(name string, prov TargetProvider) { |
|
|
|
var initial []*config.TargetGroup |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select { |
|
|
|
select { |
|
|
|
case <-ctx.Done(): |
|
|
|
case <-ctx.Done(): |
|
|
|
wg.Done() |
|
|
|
case initial, ok := <-updates: |
|
|
|
return |
|
|
|
// Handle the case that a target provider exits and closes the channel
|
|
|
|
case initial = <-updates: |
|
|
|
// before the context is done.
|
|
|
|
// First set of all targets the provider knows.
|
|
|
|
if !ok { |
|
|
|
case <-time.After(5 * time.Second): |
|
|
|
break |
|
|
|
// Initial set didn't arrive. Act as if it was empty
|
|
|
|
|
|
|
|
// and wait for updates later on.
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// First set of all targets the provider knows.
|
|
|
|
for _, tgroup := range initial { |
|
|
|
for _, tgroup := range initial { |
|
|
|
targets, err := targetsFromGroup(tgroup, ts.config) |
|
|
|
targets, err := targetsFromGroup(tgroup, ts.config) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -295,6 +291,10 @@ func (ts *targetSet) runProviders(ctx context.Context, providers map[string]Targ |
|
|
|
} |
|
|
|
} |
|
|
|
ts.tgroups[name+"/"+tgroup.Source] = targets |
|
|
|
ts.tgroups[name+"/"+tgroup.Source] = targets |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
case <-time.After(5 * time.Second): |
|
|
|
|
|
|
|
// Initial set didn't arrive. Act as if it was empty
|
|
|
|
|
|
|
|
// and wait for updates later on.
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wg.Done() |
|
|
|
wg.Done() |
|
|
|
|
|
|
|
|
|
|
@ -303,7 +303,12 @@ func (ts *targetSet) runProviders(ctx context.Context, providers map[string]Targ |
|
|
|
select { |
|
|
|
select { |
|
|
|
case <-ctx.Done(): |
|
|
|
case <-ctx.Done(): |
|
|
|
return |
|
|
|
return |
|
|
|
case tgs := <-updates: |
|
|
|
case tgs, ok := <-updates: |
|
|
|
|
|
|
|
// Handle the case that a target provider exits and closes the channel
|
|
|
|
|
|
|
|
// before the context is done.
|
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
for _, tg := range tgs { |
|
|
|
for _, tg := range tgs { |
|
|
|
if err := ts.update(name, tg); err != nil { |
|
|
|
if err := ts.update(name, tg); err != nil { |
|
|
|
log.With("target_group", tg).Errorf("Target update failed: %s", err) |
|
|
|
log.With("target_group", tg).Errorf("Target update failed: %s", err) |
|
|
|