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

@ -0,0 +1,26 @@
# frozen_string_literal: true
module Mastodon
module Middleware
class PrometheusQueueTime < ::PrometheusExporter::Middleware
# Overwrite to only collect the queue time metric
def call(env)
queue_time = measure_queue_time(env)
result = @app.call(env)
result
ensure
obj = {
type: 'web',
queue_time: queue_time,
default_labels: default_labels(env, result),
}
labels = custom_labels(env)
obj = obj.merge(custom_labels: labels) if labels
@client.send_json(obj)
end
end
end
end