func()

in pkg/discovery/discovery.go [119:146]


func (d *discovery) cleanDeletedTargets() []*targetgroup.Group {
	tgs := []*targetgroup.Group{}
	backfillSources := make(map[targetSourceSpec]bool)
	for k, _ := range d.oldSources {
		if _, ok := d.newSources[k]; !ok {
			//First check if there is failure syncing service or namespace corresponding to this source
			if _, ok := d.failedNamespaces[k.namespace]; ok {
				level.Info(d.logger).Log("msg", "Skipping cleanup because failure syncing namespace", "namespace", k.String())
				backfillSources[k] = true
				continue
			}
			if _, ok := d.failedSources[k]; ok {
				level.Info(d.logger).Log("msg", "Skipping cleanup because failure syncing source", "source", k.String())
				backfillSources[k] = true
				continue
			}
			level.Info(d.logger).Log("msg", "Cleaning up empty source", "source", k.String())
			tgs = append(tgs, &targetgroup.Group{Source: k.String()})
		}
	}
	d.oldSources = d.newSources
	//backfill oldSources with the failed ones
	for k, v := range backfillSources {
		d.oldSources[k] = v
	}

	return tgs
}