Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force-enable host-based circuits #243

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/semian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,19 @@ def require_keys!(required = [], **options)
end
end

def hostname
v = %w(KUBE_HOSTNAME KUBE_HOST_NAME KUBE_NODENAME KUBE_NODE_NAME NODENAME NODE_NAME HOSTNAME HOST_NAME)
michaelkipper marked this conversation as resolved.
Show resolved Hide resolved
var = v.find { |x| ENV.include?(x) }
ENV[var] if var
end

def force_host_circuits?
return false unless ENV.include?('SEMIAN_CIRCUIT_BREAKER_FORCE_HOST')
ENV['SEMIAN_CIRCUIT_BREAKER_FORCE_HOST'].split(',').include?(hostname)
end

if Semian.semaphores_enabled?
ENV['SEMIAN_CIRCUIT_BREAKER_IMPL'] = 'host' if force_host_circuits?
require 'semian/semian'
else
Semian::MAX_TICKETS = 0
Expand Down
11 changes: 11 additions & 0 deletions test/semian_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,15 @@ def test_disabled_via_semian_wide_env_var
ensure
ENV.delete('SEMIAN_DISABLED')
end

def test_force_host_circuits
refute force_host_circuits?
ENV['SEMIAN_CIRCUIT_BREAKER_FORCE_HOST'] = 'machine-1,machine-2,machine-3'
refute force_host_circuits?
ENV['KUBE_HOSTNAME'] = 'machine-2'
assert force_host_circuits?
ensure
ENV.delete('SEMIAN_CIRCUIT_BREAKER_FORCE_HOST')
ENV.delete('KUBE_HOSTNAME')
end
end