From 0a6bb9ab0f98166c988ebea1042e37dc82f59ecf Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 20 Nov 2024 20:42:28 +0100 Subject: [PATCH 1/4] Expose Prometheus exporter to the outside world --- .app_version | 2 +- CHANGELOG.md | 27 +++++++++++++++++++++++++++ Procfile.prometheus.dev | 2 +- docker-compose.yml | 5 +++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.app_version b/.app_version index c3f65805..427cda05 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.16.6 +0.16.7 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aa52b7a..f0b86b1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,33 @@ 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.16.7 - 2024-11-20 + +### Changed + +- Prometheus exporter is now bound to 0.0.0.0 instead of localhost +- `PROMETHEUS_EXPORTER_HOST` and `PROMETHEUS_EXPORTER_PORT` env vars were added to the `docker-compose.yml` file to allow you to set the host and port for the Prometheus exporter. They should be added to both `dawarich_app` and `dawarich_sidekiq` services Example: + +```diff + dawarich_app: + image: freikin/dawarich:latest + container_name: dawarich_app + environment: + ... + PROMETHEUS_EXPORTER_ENABLED: "true" ++ PROMETHEUS_EXPORTER_HOST: 0.0.0.0 ++ PROMETHEUS_EXPORTER_PORT: "9394" + + dawarich_sidekiq: + image: freikin/dawarich:latest + container_name: dawarich_sidekiq + environment: + ... + PROMETHEUS_EXPORTER_ENABLED: "true" ++ PROMETHEUS_EXPORTER_HOST: dawarich_app ++ PROMETHEUS_EXPORTER_PORT: "9394" +``` + # 0.16.6 - 2024-11-20 ### Added diff --git a/Procfile.prometheus.dev b/Procfile.prometheus.dev index 2f1921fb..965e5e25 100644 --- a/Procfile.prometheus.dev +++ b/Procfile.prometheus.dev @@ -1,2 +1,2 @@ +prometheus_exporter: bundle exec prometheus_exporter -b 0.0.0.0 web: bin/rails server -p 3000 -b 0.0.0.0 -prometheus_exporter: bundle exec prometheus_exporter diff --git a/docker-compose.yml b/docker-compose.yml index bd3d2049..947b6e89 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -66,6 +66,8 @@ services: PHOTON_API_HOST: photon.komoot.io PHOTON_API_USE_HTTPS: true PROMETHEUS_EXPORTER_ENABLED: false + PROMETHEUS_EXPORTER_HOST: "0.0.0.0" + PROMETHEUS_EXPORTER_PORT: 9394 logging: driver: "json-file" options: @@ -117,6 +119,9 @@ services: DISTANCE_UNIT: km PHOTON_API_HOST: photon.komoot.io PHOTON_API_USE_HTTPS: true + PROMETHEUS_EXPORTER_ENABLED: false + PROMETHEUS_EXPORTER_HOST: dawarich_app + PROMETHEUS_EXPORTER_PORT: 9394 logging: driver: "json-file" options: From d0e0158ef9ddd6f93f7be1a50102ab803077d70f Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 20 Nov 2024 20:47:30 +0100 Subject: [PATCH 2/4] Update puma.rb to include prometheus exporter for single mode --- config/puma.rb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/config/puma.rb b/config/puma.rb index 683d0ba0..7b49289f 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,28 +1,32 @@ +# 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 # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `worker_timeout` threshold that Puma will use to wait before # terminating a worker in development environments. # -worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" +worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development' # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } +pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together @@ -42,8 +46,7 @@ pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } # Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart -# Promethues exporter -after_worker_boot do - require 'prometheus_exporter/instrumentation' - PrometheusExporter::Instrumentation::Process.start(type:"web") -end +# Prometheus exporter +# +# optional check, avoids spinning up and down threads per worker +PrometheusExporter::Instrumentation::Puma.start unless PrometheusExporter::Instrumentation::Puma.started? From 55a575f87a7b15271b5cc734cccc9e1e85567410 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 20 Nov 2024 20:50:21 +0100 Subject: [PATCH 3/4] Update sidekiq configuration to include Prometheus instrumentation --- config/initializers/sidekiq.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index d3c9bbea..fdbca0dd 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -3,10 +3,22 @@ Sidekiq.configure_server do |config| config.redis = { url: ENV['REDIS_URL'] } - config.server_middleware do |chain| + if ENV.fetch('PROMETHEUS_EXPORTER_ENABLED', false) require 'prometheus_exporter/instrumentation' - chain.add PrometheusExporter::Instrumentation::Sidekiq - end + + config.server_middleware do |chain| + chain.add PrometheusExporter::Instrumentation::Sidekiq + end + + 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 + end + end end Sidekiq.configure_client do |config| From 342f025bf20eb52edebf6079af83e495fccd294b Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 20 Nov 2024 21:05:02 +0100 Subject: [PATCH 4/4] Add port 9394 to docker-compose.yml for Prometheus exporter --- config/initializers/sidekiq.rb | 22 ++++++++++------------ docker-compose.yml | 5 +++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index fdbca0dd..d7e28c3b 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -3,21 +3,19 @@ Sidekiq.configure_server do |config| config.redis = { url: ENV['REDIS_URL'] } - if ENV.fetch('PROMETHEUS_EXPORTER_ENABLED', false) - require 'prometheus_exporter/instrumentation' + require 'prometheus_exporter/instrumentation' - config.server_middleware do |chain| - chain.add PrometheusExporter::Instrumentation::Sidekiq - end + 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 - end + config.on :startup do + PrometheusExporter::Instrumentation::Process.start type: 'sidekiq' + PrometheusExporter::Instrumentation::SidekiqProcess.start + PrometheusExporter::Instrumentation::SidekiqQueue.start + PrometheusExporter::Instrumentation::SidekiqStats.start end end diff --git a/docker-compose.yml b/docker-compose.yml index 947b6e89..d5df6b27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -45,6 +45,7 @@ services: - dawarich ports: - 3000:3000 + # - 9394:9394 # Prometheus exporter, uncomment if needed stdin_open: true tty: true entrypoint: dev-entrypoint.sh @@ -65,8 +66,8 @@ services: DISTANCE_UNIT: km PHOTON_API_HOST: photon.komoot.io PHOTON_API_USE_HTTPS: true - PROMETHEUS_EXPORTER_ENABLED: false - PROMETHEUS_EXPORTER_HOST: "0.0.0.0" + PROMETHEUS_EXPORTER_ENABLED: true + PROMETHEUS_EXPORTER_HOST: 0.0.0.0 PROMETHEUS_EXPORTER_PORT: 9394 logging: driver: "json-file"