From e87afe341b77a23949198ccb57e7c8a86dab73ee Mon Sep 17 00:00:00 2001 From: arnaud briche Date: Thu, 29 Jan 2015 13:37:48 +0700 Subject: [PATCH] - add Timeout field to CheckType and CheckHTTP to make http request timeout configurable by the client --- command/agent/agent.go | 1 + command/agent/check.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index a0bd63539a..9de70594c5 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -721,6 +721,7 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType, persist CheckID: check.CheckID, HTTP: chkType.HTTP, Interval: chkType.Interval, + Timeout: chkType.Timeout, Logger: a.logger, } http.Start() diff --git a/command/agent/check.go b/command/agent/check.go index 71aa0eba0e..352c986fe3 100644 --- a/command/agent/check.go +++ b/command/agent/check.go @@ -36,7 +36,8 @@ type CheckType struct { HTTP string Interval time.Duration - TTL time.Duration + Timeout time.Duration + TTL time.Duration Notes string } @@ -269,6 +270,7 @@ type CheckHTTP struct { CheckID string HTTP string Interval time.Duration + Timeout time.Duration Logger *log.Logger httpClient *http.Client @@ -287,7 +289,9 @@ func (c *CheckHTTP) Start() { // For long (>10s) interval checks the http timeout is 10s, otherwise the // timeout is the interval. This means that a check *should* return // before the next check begins. - if c.Interval < 10*time.Second { + if c.Timeout > 0 && c.Timeout < c.Interval { + c.httpClient = &http.Client{Timeout: c.Timeout} + } else if c.Interval < 10*time.Second { c.httpClient = &http.Client{Timeout: c.Interval} } else { c.httpClient = &http.Client{Timeout: 10 * time.Second}