yabeda-prometheus icon indicating copy to clipboard operation
yabeda-prometheus copied to clipboard

undefined method `registry' error.

Open rparjun opened this issue 1 year ago • 6 comments

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 avatar Aug 06 '23 14:08 rparjun

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

Envek avatar Aug 07 '23 04:08 Envek

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

rparjun avatar Aug 07 '23 04:08 rparjun

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

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

See also https://github.com/yabeda-rb/yabeda-puma-plugin/issues/21#issuecomment-1568977215 for some more context for a similar problem.

Envek avatar Aug 07 '23 05:08 Envek

Thanks @Envek , requiring yabeda/prometheus works!

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

rparjun avatar Aug 07 '23 05:08 rparjun

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.

Envek avatar Aug 07 '23 05:08 Envek

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

rparjun avatar Aug 07 '23 05:08 rparjun