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
Puma.stats is now a hash, not JSON. #2086
Merged
+41
−18
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ def initialize(idx, pid, phase, options) | |
@first_term_sent = nil | ||
@started_at = Time.now | ||
@last_checkin = Time.now | ||
@last_status = '{}' | ||
@last_status = {} | ||
@term = false | ||
end | ||
|
||
|
@@ -94,7 +94,11 @@ def term? | |
|
||
def ping!(status) | ||
@last_checkin = Time.now | ||
@last_status = status | ||
captures = status.match(/{ "backlog":(?<backlog>\d*), "running":(?<running>\d*), "pool_capacity":(?<pool_capacity>\d*), "max_threads": (?<max_threads>\d*) }/) | ||
@last_status = captures.names.inject({}) do |hash, key| | ||
hash[key.to_sym] = captures[key].to_i | ||
hash | ||
end | ||
end | ||
|
||
def ping_timeout?(which) | ||
|
@@ -352,9 +356,26 @@ def reload_worker_directory | |
# the master process. | ||
def stats | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is so much more readable now ❤️ |
||
old_worker_count = @workers.count { |w| w.phase != @phase } | ||
booted_worker_count = @workers.count { |w| w.booted? } | ||
worker_status = '[' + @workers.map { |w| %Q!{ "started_at": "#{w.started_at.utc.iso8601}", "pid": #{w.pid}, "index": #{w.index}, "phase": #{w.phase}, "booted": #{w.booted?}, "last_checkin": "#{w.last_checkin.utc.iso8601}", "last_status": #{w.last_status} }!}.join(",") + ']' | ||
%Q!{ "started_at": "#{@started_at.utc.iso8601}", "workers": #{@workers.size}, "phase": #{@phase}, "booted_workers": #{booted_worker_count}, "old_workers": #{old_worker_count}, "worker_status": #{worker_status} }! | ||
worker_status = @workers.map do |w| | ||
{ | ||
started_at: w.started_at.utc.iso8601, | ||
pid: w.pid, | ||
index: w.index, | ||
phase: w.phase, | ||
booted: w.booted?, | ||
last_checkin: w.last_checkin.utc.iso8601, | ||
last_status: w.last_status, | ||
} | ||
end | ||
|
||
{ | ||
started_at: @started_at.utc.iso8601, | ||
workers: @workers.size, | ||
phase: @phase, | ||
booted_workers: worker_status.count { |w| w[:booted] }, | ||
old_workers: old_worker_count, | ||
worker_status: worker_status, | ||
} | ||
end | ||
|
||
def preload? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ def halt | |
end | ||
|
||
def stats | ||
"{}" | ||
{} | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we just deserialize the JSON response, really?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to have been an intentional decision made in the past to not let Puma rely on the JSON gem. I don't have the context as to why but since this is an internal message being passed I figured it wasn't worth adding the dependency as we don't need more robust parsing. I can change it if you still think it is better to do so.