From 60527de3558606951d5cee68f5cff746388467c3 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Thu, 6 Feb 2020 00:48:58 -0500 Subject: [PATCH] keep consul service metrics in global variables (#6764) Signed-off-by: yeya24 --- discovery/consul/consul.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/discovery/consul/consul.go b/discovery/consul/consul.go index f0db8d762..add89357b 100644 --- a/discovery/consul/consul.go +++ b/discovery/consul/consul.go @@ -83,6 +83,10 @@ var ( []string{"endpoint", "call"}, ) + // Initialize metric vectors. + servicesRPCDuraion = rpcDuration.WithLabelValues("catalog", "services") + serviceRPCDuraion = rpcDuration.WithLabelValues("catalog", "service") + // DefaultSDConfig is the default Consul SD configuration. DefaultSDConfig = SDConfig{ TagSeparator: ",", @@ -141,10 +145,6 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { func init() { prometheus.MustRegister(rpcFailuresCount) prometheus.MustRegister(rpcDuration) - - // Initialize metric vectors. - rpcDuration.WithLabelValues("catalog", "service") - rpcDuration.WithLabelValues("catalog", "services") } // Discovery retrieves target information from a Consul server @@ -355,7 +355,7 @@ func (d *Discovery) watchServices(ctx context.Context, ch chan<- []*targetgroup. } srvs, meta, err := catalog.Services(opts.WithContext(ctx)) elapsed := time.Since(t0) - rpcDuration.WithLabelValues("catalog", "services").Observe(elapsed.Seconds()) + servicesRPCDuraion.Observe(elapsed.Seconds()) // Check the context before in order to exit early. select { @@ -470,7 +470,7 @@ func (srv *consulService) watch(ctx context.Context, ch chan<- []*targetgroup.Gr } nodes, meta, err := catalog.ServiceMultipleTags(srv.name, srv.tags, opts.WithContext(ctx)) elapsed := time.Since(t0) - rpcDuration.WithLabelValues("catalog", "service").Observe(elapsed.Seconds()) + serviceRPCDuraion.Observe(elapsed.Seconds()) // Check the context before in order to exit early. select {