Skip to content

Commit

Permalink
Enhance Compatibility with Rack 3 and Maintain Support for Rack 2 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
aroop authored Jan 4, 2024
1 parent db558c1 commit 2369085
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/yabeda/prometheus/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def call(env)
def start_metrics_server!(**rack_app_options)
Thread.new do
default_port = ENV.fetch("PORT", 9394)
::Rack::Handler::WEBrick.run(
rack_handler.run(
rack_app(**rack_app_options),
Host: ENV["PROMETHEUS_EXPORTER_BIND"] || "0.0.0.0",
Port: ENV.fetch("PROMETHEUS_EXPORTER_PORT", default_port),
Expand All @@ -40,6 +40,18 @@ def rack_app(exporter = self, logger: Logger.new(IO::NULL), use_deflater: true,
run NOT_FOUND_HANDLER
end
end

def rack_handler
if Gem.loaded_specs['rack']&.version&.>= Gem::Version.new('3.0')
require 'rackup'
::Rackup::Handler::WEBrick
else
::Rack::Handler::WEBrick
end
rescue LoadError
warn 'Please add gems rackup and webrick to your Gemfile to expose Yabeda metrics from prometheus-mmap'
::Rack::Handler::WEBrick
end
end

def initialize(app, options = {})
Expand Down

0 comments on commit 2369085

Please # to comment.