From 97950a3faea3e88f643708f25cc88159e5441cce Mon Sep 17 00:00:00 2001 From: Augustin Husson Date: Sun, 16 Sep 2018 14:36:09 +0200 Subject: [PATCH] remove group if the target is empty at adapter level Signed-off-by: Augustin Husson --- discovery/manager.go | 5 ----- documentation/examples/custom-sd/adapter/adapter.go | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/discovery/manager.go b/discovery/manager.go index ab8328924..bb4409fea 100644 --- a/discovery/manager.go +++ b/discovery/manager.go @@ -232,11 +232,6 @@ func (m *Manager) updateGroup(poolKey poolKey, tgs []*targetgroup.Group) { m.targets[poolKey] = make(map[string]*targetgroup.Group) } m.targets[poolKey][tg.Source] = tg - - // Clear the key in the case where the targets is empty. - if tg.Targets == nil || len(tg.Targets) <= 0 { - delete(m.targets[poolKey], tg.Source) - } } } } diff --git a/documentation/examples/custom-sd/adapter/adapter.go b/documentation/examples/custom-sd/adapter/adapter.go index 6452a50f9..95bf09163 100644 --- a/documentation/examples/custom-sd/adapter/adapter.go +++ b/documentation/examples/custom-sd/adapter/adapter.go @@ -60,6 +60,12 @@ func (a *Adapter) generateTargetGroups(allTargetGroups map[string][]*targetgroup tempGroups := make(map[string]*customSD) for k, sdTargetGroups := range allTargetGroups { for i, group := range sdTargetGroups { + + // There is no target, so no need to keep it + if len(group.Targets) <= 0 { + continue + } + newTargets := make([]string, 0) newLabels := make(map[string]string)