- add Timeout field to CheckType and CheckHTTP to make http request timeout configurable by the client

pull/654/head
arnaud briche 2015-01-29 13:37:48 +07:00
parent 58eba95b98
commit e87afe341b
2 changed files with 7 additions and 2 deletions

View File

@ -721,6 +721,7 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType, persist
CheckID: check.CheckID, CheckID: check.CheckID,
HTTP: chkType.HTTP, HTTP: chkType.HTTP,
Interval: chkType.Interval, Interval: chkType.Interval,
Timeout: chkType.Timeout,
Logger: a.logger, Logger: a.logger,
} }
http.Start() http.Start()

View File

@ -36,6 +36,7 @@ type CheckType struct {
HTTP string HTTP string
Interval time.Duration Interval time.Duration
Timeout time.Duration
TTL time.Duration TTL time.Duration
Notes string Notes string
@ -269,6 +270,7 @@ type CheckHTTP struct {
CheckID string CheckID string
HTTP string HTTP string
Interval time.Duration Interval time.Duration
Timeout time.Duration
Logger *log.Logger Logger *log.Logger
httpClient *http.Client httpClient *http.Client
@ -287,7 +289,9 @@ func (c *CheckHTTP) Start() {
// For long (>10s) interval checks the http timeout is 10s, otherwise the // For long (>10s) interval checks the http timeout is 10s, otherwise the
// timeout is the interval. This means that a check *should* return // timeout is the interval. This means that a check *should* return
// before the next check begins. // 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} c.httpClient = &http.Client{Timeout: c.Interval}
} else { } else {
c.httpClient = &http.Client{Timeout: 10 * time.Second} c.httpClient = &http.Client{Timeout: 10 * time.Second}