Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count Resets When Circuit Breaker Enters Open State #72

Open
hamzagoc opened this issue Nov 11, 2024 · 0 comments
Open

Count Resets When Circuit Breaker Enters Open State #72

hamzagoc opened this issue Nov 11, 2024 · 0 comments

Comments

@hamzagoc
Copy link

When the circuit breaker transitions into the open state, the count is reset. This reset prevents us from feeding accurate metrics to Prometheus at the exact moment of the state change. As a result, Prometheus cannot capture the metrics correctly during this critical transition phase.

Would it be possible to retain the current count value at the moment of the state change to ensure proper metric logging? This would help us get more accurate insights into the behavior of the circuit breaker.

https://github.com/sony/gobreaker/blob/master/v2/gobreaker.go#L366

func (cb *CircuitBreaker[T]) toNewGeneration(now time.Time) {
	cb.generation++
	cb.counts.clear()

	var zero time.Time
	switch cb.state {
	case StateClosed:
		if cb.interval == 0 {
			cb.expiry = zero
		} else {
			cb.expiry = now.Add(cb.interval)
		}
	case StateOpen:
		cb.expiry = now.Add(cb.timeout)
	default: // StateHalfOpen
		cb.expiry = zero
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant