mirror of
https://github.com/gravitational/teleport
synced 2024-10-19 16:53:57 +00:00
Allow breaker tripped error to be configurable (#32869)
This commit is contained in:
parent
99b4cb4d3d
commit
afb2eab0fa
|
@ -103,7 +103,7 @@ func (s State) String() string {
|
|||
|
||||
// ErrStateTripped will be returned from executions performed while the CircuitBreaker
|
||||
// is in StateTripped
|
||||
var ErrStateTripped = trace.ConnectionProblem(nil, "breaker is tripped")
|
||||
var ErrStateTripped = &trace.ConnectionProblemError{Message: "breaker is tripped"}
|
||||
|
||||
// Config contains configuration of the CircuitBreaker
|
||||
type Config struct {
|
||||
|
@ -134,6 +134,9 @@ type Config struct {
|
|||
IsSuccessful func(v interface{}, err error) bool
|
||||
// Logger is the logger
|
||||
Logger logrus.FieldLogger
|
||||
// TrippedErrorMessage is an optional message to use as the error message when the CircuitBreaker
|
||||
// is tripped. Defaults to ErrStateTripped if not provided.
|
||||
TrippedErrorMessage string
|
||||
}
|
||||
|
||||
// TripFn determines if the CircuitBreaker should be tripped based
|
||||
|
@ -331,7 +334,11 @@ func (c *CircuitBreaker) beforeExecution() (uint64, error) {
|
|||
|
||||
switch {
|
||||
case state == StateTripped:
|
||||
return generation, ErrStateTripped
|
||||
if c.cfg.TrippedErrorMessage != "" {
|
||||
return generation, trace.ConnectionProblem(nil, c.cfg.TrippedErrorMessage)
|
||||
}
|
||||
|
||||
return generation, trace.Wrap(ErrStateTripped)
|
||||
}
|
||||
|
||||
c.metrics.execute()
|
||||
|
|
|
@ -86,6 +86,8 @@ var _ ClientI = &Client{}
|
|||
func NewClient(cfg client.Config, params ...roundtrip.ClientParam) (*Client, error) {
|
||||
cfg.DialInBackground = true
|
||||
|
||||
cfg.CircuitBreakerConfig.TrippedErrorMessage = "Unable to communicate with the Teleport Auth Service"
|
||||
|
||||
if err := cfg.CheckAndSetDefaults(); err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue