From 13364c00d57ce3150a50c23ea3eb0e6af4271d92 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Wed, 12 Jun 2019 12:33:34 +0200 Subject: 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. --- lib/gitlab/cluster/rack_timeout_observer.rb | 5 ++++- .../gitlab/cluster/rack_timeout_observer_spec.rb | 23 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/gitlab/cluster/rack_timeout_observer.rb b/lib/gitlab/cluster/rack_timeout_observer.rb index 2bc006b8011..5182b2be148 100644 --- a/lib/gitlab/cluster/rack_timeout_observer.rb +++ b/lib/gitlab/cluster/rack_timeout_observer.rb @@ -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 diff --git a/spec/lib/gitlab/cluster/rack_timeout_observer_spec.rb b/spec/lib/gitlab/cluster/rack_timeout_observer_spec.rb index 2adb1d7cc71..68e5435450c 100644 --- a/spec/lib/gitlab/cluster/rack_timeout_observer_spec.rb +++ b/spec/lib/gitlab/cluster/rack_timeout_observer_spec.rb @@ -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 -- cgit v1.2.1