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

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

Open
hanyueitaro opened this issue Dec 28, 2021 · 4 comments

Comments

@hanyueitaro
Copy link

Overview

Hello.

I use this gem integrating with rails. However,

  • When I run rails app via bundle exec puma -C config/puma.rb, I get empty response from metrics endpoint.
  • On the other hand, when via bundle exec rails s, I get valid response from metrics endpoint.

This may be caused by the similar problem:

yabeda-rb/yabeda#15

Reproduce

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

  • ruby: 3.0.2
  • rails: 6.1.4.1
  • gems:
    • yabeda-puma-plugin: 0.6.0
    • yabeda-prometheus: 0.7.0
    • yabeda: 0.11.0
    • prometheus-client: 2.1.0
  • config/puma.rb:
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
Copy link

jsimpson commented Aug 5, 2022

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

@zabolotnov87
Copy link

zabolotnov87 commented May 30, 2023

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
Copy link
Member

Envek commented May 31, 2023

Thanks a lot for your investigation, @zabolotnov87!

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

@chornbec
Copy link

chornbec commented Nov 5, 2024

Are there updated instructions for this plugin when running puma directly with bundle exec puma ...? I've followed these instructions and I still get a undefined method registry' for module Yabeda::Prometheus::Mmap` error. After reading the mentioned issue here, the plugin only works if I have the following:

# ./config/initializers/yabeda.rb
# I actually found that I don't even need this file for the plugin to work...
require 'yabeda/railtie'
# ./config/puma.rb
# ...
# ...
require 'yabeda/prometheus/mmap'
activate_control_app
plugin :yabeda
plugin :yabeda_prometheus

before_fork do # for puma cluster mode
  Yabeda.configure!
end
# Gemfile
# ... some other gems
gem 'yabeda'
gem 'yabeda-prometheus-mmap'
gem 'yabeda-puma-plugin'
# ... some other gems

Is this setup expected? Doesn't look as straightforward as the docs make it seem.

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

No branches or pull requests

5 participants