Send 'Retry-After' to comply with RFC6585.
This commit is contained in:
parent
027093a5a5
commit
8d75aba7eb
29 changed files with 435 additions and 172 deletions
12
vendor/github.com/vulcand/oxy/cbreaker/ratio.go
generated
vendored
12
vendor/github.com/vulcand/oxy/cbreaker/ratio.go
generated
vendored
|
@ -19,13 +19,17 @@ type ratioController struct {
|
|||
tm timetools.TimeProvider
|
||||
allowed int
|
||||
denied int
|
||||
|
||||
log *log.Logger
|
||||
}
|
||||
|
||||
func newRatioController(tm timetools.TimeProvider, rampUp time.Duration) *ratioController {
|
||||
func newRatioController(tm timetools.TimeProvider, rampUp time.Duration, log *log.Logger) *ratioController {
|
||||
return &ratioController{
|
||||
duration: rampUp,
|
||||
tm: tm,
|
||||
start: tm.UtcNow(),
|
||||
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,17 +38,17 @@ func (r *ratioController) String() string {
|
|||
}
|
||||
|
||||
func (r *ratioController) allowRequest() bool {
|
||||
log.Debugf("%v", r)
|
||||
r.log.Debugf("%v", r)
|
||||
t := r.targetRatio()
|
||||
// This condition answers the question - would we satisfy the target ratio if we allow this request?
|
||||
e := r.computeRatio(r.allowed+1, r.denied)
|
||||
if e < t {
|
||||
r.allowed++
|
||||
log.Debugf("%v allowed", r)
|
||||
r.log.Debugf("%v allowed", r)
|
||||
return true
|
||||
}
|
||||
r.denied++
|
||||
log.Debugf("%v denied", r)
|
||||
r.log.Debugf("%v denied", r)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue