|
|
@ -94,6 +94,7 @@ type discovery struct { |
|
|
|
clientDatacenter string |
|
|
|
clientDatacenter string |
|
|
|
tagSeparator string |
|
|
|
tagSeparator string |
|
|
|
logger log.Logger |
|
|
|
logger log.Logger |
|
|
|
|
|
|
|
oldSourceList map[string]bool |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (d *discovery) parseServiceNodes(resp *http.Response, name string) (*targetgroup.Group, error) { |
|
|
|
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
|
|
|
|
// 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
|
|
|
|
// gone as far as consul is concerned, that will be picked up during the next iteration of
|
|
|
|
// the outer loop.
|
|
|
|
// the outer loop.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newSourceList := make(map[string]bool) |
|
|
|
for name := range srvs { |
|
|
|
for name := range srvs { |
|
|
|
if name == "consul" { |
|
|
|
if name == "consul" { |
|
|
|
continue |
|
|
|
continue |
|
|
@ -195,7 +198,17 @@ func (d *discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
tgs = append(tgs, tg) |
|
|
|
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 { |
|
|
|
if err == nil { |
|
|
|
// We're returning all Consul services as a single targetgroup.
|
|
|
|
// We're returning all Consul services as a single targetgroup.
|
|
|
|
ch <- tgs |
|
|
|
ch <- tgs |
|
|
@ -216,6 +229,7 @@ func newDiscovery(conf sdConfig) (*discovery, error) { |
|
|
|
refreshInterval: conf.RefreshInterval, |
|
|
|
refreshInterval: conf.RefreshInterval, |
|
|
|
tagSeparator: conf.TagSeparator, |
|
|
|
tagSeparator: conf.TagSeparator, |
|
|
|
logger: logger, |
|
|
|
logger: logger, |
|
|
|
|
|
|
|
oldSourceList: make(map[string]bool), |
|
|
|
} |
|
|
|
} |
|
|
|
return cd, nil |
|
|
|
return cd, nil |
|
|
|
} |
|
|
|
} |
|
|
|