Commit e9363229 authored by Ben Kochie's avatar Ben Kochie

Update rack metric names

* Follow Prometheus naming conventions[0].
* Simplify metrics by adding response lables to the histogram.
* Use standard `http_request_duration_seconds_...` names for the histogram.

[0]: https://prometheus.io/docs/practices/naming/#metric-names
parent 571c4f5a
...@@ -6,19 +6,15 @@ module Gitlab ...@@ -6,19 +6,15 @@ module Gitlab
end end
def self.rack_request_count def self.rack_request_count
@rack_request_count ||= Gitlab::Metrics.counter(:rack_request, 'Rack request count') @rack_request_count ||= Gitlab::Metrics.counter(:http_requests_total, 'Rack request count')
end
def self.rack_response_count
@rack_response_count ||= Gitlab::Metrics.counter(:rack_response, 'Rack response count')
end end
def self.rack_uncaught_errors_count def self.rack_uncaught_errors_count
@rack_uncaught_errors_count ||= Gitlab::Metrics.counter(:rack_uncaught_errors, 'Rack connections handling uncaught errors count') @rack_uncaught_errors_count ||= Gitlab::Metrics.counter(:rack_uncaught_errors_total, 'Rack connections handling uncaught errors count')
end end
def self.rack_execution_time def self.rack_execution_time
@rack_execution_time ||= Gitlab::Metrics.histogram(:rack_execution_time, 'Rack connection handling execution time', @rack_execution_time ||= Gitlab::Metrics.histogram(:http_request_duration_seconds, 'Rack connection handling execution time',
{}, [0.05, 0.1, 0.25, 0.5, 0.7, 1, 1.5, 2, 2.5, 3, 5, 7, 10]) {}, [0.05, 0.1, 0.25, 0.5, 0.7, 1, 1.5, 2, 2.5, 3, 5, 7, 10])
end end
...@@ -30,14 +26,13 @@ module Gitlab ...@@ -30,14 +26,13 @@ module Gitlab
status, headers, body = @app.call(env) status, headers, body = @app.call(env)
ConnectionRackMiddleware.rack_response_count.increment(method: method, status: status)
[status, headers, body] [status, headers, body]
rescue rescue
ConnectionRackMiddleware.rack_uncaught_errors_count.increment ConnectionRackMiddleware.rack_uncaught_errors_count.increment
raise raise
ensure ensure
elapsed = Time.now.to_f - started elapsed = Time.now.to_f - started
ConnectionRackMiddleware.rack_execution_time.observe({}, elapsed) ConnectionRackMiddleware.rack_execution_time.observe({method: method, status: status}, elapsed)
end end
end end
end end
......
...@@ -22,12 +22,6 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do ...@@ -22,12 +22,6 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do
allow(app).to receive(:call).and_return([200, nil, nil]) allow(app).to receive(:call).and_return([200, nil, nil])
end end
it 'increments response count with status label' do
expect(described_class).to receive_message_chain(:rack_response_count, :increment).with(include(status: 200, method: 'get'))
subject.call(env)
end
it 'increments requests count' do it 'increments requests count' do
expect(described_class).to receive_message_chain(:rack_request_count, :increment).with(method: 'get') expect(described_class).to receive_message_chain(:rack_request_count, :increment).with(method: 'get')
...@@ -40,7 +34,7 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do ...@@ -40,7 +34,7 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do
Timecop.freeze(execution_time.seconds) Timecop.freeze(execution_time.seconds)
end end
expect(described_class).to receive_message_chain(:rack_execution_time, :observe).with({}, execution_time) expect(described_class).to receive_message_chain(:rack_execution_time, :observe).with({status: 200, method: 'get'}, execution_time)
subject.call(env) subject.call(env)
end end
...@@ -49,11 +43,6 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do ...@@ -49,11 +43,6 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do
context '@app.call throws exception' do context '@app.call throws exception' do
let(:rack_response_count) { double('rack_response_count') } let(:rack_response_count) { double('rack_response_count') }
before do
allow(app).to receive(:call).and_raise(StandardError)
allow(described_class).to receive(:rack_response_count).and_return(rack_response_count)
end
it 'increments exceptions count' do it 'increments exceptions count' do
expect(described_class).to receive_message_chain(:rack_uncaught_errors_count, :increment) expect(described_class).to receive_message_chain(:rack_uncaught_errors_count, :increment)
......
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