From 3a7120bc07f49d35f537bee6c81f5e6e849de0f8 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Sun, 2 Aug 2020 15:39:23 +0200 Subject: [PATCH] Consul: Reduce WatchTimeout to 2m and set it as timeout for requests Signed-off-by: Julien Pivotto --- discovery/consul/consul.go | 4 ++-- discovery/consul/consul_test.go | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/discovery/consul/consul.go b/discovery/consul/consul.go index faafc5855..93adc1f6c 100644 --- a/discovery/consul/consul.go +++ b/discovery/consul/consul.go @@ -36,7 +36,7 @@ import ( ) const ( - watchTimeout = 10 * time.Minute + watchTimeout = 2 * time.Minute retryInterval = 15 * time.Second // addressLabel is the name for the label containing a target's address. @@ -184,7 +184,7 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) { } wrapper := &http.Client{ Transport: transport, - Timeout: 35 * time.Second, + Timeout: time.Duration(watchTimeout) + 15*time.Second, } clientConf := &consul.Config{ diff --git a/discovery/consul/consul_test.go b/discovery/consul/consul_test.go index 5be2bd73b..2409d7dbc 100644 --- a/discovery/consul/consul_test.go +++ b/discovery/consul/consul_test.go @@ -223,20 +223,20 @@ func newServer(t *testing.T) (*httptest.Server, *SDConfig) { switch r.URL.String() { case "/v1/agent/self": response = AgentAnswer - case "/v1/health/service/test?node-meta=rack_name%3A2304&stale=&tag=tag1&wait=600000ms": + case "/v1/health/service/test?node-meta=rack_name%3A2304&stale=&tag=tag1&wait=120000ms": response = ServiceTestAnswer - case "/v1/health/service/test?wait=600000ms": + case "/v1/health/service/test?wait=120000ms": response = ServiceTestAnswer - case "/v1/health/service/other?wait=600000ms": + case "/v1/health/service/other?wait=120000ms": response = `[]` - case "/v1/catalog/services?node-meta=rack_name%3A2304&stale=&wait=600000ms": + case "/v1/catalog/services?node-meta=rack_name%3A2304&stale=&wait=120000ms": response = ServicesTestAnswer - case "/v1/catalog/services?wait=600000ms": + case "/v1/catalog/services?wait=120000ms": response = ServicesTestAnswer - case "/v1/catalog/services?index=1&node-meta=rack_name%3A2304&stale=&wait=600000ms": + case "/v1/catalog/services?index=1&node-meta=rack_name%3A2304&stale=&wait=120000ms": time.Sleep(5 * time.Second) response = ServicesTestAnswer - case "/v1/catalog/services?index=1&wait=600000ms": + case "/v1/catalog/services?index=1&wait=120000ms": time.Sleep(5 * time.Second) response = ServicesTestAnswer default: