Class: Stoplight::Infrastructure::Storage::CompatibilityRecoveryMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb

Overview

When a circuit is RED (open), Stoplight periodically sends “recovery probes” to test whether the protected service has recovered. These test requests have different semantics than normal requests and their metrics are tracked separately.

Like CompatibilityMetrics, this adapter will be replaced with purpose-built recovery metrics implementations (e.g., ConsecutiveSuccessMetrics) once the metrics extraction is complete.

Examples:

Recovery probe flow

# Circuit is RED, start probing
recovery_metrics = CompatibilityRecoveryMetrics.new(
  data_store: redis_store,
  config: circuit_config
)

recovery_metrics.record_success
recovery_metrics.metrics_snapshot # => 1 success, 0 failures

Instance Method Summary collapse

Constructor Details

#initialize(data_store:, config:) ⇒ CompatibilityRecoveryMetrics

Returns a new instance of CompatibilityRecoveryMetrics.



25
26
27
28
# File 'lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb', line 25

def initialize(data_store:, config:)
  @data_store = data_store
  @config = config
end

Instance Method Details

#clearObject



38
# File 'lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb', line 38

def clear = data_store.clear_recovery_metrics(config)

#metrics_snapshotObject



30
# File 'lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb', line 30

def metrics_snapshot = data_store.get_recovery_metrics(config)

#record_failure(error) ⇒ Object

Tracks failed circuit breaker execution



36
# File 'lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb', line 36

def record_failure(error) = data_store.record_recovery_probe_failure(config, error)

#record_successObject

Tracks successful circuit breaker execution



33
# File 'lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb', line 33

def record_success = data_store.record_recovery_probe_success(config)