Module: Philiprehberger::Circuit::Metrics

Included in:
Breaker
Defined in:
lib/philiprehberger/circuit/metrics.rb

Overview

Thread-safe counters and state change log for monitoring

Instance Method Summary collapse

Instance Method Details

#last_failureHash?

Most recent failure recorded by the breaker, or nil when none has occurred since the last reset.

Returns:

  • (Hash, nil)

    { at: Time, error_class: Class, message: String } or nil



15
16
17
# File 'lib/philiprehberger/circuit/metrics.rb', line 15

def last_failure
  @mutex.synchronize { @last_failure&.dup }
end

#metricsObject



7
8
9
# File 'lib/philiprehberger/circuit/metrics.rb', line 7

def metrics
  @mutex.synchronize { metrics_snapshot }
end

#metrics_reset!Object

Zero counters and clear the state-change log without altering the circuit’s current state or transition timestamps. Also clears the last_failure record.



22
23
24
25
26
27
28
29
30
31
# File 'lib/philiprehberger/circuit/metrics.rb', line 22

def metrics_reset!
  @mutex.synchronize do
    @success_count = 0
    @metrics_failure_count = 0
    @rejected_count = 0
    @state_changes = []
    @last_failure = nil
  end
  self
end