mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-12 16:44:05 -08:00
some fixies for consul sd. (#7799)
* discovery/consul: make duration more accurate. Signed-off-by: johncming <johncming@yahoo.com> * discovery/consul: fix bug when context done. Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
parent
2f2a51a43a
commit
a5beb627ff
|
@ -363,13 +363,13 @@ func (d *Discovery) watchServices(ctx context.Context, ch chan<- []*targetgroup.
|
||||||
catalog := d.client.Catalog()
|
catalog := d.client.Catalog()
|
||||||
level.Debug(d.logger).Log("msg", "Watching services", "tags", strings.Join(d.watchedTags, ","))
|
level.Debug(d.logger).Log("msg", "Watching services", "tags", strings.Join(d.watchedTags, ","))
|
||||||
|
|
||||||
t0 := time.Now()
|
|
||||||
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,
|
||||||
}
|
}
|
||||||
|
t0 := time.Now()
|
||||||
srvs, meta, err := catalog.Services(opts.WithContext(ctx))
|
srvs, meta, err := catalog.Services(opts.WithContext(ctx))
|
||||||
elapsed := time.Since(t0)
|
elapsed := time.Since(t0)
|
||||||
servicesRPCDuration.Observe(elapsed.Seconds())
|
servicesRPCDuration.Observe(elapsed.Seconds())
|
||||||
|
@ -456,18 +456,19 @@ func (d *Discovery) watchService(ctx context.Context, ch chan<- []*targetgroup.G
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(d.refreshInterval)
|
ticker := time.NewTicker(d.refreshInterval)
|
||||||
|
defer ticker.Stop()
|
||||||
var lastIndex uint64
|
var lastIndex uint64
|
||||||
health := srv.client.Health()
|
health := srv.client.Health()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
ticker.Stop()
|
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
srv.watch(ctx, ch, health, &lastIndex)
|
srv.watch(ctx, ch, health, &lastIndex)
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,7 +479,6 @@ func (d *Discovery) watchService(ctx context.Context, ch chan<- []*targetgroup.G
|
||||||
func (srv *consulService) watch(ctx context.Context, ch chan<- []*targetgroup.Group, health *consul.Health, lastIndex *uint64) {
|
func (srv *consulService) watch(ctx context.Context, ch chan<- []*targetgroup.Group, health *consul.Health, lastIndex *uint64) {
|
||||||
level.Debug(srv.logger).Log("msg", "Watching service", "service", srv.name, "tags", strings.Join(srv.tags, ","))
|
level.Debug(srv.logger).Log("msg", "Watching service", "service", srv.name, "tags", strings.Join(srv.tags, ","))
|
||||||
|
|
||||||
t0 := time.Now()
|
|
||||||
opts := &consul.QueryOptions{
|
opts := &consul.QueryOptions{
|
||||||
WaitIndex: *lastIndex,
|
WaitIndex: *lastIndex,
|
||||||
WaitTime: watchTimeout,
|
WaitTime: watchTimeout,
|
||||||
|
@ -486,6 +486,7 @@ func (srv *consulService) watch(ctx context.Context, ch chan<- []*targetgroup.Gr
|
||||||
NodeMeta: srv.discovery.watchedNodeMeta,
|
NodeMeta: srv.discovery.watchedNodeMeta,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t0 := time.Now()
|
||||||
serviceNodes, meta, err := health.ServiceMultipleTags(srv.name, srv.tags, false, opts.WithContext(ctx))
|
serviceNodes, meta, err := health.ServiceMultipleTags(srv.name, srv.tags, false, opts.WithContext(ctx))
|
||||||
elapsed := time.Since(t0)
|
elapsed := time.Since(t0)
|
||||||
serviceRPCDuration.Observe(elapsed.Seconds())
|
serviceRPCDuration.Observe(elapsed.Seconds())
|
||||||
|
|
Loading…
Reference in a new issue