yabeda-rb / yabeda-puma-plugin

Collects Puma web-server metrics from puma control panel
MIT License
69 stars 16 forks source link

Got empty response from metrics endpoint when starting server via bundle exec puma. #21

Open hanyueitaro opened 2 years ago

hanyueitaro commented 2 years ago

Overview

Hello.

I use this gem integrating with rails. However,

This may be caused by the similar problem:

https://github.com/yabeda-rb/yabeda/issues/15

Reproduce

I reproduced this problem in puma single worker mode, and exposing metrics on different port from puma.

max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"

port ENV.fetch("PORT") { 3000 }

environment ENV.fetch("RAILS_ENV") { "development" }

pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

# workers ENV.fetch("WEB_CONCURRENCY") { 2 }

plugin :tmp_restart
activate_control_app
plugin :yabeda
plugin :yabeda_prometheus
jsimpson commented 2 years ago

I also ran into this problem yesterday when setting up Yabeda w/the Puma and Prometheus plugins.

zabolotnov87 commented 1 year ago

The issue occurs when you try to start the puma server directly: bundle exec puma -C config/puma.rb

What happens:

  1. puma reads config file, finds plugin :yabeda and requires lib/puma/plugin/yabeda.rb
  2. then executes require 'yabeda/puma/plugin.rb'
  3. then require 'yabeda'
  4. then require "yabeda/railtie" if defined?(Rails) https://github.com/yabeda-rb/yabeda/blob/00ebff7036d9adcee9790e7612c3894b26a712cf/lib/yabeda.rb#L11

defined?(Rails) returns nil, so railtie is not loaded and Yabeda.configure! will not be invoked: https://github.com/yabeda-rb/yabeda/blob/7b578d8cb9ff72a2c33f954344e37f9fdeff72d0/lib/yabeda/railtie.rb#L7

As a workaround, you can add require "yabeda/railtie" into your config/initializers/yabeda.rb.

Envek commented 1 year ago

Thanks a lot for your investigation, @zabolotnov87!

I didn't even think about railtie, but now it seems to be pretty obvious :facepalm: