command/agent: HTTP Check: Create httpClient in Start()
For long (>10s) interval checks the http timeout is 10s, otherwise thetimeout is the interval. This means that a check *should* return before the next check begins.
This commit is contained in:
parent
27fe823fd2
commit
e116c03f86
|
@ -6,7 +6,6 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -688,9 +687,6 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType, persist
|
|||
HTTP: chkType.HTTP,
|
||||
Interval: chkType.Interval,
|
||||
Logger: a.logger,
|
||||
httpClient: &http.Client{
|
||||
Timeout: chkType.Interval,
|
||||
},
|
||||
}
|
||||
http.Start()
|
||||
a.checkHTTPs[check.CheckID] = http
|
||||
|
|
|
@ -280,6 +280,18 @@ type CheckHTTP struct {
|
|||
func (c *CheckHTTP) Start() {
|
||||
c.stopLock.Lock()
|
||||
defer c.stopLock.Unlock()
|
||||
|
||||
if c.httpClient == nil {
|
||||
// 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 {
|
||||
c.httpClient = &http.Client{Timeout: c.Interval}
|
||||
} else {
|
||||
c.httpClient = &http.Client{Timeout: 10 * time.Second}
|
||||
}
|
||||
}
|
||||
|
||||
c.stop = false
|
||||
c.stopCh = make(chan struct{})
|
||||
go c.run()
|
||||
|
|
Loading…
Reference in New Issue