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

Enhance Compatibility with Rack 3 and Maintain Support for Rack 2 #27

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading