Skip to content

Commit

Permalink
Make maintenance mode header configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
2k-joker committed Apr 14, 2024
1 parent 4f2065c commit 742a473
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/httpigeon/circuit_breaker/fuse_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def initialize(response = nil, exception = nil)
end

class FuseConfig
DEFAULT_MM_TIMEOUT_HEADER = 'X-Maintenance-Mode-Timeout'.freeze

attr_reader :max_failures_count,
:min_failures_count,
:failure_rate_threshold,
Expand All @@ -31,7 +33,7 @@ def initialize(fuse_options = {})
@sample_window = fuse_options[:sample_window] || HTTPigeon.fuse_sample_window
@sleep_window = fuse_options[:sleep_window] || HTTPigeon.fuse_sleep_window
@error_codes_watchlist = fuse_options[:error_codes_watchlist].to_a | HTTPigeon.fuse_error_codes_watchlist.to_a
@maintenance_mode_header = 'X-Maintenance-Timeout'
@maintenance_mode_header = fuse_options[:maintenance_mode_header] || DEFAULT_MM_TIMEOUT_HEADER

@on_open_circuit = if HTTPigeon.fuse_on_circuit_open.respond_to?(:call)
HTTPigeon.fuse_on_circuit_open
Expand All @@ -48,7 +50,8 @@ def to_h
failure_rate_threshold: failure_rate_threshold,
sample_window: sample_window,
sleep_window: sleep_window,
error_codes_watchlist: error_codes_watchlist
error_codes_watchlist: error_codes_watchlist,
maintenance_mode_header: maintenance_mode_header
}
end

Expand Down
2 changes: 1 addition & 1 deletion spec/httpigeon/circuit_breaker/fuse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

context 'when the response has a maintenance mode header' do
it 'opens the circuit and increments failure count' do
response = double('response', headers: { 'X-Maintenance-Timeout' => '10' })
response = double('response', headers: { 'X-Maintenance-Mode-Timeout' => '10' })

fuse.execute { response }

Expand Down

0 comments on commit 742a473

Please sign in to comment.