Skip to content

Commit

Permalink
Revert api change from #2086 introduce Puma.stats_hash api
Browse files Browse the repository at this point in the history
The change in #2086 is not backwards compatible with existing gems that parse the output of Puma.stats such as barnes.

Releasing a version of puma with this change would break anyone using the Barnes app and only in production. I'm proposing to keep the existing interface and instead add a new API. This buys us all the features of #2086 without causing any production facing downtime by customers due to API incompatibilities.

Unfortunately it requires that we serialize and the de-serialize the values. One prior benefit of returning json in a string was that it allowed an end user to de-serialize using a faster json algorithm such as `oj` via the "multi json" gem. But the performance penalty will be better than a stability break.
  • Loading branch information
schneems committed May 8, 2020
1 parent 6234e4b commit 6d8e889
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion History.md
Expand Up @@ -11,9 +11,9 @@
* Force shutdown responses can be overridden by using the `lowlevel_error_handler` config (#2203)
* Faster phased restart and worker timeout (#2121)
* New configuration option to set state file permissions (#2238)
* `Puma.stats_hash` returns a stats in Hash instead of a JSON string (#2086, #2253)

* Deprecations, Removals and Breaking API Changes
* `Puma.stats` now returns a Hash instead of a JSON string (#2086)
* `--control` has been removed. Use `--control-url` (#1487)
* `worker_directory` has been removed. Use `directory`.
* min_threads now set by environment variables PUMA_MIN_THREADS and MIN_THREADS. (#2143)
Expand Down
4 changes: 4 additions & 0 deletions lib/puma.rb
Expand Up @@ -20,6 +20,10 @@ def self.stats_object=(val)
end

def self.stats
@get_stats.stats.to_json
end

def self.stats_hash
@get_stats.stats
end

Expand Down
2 changes: 2 additions & 0 deletions test/test_cli.rb
Expand Up @@ -55,6 +55,8 @@ def test_control_for_tcp
body = s.read
s.close

assert_equal Puma.stats_hash, JSON.parse(Puma.stats, symbolize_names: true)

dmt = Puma::Configuration.new.default_max_threads
assert_match(/{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":#{dmt},"max_threads":#{dmt},"requests_count":0}/, body.split(/\r?\n/).last)

Expand Down
4 changes: 2 additions & 2 deletions test/test_launcher.rb
Expand Up @@ -139,7 +139,7 @@ def test_puma_stats
launcher.events.on_booted {launcher.stop}
launcher.run
Puma::Server::STAT_METHODS.each do |stat|
assert_includes Puma.stats, stat
assert_includes Puma.stats_hash, stat
end
end

Expand All @@ -154,7 +154,7 @@ def test_puma_stats_clustered
launcher = launcher(conf)
Thread.new do
sleep Puma::Const::WORKER_CHECK_INTERVAL + 1
status = Puma.stats[:worker_status].first[:last_status]
status = Puma.stats_hash[:worker_status].first[:last_status]
Puma::Server::STAT_METHODS.each do |stat|
assert_includes status, stat
end
Expand Down

0 comments on commit 6d8e889

Please sign in to comment.