summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2019-06-05 19:20:37 +0200
committerJan Provaznik <jprovaznik@gitlab.com>2019-06-12 12:09:04 +0200
commitd3a7bdda986949ca76df3c4932ee8c973437a743 (patch)
treef5bef987fa8c1a6c4f9946eda47ebb6ffba82e63
parentf18f3ed9265e777ab7ddcb87948d0e405fbbb0b0 (diff)
downloadgitlab-ce-d3a7bdda986949ca76df3c4932ee8c973437a743.tar.gz
Moved RackTimeout observer to a different location
Because there will be similar observer for PumaWorkerKiller, it makes sense to keep both on better place.
-rw-r--r--config/initializers/rack_timeout.rb2
-rw-r--r--lib/gitlab/cluster/rack_timeout_observer.rb48
-rw-r--r--lib/gitlab/rack_timeout_observer.rb46
-rw-r--r--spec/lib/gitlab/cluster/rack_timeout_observer_spec.rb (renamed from spec/lib/gitlab/rack_timeout_observer_spec.rb)2
4 files changed, 50 insertions, 48 deletions
diff --git a/config/initializers/rack_timeout.rb b/config/initializers/rack_timeout.rb
index 5c4f2dd708c..58f46b55725 100644
--- a/config/initializers/rack_timeout.rb
+++ b/config/initializers/rack_timeout.rb
@@ -18,6 +18,6 @@ if defined?(::Puma) && !Rails.env.test?
wait_timeout: 90)
end
- observer = Gitlab::RackTimeoutObserver.new
+ observer = Gitlab::Cluster::RackTimeoutObserver.new
Rack::Timeout.register_state_change_observer(:gitlab_rack_timeout, &observer.callback)
end
diff --git a/lib/gitlab/cluster/rack_timeout_observer.rb b/lib/gitlab/cluster/rack_timeout_observer.rb
new file mode 100644
index 00000000000..2bc006b8011
--- /dev/null
+++ b/lib/gitlab/cluster/rack_timeout_observer.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Cluster
+ class RackTimeoutObserver
+ def initialize
+ @counter = Gitlab::Metrics.counter(:rack_state_total, 'Number of requests in a given rack state')
+ end
+
+ # returns the Proc to be used as the observer callback block
+ def callback
+ method(:log_timeout_exception)
+ end
+
+ private
+
+ def log_timeout_exception(env)
+ info = env[::Rack::Timeout::ENV_INFO_KEY]
+ return unless info
+
+ @counter.increment(labels(info, env))
+ end
+
+ def labels(info, env)
+ params = controller_params(env) || grape_params(env) || {}
+
+ {
+ controller: params['controller'],
+ action: params['action'],
+ route: params['route'],
+ state: info.state
+ }
+ end
+
+ def controller_params(env)
+ env['action_dispatch.request.parameters']
+ end
+
+ def grape_params(env)
+ endpoint = env[Grape::Env::API_ENDPOINT]
+ route = endpoint&.route&.pattern&.origin
+ return unless route
+
+ { 'route' => route }
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/rack_timeout_observer.rb b/lib/gitlab/rack_timeout_observer.rb
deleted file mode 100644
index 80d3f7dea60..00000000000
--- a/lib/gitlab/rack_timeout_observer.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- class RackTimeoutObserver
- def initialize
- @counter = Gitlab::Metrics.counter(:rack_state_total, 'Number of requests in a given rack state')
- end
-
- # returns the Proc to be used as the observer callback block
- def callback
- method(:log_timeout_exception)
- end
-
- private
-
- def log_timeout_exception(env)
- info = env[::Rack::Timeout::ENV_INFO_KEY]
- return unless info
-
- @counter.increment(labels(info, env))
- end
-
- def labels(info, env)
- params = controller_params(env) || grape_params(env) || {}
-
- {
- controller: params['controller'],
- action: params['action'],
- route: params['route'],
- state: info.state
- }
- end
-
- def controller_params(env)
- env['action_dispatch.request.parameters']
- end
-
- def grape_params(env)
- endpoint = env[Grape::Env::API_ENDPOINT]
- route = endpoint&.route&.pattern&.origin
- return unless route
-
- { 'route' => route }
- end
- end
-end
diff --git a/spec/lib/gitlab/rack_timeout_observer_spec.rb b/spec/lib/gitlab/cluster/rack_timeout_observer_spec.rb
index 3dc1a8b68fb..2adb1d7cc71 100644
--- a/spec/lib/gitlab/rack_timeout_observer_spec.rb
+++ b/spec/lib/gitlab/cluster/rack_timeout_observer_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::RackTimeoutObserver do
+describe Gitlab::Cluster::RackTimeoutObserver do
let(:counter) { Gitlab::Metrics::NullMetric.instance }
before do