mirror of https://github.com/hashicorp/consul
- add Timeout field to CheckType and CheckHTTP to make http request timeout configurable by the client
parent
58eba95b98
commit
e87afe341b
|
@ -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()
|
||||||
|
|
|
@ -36,7 +36,8 @@ type CheckType struct {
|
||||||
HTTP string
|
HTTP string
|
||||||
Interval time.Duration
|
Interval time.Duration
|
||||||
|
|
||||||
TTL time.Duration
|
Timeout 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}
|
||||||
|
|
Loading…
Reference in New Issue