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

Configurable log levels #418

Merged
merged 1 commit into from
Aug 16, 2023
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

### Configuring the SSH log level

```yaml
ssh:
log_level: debug
```

Valid levels are `debug`, `info`, `warn`, `error` and `fatal` (default).
### Using env variables

You can inject env variables into the app containers using `env`:
Expand Down
2 changes: 1 addition & 1 deletion lib/mrsk/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def to_h
service_with_version: service_with_version,
env_args: env_args,
volume_args: volume_args,
ssh_options: ssh.options,
ssh_options: ssh.to_h,
sshkit: sshkit.to_h,
builder: builder.to_h,
accessories: raw_config.accessories,
Expand Down
16 changes: 15 additions & 1 deletion lib/mrsk/configuration/ssh.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Mrsk::Configuration::Ssh
LOGGER = ::Logger.new(STDERR)

def initialize(config:)
@config = config.raw_config.ssh || {}
end
Expand All @@ -16,9 +18,21 @@ def proxy
end

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

private
attr_accessor :config

def logger
LOGGER.tap { |logger| logger.level = log_level }
end

def log_level
config.fetch("log_level", :fatal)
end
end
10 changes: 7 additions & 3 deletions test/configuration/ssh_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ class ConfigurationSshTest < ActiveSupport::TestCase
assert_equal "root", @config.ssh.options[:user]

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

test "ssh options with proxy host" do
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

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" }) })
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
2 changes: 1 addition & 1 deletion test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class ConfigurationTest < ActiveSupport::TestCase
:absolute_image=>"dhh/app:missing",
:service_with_version=>"app-missing",
: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=>{},
:volume_args=>["--volume", "/local/path:/container/path"],
:builder=>{},
Expand Down
2 changes: 1 addition & 1 deletion test/integration/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MainTest < IntegrationTest
assert_equal "app-#{version}", config[:service_with_version]
assert_equal [], config[:env_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 [ "--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])
Expand Down
Loading