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

Add sidekiq swarm integration #555

Merged
merged 1 commit into from
Oct 11, 2024
Merged

Conversation

fatkodima
Copy link
Contributor

We use sidekiq enterprise, which has a swarm feature (https://github.com/sidekiq/sidekiq/wiki/Ent-Multi-Process).
It has a master process, which preloads the gems and application and forks child processes. When master preloads the gems, it also loads coverband. Coverband sets at_exit hook and a background thread (Coverband::Background) in the master. But when it forks the child processes, only the at_exit hook remains in the child, but the background thread is not working anymore (in the dead state).

I spent a good amount of time to figure out why we have some coverage missed, even though the code is clearly running in production.

I propose to add a simple integration for sidekiq swarm to make future people lifes easier.

Maybe it is also a good idea to make the solution more generic by somehow identifying when the process was forked and recreate the background thread? 🤔

lib/coverband.rb Outdated
@@ -116,6 +116,7 @@ def self.runtime_coverage!
start
end
require "coverband/integrations/resque" if defined? ::Resque
require "coverband/integrations/sidekiq" if defined? ::Sidekiq::Enterprise::Swarm
Copy link
Owner

Choose a reason for hiding this comment

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

if this is not for the free or pro, but just swarm, can the integration file be sidekiq_swarm

@danmayer
Copy link
Owner

yeah, there are so many different servers, I have in the past tried to document how you need to handle before_fork and after_fork... the middleware design is intended to work generically across forking web servers... but we could look more at an approach like redis-client and fork detection....

https://github.com/redis-rb/redis-client/blob/43b894880252a91e0aa4de14b12d16af5a7b26d5/lib/redis_client/pid_cache.rb#L19

I think that coverband is a bit unique in that it needs to load and start the share library coverage before you load your other code, so it has the early initialization issue... but then it also has to deal with forking and starting a background thread... There are definitely ways to improve this and split out the shared lib coverage support from the worker thread and adapter connections... but that is probably a sizable refactoring.

@danmayer
Copy link
Owner

thanks for the work @fatkodima take a look at my comments and let me know how you want to test things and verify, guessing an RC release, but you could also point to your fork and verify things work and let me know

@fatkodima
Copy link
Contributor Author

Changed to sidekiq_swarm.

I was able to replicate the problem locally and pointed the app to the local changes of this gem and it works.

@danmayer danmayer merged commit 0cd5726 into danmayer:main Oct 11, 2024
79 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants