Don't start Prometheus Exporter unless PROMETHEUS_EXPORTER_ENABLED is set to true

This commit is contained in:
Eugene Burmakin 2024-11-20 21:07:43 +01:00
parent 3994b3b2d4
commit 6b4da57f3d
3 changed files with 18 additions and 13 deletions

View file

@ -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'

View file

@ -5,6 +5,7 @@ Sidekiq.configure_server do |config|
require 'prometheus_exporter/instrumentation'
if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true'
config.server_middleware do |chain|
chain.add PrometheusExporter::Instrumentation::Sidekiq
end
@ -17,6 +18,7 @@ Sidekiq.configure_server do |config|
PrometheusExporter::Instrumentation::SidekiqQueue.start
PrometheusExporter::Instrumentation::SidekiqStats.start
end
end
end
Sidekiq.configure_client do |config|

View file

@ -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
@ -49,4 +47,9 @@ plugin :tmp_restart
# 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