diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2019-05-29 18:53:44 +0000 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2019-05-29 18:53:44 +0000 |
commit | 6d6bae66dffefeb3f34f2646b0e801b3c1002170 (patch) | |
tree | 3f9d88e2b1282418b1e011465d9c4ab6bc50cca4 /lib | |
parent | 70d1537dda66da8b319ceefde36195047b26a8fd (diff) | |
download | gitlab-ce-6d6bae66dffefeb3f34f2646b0e801b3c1002170.tar.gz |
Added rack-timeout for Puma
It assures that requests are aborted after 60 seconds, otherwise
an exception is raised. This exception is logged by Sentry, also
there is a Prometheus counter for measuring number of requests in each
state.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/rack_timeout_observer.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/gitlab/rack_timeout_observer.rb b/lib/gitlab/rack_timeout_observer.rb new file mode 100644 index 00000000000..80d3f7dea60 --- /dev/null +++ b/lib/gitlab/rack_timeout_observer.rb @@ -0,0 +1,46 @@ +# 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 |