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,32 @@
# frozen_string_literal: true
require 'rails_helper'
require 'prometheus_exporter'
require 'prometheus_exporter/middleware'
require 'mastodon/middleware/prometheus_queue_time'
RSpec.describe Mastodon::Middleware::PrometheusQueueTime do
subject { described_class.new(app, client:) }
let(:app) do
proc { |_env| [200, {}, 'OK'] }
end
let(:client) do
instance_double(PrometheusExporter::Client, send_json: true)
end
describe '#call' do
let(:env) do
{
'HTTP_X_REQUEST_START' => "t=#{(Time.now.to_f * 1000).to_i}",
}
end
it 'reports a queue time to the client' do
subject.call(env)
expect(client).to have_received(:send_json)
.with(hash_including(queue_time: instance_of(Float)))
end
end
end