Skip to content

Commit

Permalink
Rewrite rack_handler method for brevity
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Dec 11, 2023
1 parent 31ad58b commit 3950c34
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lib/yabeda/prometheus/mmap/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def call(env)
def start_metrics_server!
Thread.new do
default_port = ENV.fetch('PORT', 9394)
rack_handler = determine_rack_handler

rack_handler.run(
rack_app,
Expand All @@ -34,20 +33,16 @@ def start_metrics_server!
end
end

def determine_rack_handler
rack_version = Gem.loaded_specs['rack'].version

if rack_version >= Gem::Version.new('3.0')
begin
Gem::Specification.find_by_name('rackup')
require 'rackup'
::Rackup::Handler::WEBrick
rescue Gem::MissingSpecError
::Rack::Handler::WEBrick
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

def rack_app(exporter = self, path: '/metrics')
Expand Down

0 comments on commit 3950c34

Please sign in to comment.