Skip to content

Commit 9fb115a

Browse files
author
Michael Kipper
authored
Merge pull request #243 from Shopify/mkipper/global-circuit-breaker-simple-integer
Force-enable host-based circuits
2 parents d3f252c + ea78022 commit 9fb115a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/semian.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,19 @@ def require_keys!(required = [], **options)
296296
end
297297
end
298298

299+
def hostname
300+
v = %w(KUBE_HOSTNAME KUBE_HOST_NAME KUBE_NODENAME KUBE_NODE_NAME NODENAME NODE_NAME HOSTNAME HOST_NAME)
301+
var = v.find { |x| ENV.include?(x) }
302+
ENV[var] if var
303+
end
304+
305+
def force_host_circuits?
306+
return false unless ENV.include?('SEMIAN_CIRCUIT_BREAKER_FORCE_HOST')
307+
ENV['SEMIAN_CIRCUIT_BREAKER_FORCE_HOST'].split(',').include?(hostname)
308+
end
309+
299310
if Semian.semaphores_enabled?
311+
ENV['SEMIAN_CIRCUIT_BREAKER_IMPL'] = 'host' if force_host_circuits?
300312
require 'semian/semian'
301313
else
302314
Semian::MAX_TICKETS = 0

test/semian_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,15 @@ def test_disabled_via_semian_wide_env_var
9191
ensure
9292
ENV.delete('SEMIAN_DISABLED')
9393
end
94+
95+
def test_force_host_circuits
96+
refute force_host_circuits?
97+
ENV['SEMIAN_CIRCUIT_BREAKER_FORCE_HOST'] = 'machine-1,machine-2,machine-3'
98+
refute force_host_circuits?
99+
ENV['KUBE_HOSTNAME'] = 'machine-2'
100+
assert force_host_circuits?
101+
ensure
102+
ENV.delete('SEMIAN_CIRCUIT_BREAKER_FORCE_HOST')
103+
ENV.delete('KUBE_HOSTNAME')
104+
end
94105
end

0 commit comments

Comments
 (0)