From 0236e81f74f15b10ced1f6c9b9d2bed42954c538 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 4 Dec 2024 15:00:28 +0100 Subject: [PATCH] Fix Prometheus exporter for Sidekiq --- CHANGELOG.md | 8 +++++++- config/initializers/prometheus.rb | 2 +- config/initializers/sidekiq.rb | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6e923d2..b4cb6251 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -# 0.19.0 - 2024-12-03 +# 0.19.1 - 2024-12-04 + +### Fixed + +- Sidekiq is now being correctly exported to Prometheus with `PROMETHEUS_EXPORTER_ENABLED=true` env var in `dawarich_sidekiq` service. + +# 0.19.0 - 2024-12-04 ## The Photoprism integration release diff --git a/config/initializers/prometheus.rb b/config/initializers/prometheus.rb index 0a3e1b37..3573fb84 100644 --- a/config/initializers/prometheus.rb +++ b/config/initializers/prometheus.rb @@ -7,7 +7,7 @@ if !Rails.env.test? && ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true' # This reports stats per request like HTTP status and timings Rails.application.middleware.unshift PrometheusExporter::Middleware - # this reports basic process stats like RSS and GC info + # This reports basic process stats like RSS and GC info PrometheusExporter::Instrumentation::Process.start(type: 'web') # Add ActiveRecord instrumentation diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 4ae6cc8d..9e54f2ab 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -6,14 +6,16 @@ Sidekiq.configure_server do |config| if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true' require 'prometheus_exporter/instrumentation' + # Add middleware for collecting job-level metrics config.server_middleware do |chain| chain.add PrometheusExporter::Instrumentation::Sidekiq end + # Capture metrics for failed jobs config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler + # Start Prometheus instrumentation config.on :startup do - PrometheusExporter::Instrumentation::Process.start type: 'sidekiq' PrometheusExporter::Instrumentation::SidekiqProcess.start PrometheusExporter::Instrumentation::SidekiqQueue.start PrometheusExporter::Instrumentation::SidekiqStats.start @@ -25,6 +27,4 @@ Sidekiq.configure_client do |config| config.redis = { url: ENV['REDIS_URL'] } end -if (defined?(Rails::Server) || Sidekiq.server?) && PHOTON_API_HOST == 'photon.komoot.io' - Sidekiq::Queue['reverse_geocoding'].limit = 1 -end +Sidekiq::Queue['reverse_geocoding'].limit = 1 if Sidekiq.server? && PHOTON_API_HOST == 'photon.komoot.io'