Commit ca4a2642 authored by Ryan Cobb's avatar Ryan Cobb

Add specs for http_request_duration_seconds

parent 3ac1d9ad
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Gitlab module Gitlab
module Metrics module Metrics
class RequestsRackMiddleware class RequestsRackMiddleware
METHODS = %w(delete get head options patch post put trace).freeze HTTP_METHODS = %w(delete get head options patch post put trace).freeze
STATUSES = %w(200 301 304 400 401 403 404 500).freeze STATUSES = %w(200 301 304 400 401 403 404 500).freeze
def initialize(app) def initialize(app)
...@@ -24,9 +24,9 @@ module Gitlab ...@@ -24,9 +24,9 @@ module Gitlab
end end
def self.initialize_http_request_duration_seconds def self.initialize_http_request_duration_seconds
METHODS.each do |method| HTTP_METHODS.each do |method|
STATUSES.each do |status| STATUSES.each do |status|
::Gitlab::Metrics.histogram(:http_request_duration_seconds, 'Request handling execution time').get({ method: method, status: status }) http_request_duration_seconds.get({ method: method, status: status })
end end
end end
end end
......
...@@ -63,5 +63,19 @@ describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -63,5 +63,19 @@ describe Gitlab::Metrics::RequestsRackMiddleware do
expect { subject.call(env) }.to raise_error(StandardError) expect { subject.call(env) }.to raise_error(StandardError)
end end
end end
describe '.initialize_http_request_duration_seconds' do
it "sets labels" do
expected_labels = []
described_class::HTTP_METHODS.each do |method|
described_class::STATUSES.each do |status|
expected_labels << { method: method, status: status }
end
end
described_class.initialize_http_request_duration_seconds
expect(described_class.http_request_duration_seconds.values.keys).to include(*expected_labels)
end
end
end end
end 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