Commit 13364c00 authored by Jan Provaznik's avatar Jan Provaznik

Monitor only final states

There is no reason to monitor transition states so we ignore
ready and active states. We can get ratio of completed vs failed
requests from final states.
parent d3a7bdda
......@@ -3,8 +3,10 @@
module Gitlab
module Cluster
class RackTimeoutObserver
TRANSITION_STATES = %i(ready active).freeze
def initialize
@counter = Gitlab::Metrics.counter(:rack_state_total, 'Number of requests in a given rack state')
@counter = Gitlab::Metrics.counter(:rack_requests_total, 'Number of requests in a given rack state')
end
# returns the Proc to be used as the observer callback block
......@@ -17,6 +19,7 @@ module Gitlab
def log_timeout_exception(env)
info = env[::Rack::Timeout::ENV_INFO_KEY]
return unless info
return if TRANSITION_STATES.include?(info.state)
@counter.increment(labels(info, env))
end
......
......@@ -25,7 +25,7 @@ describe Gitlab::Cluster::RackTimeoutObserver do
subject { described_class.new }
it 'increments timeout counter' do
it 'increments counter' do
expect(counter)
.to receive(:increment)
.with({ controller: 'foo', action: 'bar', route: nil, state: :timed_out })
......@@ -45,7 +45,7 @@ describe Gitlab::Cluster::RackTimeoutObserver do
subject { described_class.new }
it 'increments timeout counter' do
it 'increments counter' do
allow(endpoint).to receive_message_chain('route.pattern.origin') { 'foobar' }
expect(counter)
.to receive(:increment)
......@@ -54,5 +54,24 @@ describe Gitlab::Cluster::RackTimeoutObserver do
subject.callback.call(env)
end
end
context 'when request is being processed' do
let(:endpoint) { double }
let(:env) do
{
::Rack::Timeout::ENV_INFO_KEY => double(state: :active),
Grape::Env::API_ENDPOINT => endpoint
}
end
subject { described_class.new }
it 'does not increment counter' do
allow(endpoint).to receive_message_chain('route.pattern.origin') { 'foobar' }
expect(counter).not_to receive(:increment)
subject.callback.call(env)
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