Skip to content

Commit

Permalink
Allow prometheus binding to fail with a warning rather than a crash
Browse files Browse the repository at this point in the history
- This allows us to (eg) run rake tasks or db migrations
  in situations where the port is already bound (for instance
  in a pod shell)
  • Loading branch information
KludgeKML committed May 10, 2023
1 parent 9e782eb commit dcff81c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/govuk_app_config/govuk_prometheus_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@ def self.configure
end
end

server = PrometheusExporter::Server::WebServer.new bind: "0.0.0.0", port: 9394
server.start
begin
server = PrometheusExporter::Server::WebServer.new bind: "0.0.0.0", port: 9394
server.start

if defined?(Rails)
Rails.application.middleware.unshift PrometheusExporter::Middleware
end
if defined?(Rails)
Rails.application.middleware.unshift PrometheusExporter::Middleware
end

if defined?(Sinatra)
Sinatra.use PrometheusExporter::Middleware
if defined?(Sinatra)
Sinatra.use PrometheusExporter::Middleware
end
rescue Errno::EADDRINUSE => e
warn "Warning: Could not connect to Prometheus Server"
end
end
end

0 comments on commit dcff81c

Please sign in to comment.