Add middleware to record queue time (#34172)

This commit is contained in:
David Roetzel 2025-03-14 14:52:04 +01:00 committed by GitHub
parent 24ec83ee52
commit 4a6cf67c46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 65 additions and 3 deletions

View file

@ -1,8 +1,10 @@
# frozen_string_literal: true
if ENV['MASTODON_PROMETHEUS_EXPORTER_ENABLED'] == 'true'
require 'prometheus_exporter'
require 'prometheus_exporter/middleware'
if ENV['MASTODON_PROMETHEUS_EXPORTER_LOCAL'] == 'true'
require 'prometheus_exporter'
require 'prometheus_exporter/server'
require 'prometheus_exporter/client'
@ -17,9 +19,11 @@ if ENV['MASTODON_PROMETHEUS_EXPORTER_ENABLED'] == 'true'
if ENV['MASTODON_PROMETHEUS_EXPORTER_WEB_DETAILED_METRICS'] == 'true'
# Optional, as those metrics might generate extra overhead and be redundant with what OTEL provides
require 'prometheus_exporter/middleware'
# Per-action/controller request stats like HTTP status and timings
Rails.application.middleware.unshift PrometheusExporter::Middleware
else
# Include stripped down version of PrometheusExporter::Middleware that only collects queue time
require 'mastodon/middleware/prometheus_queue_time'
Rails.application.middleware.unshift Mastodon::Middleware::PrometheusQueueTime
end
end