Skip to content

Commit

Permalink
Don't start Prometheus Exporter unless PROMETHEUS_EXPORTER_ENABLED is…
Browse files Browse the repository at this point in the history
… set to true
  • Loading branch information
Freika committed Nov 20, 2024
1 parent 3994b3b commit 6b4da57
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/initializers/prometheus.rb
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
# in config/initializers/prometheus.rb
if Rails.env != "test"
if Rails.env != "test" && ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true'
require 'prometheus_exporter/middleware'
require 'prometheus_exporter/instrumentation'

Expand Down
20 changes: 11 additions & 9 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 5,19 @@

require 'prometheus_exporter/instrumentation'

config.server_middleware do |chain|
chain.add PrometheusExporter::Instrumentation::Sidekiq
end
if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true'
config.server_middleware do |chain|
chain.add PrometheusExporter::Instrumentation::Sidekiq
end

config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler
config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler

config.on :startup do
PrometheusExporter::Instrumentation::Process.start type: 'sidekiq'
PrometheusExporter::Instrumentation::SidekiqProcess.start
PrometheusExporter::Instrumentation::SidekiqQueue.start
PrometheusExporter::Instrumentation::SidekiqStats.start
config.on :startup do
PrometheusExporter::Instrumentation::Process.start type: 'sidekiq'
PrometheusExporter::Instrumentation::SidekiqProcess.start
PrometheusExporter::Instrumentation::SidekiqQueue.start
PrometheusExporter::Instrumentation::SidekiqStats.start
end
end
end

Expand Down
9 changes: 6 additions & 3 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -1,7 1,5 @@
# frozen_string_literal: true

require 'prometheus_exporter/instrumentation'

# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
Expand Down Expand Up @@ -49,4 47,9 @@
# Prometheus exporter
#
# optional check, avoids spinning up and down threads per worker
PrometheusExporter::Instrumentation::Puma.start unless PrometheusExporter::Instrumentation::Puma.started?

if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true'
require 'prometheus_exporter/instrumentation'

PrometheusExporter::Instrumentation::Puma.start unless PrometheusExporter::Instrumentation::Puma.started?
end

0 comments on commit 6b4da57

Please sign in to comment.