From 9d311827783ba0a74ad90d6bf41a61376fa104f3 Mon Sep 17 00:00:00 2001 From: Thomas Jackson Date: Mon, 8 Oct 2018 15:55:40 -0700 Subject: [PATCH] Backport https://github.com/prometheus/prometheus/pull/4443 --- Gopkg.lock | 2 +- .../prometheus/prometheus/discovery/consul/consul.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 22acc5bb5..abffaa538 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -510,7 +510,7 @@ "web/api/v2", "web/ui" ] - revision = "b40118231a4d4974b97ec3f45120f8266ca562d6" + revision = "6fd27a1bc5a9a6cc4fa09f94766dd0ee3fe258a8" source = "github.com/jacksontj/prometheus" [[projects]] diff --git a/vendor/github.com/prometheus/prometheus/discovery/consul/consul.go b/vendor/github.com/prometheus/prometheus/discovery/consul/consul.go index a0bcf1346..a3ca662d2 100644 --- a/vendor/github.com/prometheus/prometheus/discovery/consul/consul.go +++ b/vendor/github.com/prometheus/prometheus/discovery/consul/consul.go @@ -145,7 +145,6 @@ func init() { // and updates them via watches. type Discovery struct { client *consul.Client - clientConf *consul.Config clientDatacenter string tagSeparator string watchedServices []string // Set of services which will be discovered. @@ -153,6 +152,7 @@ type Discovery struct { watchedNodeMeta map[string]string allowStale bool refreshInterval time.Duration + finalizer func() logger log.Logger } @@ -167,6 +167,7 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) { return nil, err } transport := &http.Transport{ + IdleConnTimeout: 5 * time.Duration(conf.RefreshInterval), TLSClientConfig: tls, DialContext: conntrack.NewDialContextFunc( conntrack.DialWithTracing(), @@ -195,14 +196,14 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) { } cd := &Discovery{ client: client, - clientConf: clientConf, tagSeparator: conf.TagSeparator, watchedServices: conf.Services, watchedTag: conf.ServiceTag, watchedNodeMeta: conf.NodeMeta, allowStale: conf.AllowStale, refreshInterval: time.Duration(conf.RefreshInterval), - clientDatacenter: clientConf.Datacenter, + clientDatacenter: conf.Datacenter, + finalizer: transport.CloseIdleConnections, logger: logger, } return cd, nil @@ -296,6 +297,9 @@ func (d *Discovery) initialize(ctx context.Context) { // Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { + if d.finalizer != nil { + defer d.finalizer() + } d.initialize(ctx) if len(d.watchedServices) == 0 || d.watchedTag != "" {