Skip to content

Count Resets When Circuit Breaker Enters Open State #72

@hamzagoc

Description

@hamzagoc

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
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions