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

Support Yabeda server in a new process #22

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

etsenake
Copy link
Contributor

@etsenake etsenake commented Nov 6, 2022

Should fix #21

I've been working on getting yabeda into our app which runs on passenger. I finally have it running, but faced a couple of issues that I've been able to fix manually in our app but wanted to upstream some of those changes
Issue 1: Thread gets killed by passenger as a long-running request
Issue 2 ✅ : Metrics become pretty bloated when we haven't deployed in a while I imagine this would be a problem on weekends where the app is up for days. The addition of rack deflater shrunk the size of the metrics logged by close to 90% in my testing:

With Rack deflater Without Rack deflater
1355 15918
1538 16851
1582 17784

Depending on your scrape timeout on your prometheus server this could or could not be a problem ours is set pretty low but has worked fine for other exporters we have.

Issue 3[Just a minor annoyance 😅 ]: When running in clustered mode if app isn't preloaded the other processes or threads error out with Errno::EADDRINUSE doesn't kill the app just pollutes the start up logs a bit

Changes

  • add support for turning on rack deflater for the rack app
  • add support for starting the metrics server in a separate process
  • add support for suppressing Errno::EADDRINUSE when running in clustered mode in production apps

Gearing up to go live Monday with these changes and a couple others others in relation to resque on Monday so any feedback would be greatly appreciated.

Shameless plug: because we use resque I wrote a small extension for metrics around activejob for us to get some insight similar to what y’all have done for sidekiq and faktory. Check it out here

@etsenake etsenake changed the title add support for turning on rack deflater for the rack app add support for starting the metrics server in a separate process add support for suppressing Errno::EADDRINUSE when running in clustered mode in production apps Support Yabeda server in a new process Nov 6, 2022
@etsenake etsenake marked this pull request as ready for review November 6, 2022 00:09
@etsenake
Copy link
Contributor Author

etsenake commented Nov 6, 2022

I could also split this up into multiple PRs if that makes it easier to review unsure who to add as a reviewer though @Envek are you the person to review? 😅

Copy link
Member

@Envek Envek left a comment

Choose a reason for hiding this comment

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

Hey, thank you very much for your pull request! It has many interesting things and many surprising ones :-D

When running in clustered mode if app isn't preloaded the other processes or threads error out with Errno::EADDRINUSE doesn't kill the app just pollutes the start up logs a bit

Trying to run a metrics exporter process from every clustered worker and hope for a luck that some of them will start listening on a port feels very wrong to me. If you want to start separate process, isn't it better to start completely independent process just to export metrics then? Let it be managed separately by your runtime (whether it will be Systemd service on a server or sidecar container in Kubernetes pod).

Explicitly run separate process which will only export metrics from all processes on the same machine and nothing else.

Example of such exporter process can be found here: https://gist.github.com/Envek/96f297c1dfbac8ae5afa7e4abff78f0b

lib/yabeda/prometheus/exporter.rb Outdated Show resolved Hide resolved
lib/yabeda/prometheus/exporter.rb Outdated Show resolved Hide resolved
lib/yabeda/prometheus/version.rb Outdated Show resolved Hide resolved
def start_server_in_process!(**rack_app_options)
pid = Process.fork do
# re-configure yabeda since we're in a new process
Yabeda.configure!
Copy link
Member

Choose a reason for hiding this comment

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

Will it really work?

I believe that if yabeda was already configured before fork, it won't allow to call this method.

See https://github.com/yabeda-rb/yabeda/blob/be2700fb3a3694b4f17c92d6c038ca37221d9ce7/lib/yabeda.rb#L91 (I believe instance variable values are preserved after fork)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that’s what I thought too but i was seeing the same behaviour on prefork puma and passenger where if I don’t call configure! again in the process I get an empty page and no metrics are served via the endpoint from what I can tell it won’t serve metrics if they aren’t registered on the specific process. Also if you want, you could pull it down and try it out. Perhaps where I’m installing our metrics is the problem? It’s in an initializer though which seems pretty typical a possible reason could also be because we’re using direct file store? I’ll try out one of the other stores and see if they have the same issue if not I could conditionally call configure!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Figured out why sub-processes don't have the configured metrics declared, its because the configure!method is called in an after_initialize hook which never gets called in the sub process I'll make sure to check if its already configured like its being done here. If you're forking a process its pretty likely that you're not planning on running your entire app initialization process

@Envek
Copy link
Member

Envek commented Nov 8, 2022

Also added your yabeda-activejob to the Yabeda plugin list. Thanks for sharing!

@etsenake
Copy link
Contributor Author

Awesome! Apologies for taking so long to get back to this was at a work conference for the past couple days getting those changes in, test some things around calling configure! over the next little bit. I'll ping you once it's ready for another

Josh Etsenake added 5 commits November 10, 2022 07:23
add support for starting the metrics server in a separate process
add support for suppressing Errno::EADDRINUSE when running in clustered mode in production apps
@etsenake etsenake force-pushed the add-starting-metrics-server-in-a-new-process branch from 8519389 to 0bd3421 Compare November 10, 2022 12:28
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.

WEBrick suddenly shuts down with no errors
2 participants