From ea36efbbd177fc309884d35f428d0fc5dc371fca Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 25 May 2016 16:17:25 -0700 Subject: [PATCH 1/2] retrieval: document panic behavior --- retrieval/targetmanager.go | 1 + 1 file changed, 1 insertion(+) diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index dc02cae97..5592476f2 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -404,6 +404,7 @@ func providersFromConfig(cfg *config.ScrapeConfig) map[string]TargetProvider { } // targetsFromGroup builds targets based on the given TargetGroup and config. +// Panics if target group is nil. func targetsFromGroup(tg *config.TargetGroup, cfg *config.ScrapeConfig) ([]*Target, error) { targets := make([]*Target, 0, len(tg.Targets)) From 12b03db373e7a8f52eda727dcf7b1a4df9381d39 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 25 May 2016 16:59:16 -0700 Subject: [PATCH 2/2] retrieval: handle nil target groups from updates --- retrieval/targetmanager.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index 5592476f2..ed0886f82 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -288,6 +288,9 @@ func (ts *targetSet) runProviders(ctx context.Context, providers map[string]Targ } // First set of all targets the provider knows. for _, tgroup := range initial { + if tgroup == nil { + continue + } targets, err := targetsFromGroup(tgroup, ts.config) if err != nil { log.With("target_group", tgroup).Errorf("Target update failed: %s", err) @@ -333,6 +336,9 @@ func (ts *targetSet) runProviders(ctx context.Context, providers map[string]Targ // update handles a target group update from a target provider identified by the name. func (ts *targetSet) update(name string, tgroup *config.TargetGroup) error { + if tgroup == nil { + return nil + } targets, err := targetsFromGroup(tgroup, ts.config) if err != nil { return err