Skip to content

Commit

Permalink
Allow accessing to internal counters (eg. for stats) (#25)
Browse files Browse the repository at this point in the history
* Allow accessing to internal counters (eg. for stats)

* Add mutex for Counts() function, fix godoc
  • Loading branch information
Enrico204 authored Feb 16, 2021
1 parent 9c3b944 commit dd874f9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gobreaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ func (cb *CircuitBreaker) State() State {
return state
}

// Counts returns internal counters
func (cb *CircuitBreaker) Counts() Counts {
cb.mutex.Lock()
defer cb.mutex.Unlock()

return cb.counts
}

// Execute runs the given request if the CircuitBreaker accepts it.
// Execute returns an error instantly if the CircuitBreaker rejects the request.
// Otherwise, Execute returns the result of the request.
Expand Down Expand Up @@ -246,6 +254,11 @@ func (tscb *TwoStepCircuitBreaker) State() State {
return tscb.cb.State()
}

// Counts returns internal counters
func (tscb *TwoStepCircuitBreaker) Counts() Counts {
return tscb.cb.Counts()
}

// Allow checks if a new request can proceed. It returns a callback that should be used to
// register the success or failure in a separate step. If the circuit breaker doesn't allow
// requests, it returns an error.
Expand Down

0 comments on commit dd874f9

Please sign in to comment.