Commit 2e16d0ff authored by Ben Kochie's avatar Ben Kochie

Use strings for request status label

Prometheus metric labels are always strings. This will avoid passing
invalid ints to the metric library in case it rejects non-string label
value input.

Related to https://gitlab.com/gitlab-org/gitlab/issues/34887
parent 36f4701f
...@@ -35,7 +35,7 @@ module Gitlab ...@@ -35,7 +35,7 @@ module Gitlab
def self.initialize_http_request_duration_seconds def self.initialize_http_request_duration_seconds
HTTP_METHODS.each do |method, statuses| HTTP_METHODS.each do |method, statuses|
statuses.each do |status| statuses.each do |status|
http_request_duration_seconds.get({ method: method, status: status.to_i }) http_request_duration_seconds.get({ method: method, status: status.to_s })
end end
end end
end end
...@@ -49,7 +49,7 @@ module Gitlab ...@@ -49,7 +49,7 @@ module Gitlab
status, headers, body = @app.call(env) status, headers, body = @app.call(env)
elapsed = Time.now.to_f - started elapsed = Time.now.to_f - started
RequestsRackMiddleware.http_request_duration_seconds.observe({ method: method, status: status }, elapsed) RequestsRackMiddleware.http_request_duration_seconds.observe({ method: method, status: status.to_s }, elapsed)
[status, headers, body] [status, headers, body]
rescue rescue
......
...@@ -31,7 +31,7 @@ describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -31,7 +31,7 @@ describe Gitlab::Metrics::RequestsRackMiddleware do
end end
it 'measures execution time' do it 'measures execution time' do
expect(described_class).to receive_message_chain(:http_request_duration_seconds, :observe).with({ status: 200, method: 'get' }, a_positive_execution_time) expect(described_class).to receive_message_chain(:http_request_duration_seconds, :observe).with({ status: '200', method: 'get' }, a_positive_execution_time)
Timecop.scale(3600) { subject.call(env) } Timecop.scale(3600) { subject.call(env) }
end end
...@@ -69,7 +69,7 @@ describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -69,7 +69,7 @@ describe Gitlab::Metrics::RequestsRackMiddleware do
expected_labels = [] expected_labels = []
described_class::HTTP_METHODS.each do |method, statuses| described_class::HTTP_METHODS.each do |method, statuses|
statuses.each do |status| statuses.each do |status|
expected_labels << { method: method, status: status.to_i } expected_labels << { method: method, status: status.to_s }
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