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

Periodically send status to systemd #3006

Merged
merged 3 commits into from Feb 9, 2023

Conversation

QWYNG
Copy link
Contributor

@QWYNG QWYNG commented Oct 29, 2022

Description

Hi, Thank you for great gem.
Add test for #2833. Thank you @ekohl
it was not able to retrieve information from Puma.stats_hash properly.
So I have changed the logic in lib/puma/plugin/systemd.rb a little.

Description from #2833

With systemd it's possible to send a status line. This will show up when users run systemctl status puma.service.

Most of this code is based on puma-plugin-systemd.

At the moment this is completely untested, but I had written some code that I wanted to share. If anyone wants to finish this before I do, they should feel welcome to.

Closes #2604

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

@QWYNG QWYNG changed the title Add test for exohl set status Add test for exohl:set status Oct 29, 2022
@QWYNG QWYNG changed the title Add test for exohl:set status Add test for ekohl:set status Oct 29, 2022
@QWYNG QWYNG force-pushed the add_test_for_exohl_set_status branch 2 times, most recently from e98e6d7 to 3008009 Compare October 30, 2022 05:24
@nateberkopec nateberkopec added waiting-for-review Waiting on review from anyone feature systemd labels Nov 2, 2022
@dentarg dentarg changed the title Add test for ekohl:set status Periodically send status to systemd (#2833) with test Nov 5, 2022
@QWYNG QWYNG marked this pull request as ready for review November 11, 2022 01:43
@dentarg dentarg mentioned this pull request Jan 12, 2023
7 tasks
@dentarg dentarg changed the title Periodically send status to systemd (#2833) with test Periodically send status to systemd Jan 12, 2023
@dentarg
Copy link
Member

dentarg commented Jan 16, 2023

@QWYNG are you up for rebasing this PR? Sounds like potential users would be happy with it (latest replies in #2604)

Copy link
Contributor

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @QWYNG for taking my work and taking it over the finish line.

It does look the message gets trimmed so that could be a future improvement. Still, I think this is ready to merge.

Comment on lines 55 to 56
messages = Array.new(workers) do |i|
common_message(stats[:worker_status][i][:last_status])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look at the actual source, but would it be possible to iterate over stats[:worker_status] instead? Untested, but something like:

Suggested change
messages = Array.new(workers) do |i|
common_message(stats[:worker_status][i][:last_status])
messages = stats[:worker_status].values do |worker|
common_message(worker[:last_status])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
stats[:worker_status] is Array instanse.
So I modified it as follows

      messages = stats[:worker_status].map do |worker|
        common_message(worker[:last_status])
      end.join(',')

With systemd it's possible to send a status line. This will show up when
users run systemctl status puma.service.

Most of this code is based on puma-plugin-systemd.
@QWYNG QWYNG force-pushed the add_test_for_exohl_set_status branch from 3008009 to 91fa294 Compare January 17, 2023 03:59
@@ -10,7 +10,7 @@
Puma::Plugin.create do
def start(launcher)
begin
require 'sd_notify'
require_relative '../sd_notify'
rescue LoadError
launcher.log_writer.log "Systemd integration failed. It looks like you're trying to use systemd notify but don't have sd_notify gem installed"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that it's vendored (6d8b728), I don't think there's a chance that it will fail to load. Certainly the message is wrong now since the sd_notify gem is no longer needed.

@@ -29,6 +29,29 @@ def start_watchdog
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something went wrong in your rebase. This file is supposed to be deleted in the Rewrite systemd integration as a plugin commit.

ekohl and others added 2 commits January 17, 2023 23:59
The primary motiviation for this is that plugins have native integration
for background threads. This is much cleaner since it allows tracking of
those. For example, it's possible to clean up those threads in the test
suite.
@QWYNG QWYNG force-pushed the add_test_for_exohl_set_status branch from c644273 to 338ef29 Compare January 17, 2023 15:05
@QWYNG
Copy link
Contributor Author

QWYNG commented Jan 17, 2023

@dentarg
Rebased with some fix!

Copy link
Contributor

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@QWYNG
Copy link
Contributor Author

QWYNG commented Feb 9, 2023

Hi @dentarg, @nateberkopec
Could you please check this PR?

Copy link
Member

@dentarg dentarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, haven't used it myself, but I trust people from the community who seems to have tried this out!

@nateberkopec nateberkopec merged commit 964ddb3 into puma:master Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature systemd waiting-for-review Waiting on review from anyone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Utilize systemd-notify to add status details
4 participants