Commit b18cdc7a authored by Robert Speicher's avatar Robert Speicher

Merge branch 'bvl-add-status-to-http-requests-total-metric' into 'master'

This adds a status label to http_requests_total

See merge request gitlab-org/gitlab!44468
parents 5bed6658 072ba99e
......@@ -49,14 +49,9 @@ module Gitlab
method = 'INVALID' unless HTTP_METHODS.key?(method)
started = Time.now.to_f
health_endpoint = health_endpoint?(env['PATH_INFO'])
status = 'undefined'
begin
if health_endpoint
RequestsRackMiddleware.http_health_requests_total.increment(method: method)
else
RequestsRackMiddleware.http_request_total.increment(method: method)
end
status, headers, body = @app.call(env)
elapsed = Time.now.to_f - started
......@@ -69,6 +64,12 @@ module Gitlab
rescue
RequestsRackMiddleware.rack_uncaught_errors_count.increment
raise
ensure
if health_endpoint
RequestsRackMiddleware.http_health_requests_total.increment(method: method, status: status)
else
RequestsRackMiddleware.http_request_total.increment(method: method, status: status)
end
end
end
......
......@@ -22,7 +22,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
end
it 'increments requests count' do
expect(described_class).to receive_message_chain(:http_request_total, :increment).with(method: 'get')
expect(described_class).to receive_message_chain(:http_request_total, :increment).with(method: 'get', status: 200)
subject.call(env)
end
......@@ -45,7 +45,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
end
it 'increments health endpoint counter rather than overall counter' do
expect(described_class).to receive_message_chain(:http_health_requests_total, :increment).with(method: 'get')
expect(described_class).to receive_message_chain(:http_health_requests_total, :increment).with(method: 'get', status: 200)
expect(described_class).not_to receive(:http_request_total)
subject.call(env)
......@@ -68,7 +68,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
end
it 'increments overall counter rather than health endpoint counter' do
expect(described_class).to receive_message_chain(:http_request_total, :increment).with(method: 'get')
expect(described_class).to receive_message_chain(:http_request_total, :increment).with(method: 'get', status: 200)
expect(described_class).not_to receive(:http_health_requests_total)
subject.call(env)
......@@ -101,7 +101,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
end
it 'increments requests count' do
expect(described_class).to receive_message_chain(:http_request_total, :increment).with(method: 'get')
expect(described_class).to receive_message_chain(:http_request_total, :increment).with(method: 'get', status: 'undefined')
expect { subject.call(env) }.to raise_error(StandardError)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment