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,17 +5,19 @@ Sidekiq.configure_server do |config|
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

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