mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
fix targetGroup that disappear totally
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
This commit is contained in:
parent
3c0b130e5e
commit
9e6dc6f96c
|
@ -94,6 +94,7 @@ type discovery struct {
|
|||
clientDatacenter string
|
||||
tagSeparator string
|
||||
logger log.Logger
|
||||
oldSourceList map[string]bool
|
||||
}
|
||||
|
||||
func (d *discovery) parseServiceNodes(resp *http.Response, name string) (*targetgroup.Group, error) {
|
||||
|
@ -180,6 +181,8 @@ func (d *discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
|
|||
// list of targets simply because there may have been a timeout. If the service is actually
|
||||
// gone as far as consul is concerned, that will be picked up during the next iteration of
|
||||
// the outer loop.
|
||||
|
||||
newSourceList := make(map[string]bool)
|
||||
for name := range srvs {
|
||||
if name == "consul" {
|
||||
continue
|
||||
|
@ -195,7 +198,17 @@ func (d *discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
|
|||
break
|
||||
}
|
||||
tgs = append(tgs, tg)
|
||||
newSourceList[tg.Source] = true
|
||||
}
|
||||
// when targetGroup disappear, send an update with empty targetList
|
||||
for key := range d.oldSourceList {
|
||||
if !newSourceList[key] {
|
||||
tgs = append(tgs, &targetgroup.Group{
|
||||
Source: key,
|
||||
})
|
||||
}
|
||||
}
|
||||
d.oldSourceList = newSourceList
|
||||
if err == nil {
|
||||
// We're returning all Consul services as a single targetgroup.
|
||||
ch <- tgs
|
||||
|
@ -216,6 +229,7 @@ func newDiscovery(conf sdConfig) (*discovery, error) {
|
|||
refreshInterval: conf.RefreshInterval,
|
||||
tagSeparator: conf.TagSeparator,
|
||||
logger: logger,
|
||||
oldSourceList: make(map[string]bool),
|
||||
}
|
||||
return cd, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue