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)