1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Log puma config if the env variable LOG_CONFIG exists (#2472)

This commit is contained in:
Carlos Castellanos Vera 2020-11-02 16:32:37 +01:00 committed by GitHub
parent 5f8b5fc407
commit c1b6071ae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 0 deletions

View file

@ -2,6 +2,7 @@
* Features
* Your feature goes here <Most recent on the top, like GitHub> (#Github Number)
* Prints the loaded configuration if the environment variable `PUMA_LOG_CONFIG` is present ([#2472])
* Integrate with systemd's watchdog and notification features ([#2438])
* Adds max_fast_inline as a configuration option for the Server object ([#2406])
* You can now fork workers from worker 0 using SIGURG w/o fork_worker enabled [#2449]

View file

@ -85,6 +85,9 @@ Puma provides numerous options. Consult `puma -h` (or `puma --help`) for a full
You can also find several configuration examples as part of the
[test](https://github.com/puma/puma/tree/master/test/config) suite.
For debugging purposes, you can set the environment variable `PUMA_LOG_CONFIG` with a value
and the loaded configuration will be printed as part of the boot process.
### Thread Pool
Puma uses a thread pool. You can set the minimum and maximum number of threads that are available in the pool with the `-t` (or `--threads`) flag:

View file

@ -92,6 +92,12 @@ module Puma
end
end
end
def final_options
default_options
.merge(file_options)
.merge(user_options)
end
end
# The main configuration class of Puma.
@ -290,6 +296,10 @@ module Puma
end
end
def final_options
@options.final_options
end
def self.temp_path
require 'tmpdir'

View file

@ -87,6 +87,8 @@ module Puma
Puma.stats_object = @runner
@status = :run
log_config if ENV['PUMA_LOG_CONFIG']
end
attr_reader :binder, :events, :config, :options, :restart_dir
@ -521,5 +523,14 @@ module Puma
Bundler.with_unbundled_env { yield }
end
end
def log_config
log "Configuration:"
@config.final_options
.each { |config_key, value| log "- #{config_key}: #{value}" }
log "\n"
end
end
end

View file

@ -265,6 +265,13 @@ class TestConfigFile < TestConfigFileBase
assert_equal 0, Puma::Configuration.new.options.default_options[:workers]
end
def test_final_options_returns_merged_options
conf = Puma::Configuration.new({ min_threads: 1, max_threads: 2 }, { min_threads: 2 })
assert_equal 1, conf.final_options[:min_threads]
assert_equal 2, conf.final_options[:max_threads]
end
private
def assert_run_hooks(hook_name, options = {})

View file

@ -158,6 +158,22 @@ class TestLauncher < Minitest::Test
launcher.run
end
def test_log_config_enabled
ENV['PUMA_LOG_CONFIG'] = "1"
assert_match(/Configuration:/, launcher.events.stdout.string)
launcher.config.final_options.each do |config_key, _value|
assert_match(/#{config_key}/, launcher.events.stdout.string)
end
ENV.delete('PUMA_LOG_CONFIG')
end
def test_log_config_disabled
refute_match /Configuration:/, launcher.events.stdout.string
end
private
def events