Configurable log levels

Allow ssh log_level to be set - this will help to debug connection
issues.
This commit is contained in:
Donal McBreen
2023-08-15 16:36:06 +01:00
parent 715cd94bbf
commit 1163c3de07
6 changed files with 33 additions and 7 deletions

View File

@@ -258,6 +258,14 @@ ssh:
proxy_command: aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p' --region=us-east-1 ## ssh via aws ssm proxy_command: aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p' --region=us-east-1 ## ssh via aws ssm
``` ```
### Configuring the SSH log level
```yaml
ssh:
log_level: debug
```
Valid levels are `debug`, `info`, `warn`, `error` and `fatal` (default).
### Using env variables ### Using env variables
You can inject env variables into the app containers using `env`: You can inject env variables into the app containers using `env`:

View File

@@ -172,7 +172,7 @@ class Mrsk::Configuration
service_with_version: service_with_version, service_with_version: service_with_version,
env_args: env_args, env_args: env_args,
volume_args: volume_args, volume_args: volume_args,
ssh_options: ssh.options, ssh_options: ssh.to_h,
sshkit: sshkit.to_h, sshkit: sshkit.to_h,
builder: builder.to_h, builder: builder.to_h,
accessories: raw_config.accessories, accessories: raw_config.accessories,

View File

@@ -1,4 +1,6 @@
class Mrsk::Configuration::Ssh class Mrsk::Configuration::Ssh
LOGGER = ::Logger.new(STDERR)
def initialize(config:) def initialize(config:)
@config = config.raw_config.ssh || {} @config = config.raw_config.ssh || {}
end end
@@ -16,9 +18,21 @@ class Mrsk::Configuration::Ssh
end end
def options def options
{ user: user, proxy: proxy, auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30 }.compact { user: user, proxy: proxy, auth_methods: [ "publickey" ], logger: logger, keepalive: true, keepalive_interval: 30 }.compact
end
def to_h
options.except(:logger).merge(log_level: log_level)
end end
private private
attr_accessor :config attr_accessor :config
def logger
LOGGER.tap { |logger| logger.level = log_level }
end
def log_level
config.fetch("log_level", :fatal)
end
end end

View File

@@ -17,16 +17,20 @@ class ConfigurationSshTest < ActiveSupport::TestCase
assert_equal "root", @config.ssh.options[:user] assert_equal "root", @config.ssh.options[:user]
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "user" => "app" }) }) config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "user" => "app" }) })
assert_equal "app", @config.ssh.options[:user] assert_equal "app", config.ssh.options[:user]
assert_equal 4, config.ssh.options[:logger].level
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "log_level" => "debug" }) })
assert_equal 0, config.ssh.options[:logger].level
end end
test "ssh options with proxy host" do test "ssh options with proxy host" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "1.2.3.4" }) }) config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "1.2.3.4" }) })
assert_equal "root@1.2.3.4", @config.ssh.options[:proxy].jump_proxies assert_equal "root@1.2.3.4", config.ssh.options[:proxy].jump_proxies
end end
test "ssh options with proxy host and user" do test "ssh options with proxy host and user" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "app@1.2.3.4" }) }) config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "app@1.2.3.4" }) })
assert_equal "app@1.2.3.4", @config.ssh.options[:proxy].jump_proxies assert_equal "app@1.2.3.4", config.ssh.options[:proxy].jump_proxies
end end
end end

View File

@@ -258,7 +258,7 @@ class ConfigurationTest < ActiveSupport::TestCase
:absolute_image=>"dhh/app:missing", :absolute_image=>"dhh/app:missing",
:service_with_version=>"app-missing", :service_with_version=>"app-missing",
:env_args=>["-e", "REDIS_URL=\"redis://x/y\""], :env_args=>["-e", "REDIS_URL=\"redis://x/y\""],
:ssh_options=>{ :user=>"root", :auth_methods=>["publickey"], keepalive: true, keepalive_interval: 30 }, :ssh_options=>{ :user=>"root", :auth_methods=>["publickey"], log_level: :fatal, keepalive: true, keepalive_interval: 30 },
:sshkit=>{}, :sshkit=>{},
:volume_args=>["--volume", "/local/path:/container/path"], :volume_args=>["--volume", "/local/path:/container/path"],
:builder=>{}, :builder=>{},

View File

@@ -51,7 +51,7 @@ class MainTest < IntegrationTest
assert_equal "app-#{version}", config[:service_with_version] assert_equal "app-#{version}", config[:service_with_version]
assert_equal [], config[:env_args] assert_equal [], config[:env_args]
assert_equal [], config[:volume_args] assert_equal [], config[:volume_args]
assert_equal({ user: "root", auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30 }, config[:ssh_options]) assert_equal({ user: "root", auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30, log_level: :fatal }, config[:ssh_options])
assert_equal({ "multiarch" => false, "args" => { "COMMIT_SHA" => version } }, config[:builder]) assert_equal({ "multiarch" => false, "args" => { "COMMIT_SHA" => version } }, config[:builder])
assert_equal [ "--log-opt", "max-size=\"10m\"" ], config[:logging] assert_equal [ "--log-opt", "max-size=\"10m\"" ], config[:logging]
assert_equal({ "path" => "/up", "port" => 3000, "max_attempts" => 7, "cmd" => "wget -qO- http://localhost > /dev/null" }, config[:healthcheck]) assert_equal({ "path" => "/up", "port" => 3000, "max_attempts" => 7, "cmd" => "wget -qO- http://localhost > /dev/null" }, config[:healthcheck])