Resync oxy with original repository
This commit is contained in:
parent
da5e4a13bf
commit
bee8ebb00b
31 changed files with 650 additions and 808 deletions
27
vendor/github.com/vulcand/oxy/cbreaker/cbreaker.go
generated
vendored
27
vendor/github.com/vulcand/oxy/cbreaker/cbreaker.go
generated
vendored
|
@ -1,4 +1,4 @@
|
|||
// package cbreaker implements circuit breaker similar to https://github.com/Netflix/Hystrix/wiki/How-it-Works
|
||||
// Package cbreaker implements circuit breaker similar to https://github.com/Netflix/Hystrix/wiki/How-it-Works
|
||||
//
|
||||
// Vulcan circuit breaker watches the error condtion to match
|
||||
// after which it activates the fallback scenario, e.g. returns the response code
|
||||
|
@ -31,6 +31,8 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/mailgun/timetools"
|
||||
"github.com/vulcand/oxy/memmetrics"
|
||||
"github.com/vulcand/oxy/utils"
|
||||
|
@ -60,7 +62,6 @@ type CircuitBreaker struct {
|
|||
fallback http.Handler
|
||||
next http.Handler
|
||||
|
||||
log utils.Logger
|
||||
clock timetools.TimeProvider
|
||||
}
|
||||
|
||||
|
@ -75,7 +76,6 @@ func New(next http.Handler, expression string, options ...CircuitBreakerOption)
|
|||
fallbackDuration: defaultFallbackDuration,
|
||||
recoveryDuration: defaultRecoveryDuration,
|
||||
fallback: defaultFallback,
|
||||
log: utils.NullLogger,
|
||||
}
|
||||
|
||||
for _, s := range options {
|
||||
|
@ -100,6 +100,11 @@ func New(next http.Handler, expression string, options ...CircuitBreakerOption)
|
|||
}
|
||||
|
||||
func (c *CircuitBreaker) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
if log.GetLevel() >= log.DebugLevel {
|
||||
logEntry := log.WithField("Request", utils.DumpHttpRequest(req))
|
||||
logEntry.Debug("vulcand/oxy/circuitbreaker: begin ServeHttp on request")
|
||||
defer logEntry.Debug("vulcand/oxy/circuitbreaker: competed ServeHttp on request")
|
||||
}
|
||||
if c.activateFallback(w, req) {
|
||||
c.fallback.ServeHTTP(w, req)
|
||||
return
|
||||
|
@ -121,7 +126,7 @@ func (c *CircuitBreaker) activateFallback(w http.ResponseWriter, req *http.Reque
|
|||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
|
||||
c.log.Infof("%v is in error state", c)
|
||||
log.Infof("%v is in error state", c)
|
||||
|
||||
switch c.state {
|
||||
case stateStandby:
|
||||
|
@ -186,13 +191,13 @@ func (c *CircuitBreaker) exec(s SideEffect) {
|
|||
}
|
||||
go func() {
|
||||
if err := s.Exec(); err != nil {
|
||||
c.log.Errorf("%v side effect failure: %v", c, err)
|
||||
log.Errorf("%v side effect failure: %v", c, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (c *CircuitBreaker) setState(new cbState, until time.Time) {
|
||||
c.log.Infof("%v setting state to %v, until %v", c, new, until)
|
||||
log.Infof("%v setting state to %v, until %v", c, new, until)
|
||||
c.state = new
|
||||
c.until = until
|
||||
switch new {
|
||||
|
@ -225,7 +230,7 @@ func (c *CircuitBreaker) checkAndSet() {
|
|||
c.lastCheck = c.clock.UtcNow().Add(c.checkPeriod)
|
||||
|
||||
if c.state == stateTripped {
|
||||
c.log.Infof("%v skip set tripped", c)
|
||||
log.Infof("%v skip set tripped", c)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -309,14 +314,6 @@ func Fallback(h http.Handler) CircuitBreakerOption {
|
|||
}
|
||||
}
|
||||
|
||||
// Logger adds logging for the CircuitBreaker.
|
||||
func Logger(l utils.Logger) CircuitBreakerOption {
|
||||
return func(c *CircuitBreaker) error {
|
||||
c.log = l
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// cbState is the state of the circuit breaker
|
||||
type cbState int
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue