|
|
@ -113,8 +113,11 @@ type SDConfig struct { |
|
|
|
Services []string `yaml:"services,omitempty"` |
|
|
|
Services []string `yaml:"services,omitempty"` |
|
|
|
// A list of tags used to filter instances inside a service. Services must contain all tags in the list.
|
|
|
|
// A list of tags used to filter instances inside a service. Services must contain all tags in the list.
|
|
|
|
ServiceTags []string `yaml:"tags,omitempty"` |
|
|
|
ServiceTags []string `yaml:"tags,omitempty"` |
|
|
|
// Desired node metadata.
|
|
|
|
// Desired node metadata. As of Consul 1.14, consider `filter` instead.
|
|
|
|
NodeMeta map[string]string `yaml:"node_meta,omitempty"` |
|
|
|
NodeMeta map[string]string `yaml:"node_meta,omitempty"` |
|
|
|
|
|
|
|
// Consul filter string
|
|
|
|
|
|
|
|
// See https://www.consul.io/api-docs/catalog#filtering-1, for syntax
|
|
|
|
|
|
|
|
Filter string `yaml:"filter,omitempty"` |
|
|
|
|
|
|
|
|
|
|
|
HTTPClientConfig config.HTTPClientConfig `yaml:",inline"` |
|
|
|
HTTPClientConfig config.HTTPClientConfig `yaml:",inline"` |
|
|
|
} |
|
|
|
} |
|
|
@ -174,6 +177,7 @@ type Discovery struct { |
|
|
|
watchedServices []string // Set of services which will be discovered.
|
|
|
|
watchedServices []string // Set of services which will be discovered.
|
|
|
|
watchedTags []string // Tags used to filter instances of a service.
|
|
|
|
watchedTags []string // Tags used to filter instances of a service.
|
|
|
|
watchedNodeMeta map[string]string |
|
|
|
watchedNodeMeta map[string]string |
|
|
|
|
|
|
|
watchedFilter string |
|
|
|
allowStale bool |
|
|
|
allowStale bool |
|
|
|
refreshInterval time.Duration |
|
|
|
refreshInterval time.Duration |
|
|
|
finalizer func() |
|
|
|
finalizer func() |
|
|
@ -218,6 +222,7 @@ func NewDiscovery(conf *SDConfig, logger *slog.Logger, metrics discovery.Discove |
|
|
|
watchedServices: conf.Services, |
|
|
|
watchedServices: conf.Services, |
|
|
|
watchedTags: conf.ServiceTags, |
|
|
|
watchedTags: conf.ServiceTags, |
|
|
|
watchedNodeMeta: conf.NodeMeta, |
|
|
|
watchedNodeMeta: conf.NodeMeta, |
|
|
|
|
|
|
|
watchedFilter: conf.Filter, |
|
|
|
allowStale: conf.AllowStale, |
|
|
|
allowStale: conf.AllowStale, |
|
|
|
refreshInterval: time.Duration(conf.RefreshInterval), |
|
|
|
refreshInterval: time.Duration(conf.RefreshInterval), |
|
|
|
clientDatacenter: conf.Datacenter, |
|
|
|
clientDatacenter: conf.Datacenter, |
|
|
@ -361,13 +366,14 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { |
|
|
|
// entire list of services.
|
|
|
|
// entire list of services.
|
|
|
|
func (d *Discovery) watchServices(ctx context.Context, ch chan<- []*targetgroup.Group, lastIndex *uint64, services map[string]func()) { |
|
|
|
func (d *Discovery) watchServices(ctx context.Context, ch chan<- []*targetgroup.Group, lastIndex *uint64, services map[string]func()) { |
|
|
|
catalog := d.client.Catalog() |
|
|
|
catalog := d.client.Catalog() |
|
|
|
d.logger.Debug("Watching services", "tags", strings.Join(d.watchedTags, ",")) |
|
|
|
d.logger.Debug("Watching services", "tags", strings.Join(d.watchedTags, ","), "filter", d.watchedFilter) |
|
|
|
|
|
|
|
|
|
|
|
opts := &consul.QueryOptions{ |
|
|
|
opts := &consul.QueryOptions{ |
|
|
|
WaitIndex: *lastIndex, |
|
|
|
WaitIndex: *lastIndex, |
|
|
|
WaitTime: watchTimeout, |
|
|
|
WaitTime: watchTimeout, |
|
|
|
AllowStale: d.allowStale, |
|
|
|
AllowStale: d.allowStale, |
|
|
|
NodeMeta: d.watchedNodeMeta, |
|
|
|
NodeMeta: d.watchedNodeMeta, |
|
|
|
|
|
|
|
Filter: d.watchedFilter, |
|
|
|
} |
|
|
|
} |
|
|
|
t0 := time.Now() |
|
|
|
t0 := time.Now() |
|
|
|
srvs, meta, err := catalog.Services(opts.WithContext(ctx)) |
|
|
|
srvs, meta, err := catalog.Services(opts.WithContext(ctx)) |
|
|
|