diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2019-06-12 13:33:34 +0300 |
---|---|---|
committer | Dimitrie Hoekstra <dimitriehoekstra@gmail.com> | 2019-06-13 20:46:15 +0300 |
commit | 9cb9b36d48661fb34cb9d2e78990046ac7cc96cb (patch) | |
tree | d46347f8cde08e95ac3727c0728ed6de37764727 | |
parent | 159ea6de3c6e99fa1993ec4b56dbf2f2b05e6d77 (diff) |
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.
-rw-r--r-- | lib/gitlab/cluster/rack_timeout_observer.rb | 5 | ||||
-rw-r--r-- | spec/lib/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 |