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

undefined method `registry' error. #25

Open
rparjun opened this issue Aug 6, 2023 · 6 comments
Open

undefined method `registry' error. #25

rparjun opened this issue Aug 6, 2023 · 6 comments

Comments

@rparjun
Copy link

rparjun commented Aug 6, 2023

I am getting an exception while using yabeda_prometheus plugin in config/puma.rb
error:

Puma caught this error: undefined method `registry' for Yabeda::Prometheus:Module (NoMethodError)
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/yabeda-prometheus-0.9.0/lib/yabeda/prometheus/exporter.rb:53:in `initialize'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/rack-2.2.7/lib/rack/builder.rb:158:in `new'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/rack-2.2.7/lib/rack/builder.rb:158:in `block in use'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/rack-2.2.7/lib/rack/builder.rb:235:in `block in to_app'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/rack-2.2.7/lib/rack/builder.rb:235:in `each'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/rack-2.2.7/lib/rack/builder.rb:235:in `inject'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/rack-2.2.7/lib/rack/builder.rb:235:in `to_app'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/rack-2.2.7/lib/rack/builder.rb:244:in `call'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/puma-6.1.0/lib/puma/request.rb:98:in `block in handle_request'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/puma-6.1.0/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/puma-6.1.0/lib/puma/request.rb:97:in `handle_request'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/puma-6.1.0/lib/puma/server.rb:431:in `process_client'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/puma-6.1.0/lib/puma/server.rb:233:in `block in run'
/Users/arjun/x/vendor/cache/ruby/2.7.0/gems/puma-6.1.0/lib/puma/thread_pool.rb:147:in `block in spawn_thread'

puma.rb:

workers 2
threads 0, 16
port 3000
pidfile 'tmp/pids/puma.pid'

activate_control_app
plugin :yabeda
plugin :yabeda_prometheus

Versions:

    yabeda (0.12.0)
      anyway_config (>= 1.0, < 3)
      concurrent-ruby
      dry-initializer
    yabeda-prometheus (0.9.0)
      prometheus-client (>= 3.0, < 5.0)
      rack
      yabeda (~> 0.10)
    yabeda-puma-plugin (0.7.1)
      json
      puma
      yabeda (~> 0.5)
    yabeda-rails (0.9.0)
      activesupport
      anyway_config (>= 1.3, < 3)
      railties
      yabeda (~> 0.8)
    yabeda-sidekiq (0.10.0)
      anyway_config (>= 1.3, < 3)
      sidekiq
      yabeda (~> 0.6)


RUBY VERSION
   ruby 2.7.6p219

BUNDLED WITH
   2.3.5
@rparjun rparjun changed the title Error while using yabeda_prometheus undefined method `registry' error. Aug 6, 2023
@Envek
Copy link
Member

Envek commented Aug 7, 2023

Looks like plugin :yabeda_prometheus from yabeda-puma-plugin gem requires lib/yabeda/prometheus/exporter.rb from this yabeda-prometheus gem, which in turn doesn't require lib/yabeda/prometheus.rb where registry method is defined…

But lib/yabeda/prometheus.rb has require for lib/yabeda/prometheus/exporter.rb, is it safe to require it back from there?

Meanwhile you can put this require into your config/puma.rb:

+require "yabeda/prometheus/exporter"
 activate_control_app
 plugin :yabeda
 plugin :yabeda_prometheus

@rparjun
Copy link
Author

rparjun commented Aug 7, 2023

@Envek getting the same error after adding require "yabeda/prometheus/exporter"

@Envek
Copy link
Member

Envek commented Aug 7, 2023

Oh, sorry, try to require 'yabeda/prometheus':

+require "yabeda/prometheus"
 activate_control_app
 plugin :yabeda
 plugin :yabeda_prometheus

See also yabeda-rb/yabeda-puma-plugin#21 (comment) for some more context for a similar problem.

@rparjun
Copy link
Author

rparjun commented Aug 7, 2023

Thanks @Envek , requiring yabeda/prometheus works!

Only puma metrics are showing up, not the Rails metrics(yabeda-rails). Let me debug further.

@Envek
Copy link
Member

Envek commented Aug 7, 2023

Try to manually require railties for both yabeda and yabeda-rails in your app initializer:

# config/initializers/yabeda.rb
require "yabeda/railtie"
require "yabeda/rails/railtie"

Usually they are required automatically when rails is required first (as it usually first in Gemfile), but when you start puma directly with puma -C config/puma.rb yabeda is going to be required before rails and thus can't register itself into Rails configuration pipeline.

I don't know how to properly handle it at the moment.

See the same comment I referenced above for details.

@rparjun
Copy link
Author

rparjun commented Aug 7, 2023

@Envek should we update the readme with this information? We can add a note to avoid the confusion.

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

2 participants