mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 10:43:17 -04:00
middleware/proxy: async health checks (#749)
* Switches out Unhealthy bool for OkUntil timestamp * Make sure servers are healthy forever if there are no health checks * Moves health check off into a go routine to avoid blocking conditions * Improved logging info * Fixes initial date * Fixes health checking; alters tests to adapt to async health checking * Moves future variable into static upstream and populates it in more places * Restores silencing of stdout during testing * Restores silencing of stdout during testing * keeps check url string once built * Removes debug message * uses zero value to signal no checking; reduces in-mutex code to a fetch
This commit is contained in:
@@ -30,6 +30,7 @@ func NewLookupWithOption(hosts []string, opts Options) Proxy {
|
||||
Spray: nil,
|
||||
FailTimeout: 10 * time.Second,
|
||||
MaxFails: 3, // TODO(miek): disable error checking for simple lookups?
|
||||
Future: 60 * time.Second,
|
||||
ex: newDNSExWithOption(opts),
|
||||
}
|
||||
|
||||
@@ -40,21 +41,29 @@ func NewLookupWithOption(hosts []string, opts Options) Proxy {
|
||||
Fails: 0,
|
||||
FailTimeout: upstream.FailTimeout,
|
||||
|
||||
Unhealthy: false,
|
||||
CheckDown: func(upstream *staticUpstream) UpstreamHostDownFunc {
|
||||
return func(uh *UpstreamHost) bool {
|
||||
if uh.Unhealthy {
|
||||
return true
|
||||
|
||||
down := false
|
||||
|
||||
uh.checkMu.Lock()
|
||||
until := uh.OkUntil
|
||||
uh.checkMu.Unlock()
|
||||
|
||||
if !until.IsZero() && time.Now().After(until) {
|
||||
down = true
|
||||
}
|
||||
|
||||
fails := atomic.LoadInt32(&uh.Fails)
|
||||
if fails >= upstream.MaxFails && upstream.MaxFails != 0 {
|
||||
return true
|
||||
down = true
|
||||
}
|
||||
return false
|
||||
return down
|
||||
}
|
||||
}(upstream),
|
||||
WithoutPathPrefix: upstream.WithoutPathPrefix,
|
||||
}
|
||||
|
||||
upstream.Hosts[i] = uh
|
||||
}
|
||||
p.Upstreams = &[]Upstream{upstream}
|
||||
|
||||
Reference in New Issue
Block a user