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
This commit is contained in:
parent
571c4f5a4f
commit
e9363229b7
2 changed files with 5 additions and 21 deletions
|
@ -6,19 +6,15 @@ module Gitlab
|
|||
end
|
||||
|
||||
def self.rack_request_count
|
||||
@rack_request_count ||= Gitlab::Metrics.counter(:rack_request, 'Rack request count')
|
||||
end
|
||||
|
||||
def self.rack_response_count
|
||||
@rack_response_count ||= Gitlab::Metrics.counter(:rack_response, 'Rack response count')
|
||||
@rack_request_count ||= Gitlab::Metrics.counter(:http_requests_total, 'Rack request count')
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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])
|
||||
end
|
||||
|
||||
|
@ -30,14 +26,13 @@ module Gitlab
|
|||
|
||||
status, headers, body = @app.call(env)
|
||||
|
||||
ConnectionRackMiddleware.rack_response_count.increment(method: method, status: status)
|
||||
[status, headers, body]
|
||||
rescue
|
||||
ConnectionRackMiddleware.rack_uncaught_errors_count.increment
|
||||
raise
|
||||
ensure
|
||||
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
|
||||
|
|
|
@ -22,12 +22,6 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do
|
|||
allow(app).to receive(:call).and_return([200, nil, nil])
|
||||
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
|
||||
expect(described_class).to receive_message_chain(:rack_request_count, :increment).with(method: 'get')
|
||||
|
||||
|
@ -40,7 +34,7 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do
|
|||
Timecop.freeze(execution_time.seconds)
|
||||
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)
|
||||
end
|
||||
|
@ -49,11 +43,6 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do
|
|||
context '@app.call throws exception' do
|
||||
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
|
||||
expect(described_class).to receive_message_chain(:rack_uncaught_errors_count, :increment)
|
||||
|
||||
|
|
Loading…
Reference in a new issue