summaryrefslogtreecommitdiff
path: root/lib/gitlab/grape_logging/loggers/queue_duration_logger.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-05-25 21:00:26 -0700
committerStan Hu <stanhu@gmail.com>2018-05-28 13:56:42 -0700
commit16e04e006cf8996883ef0c5b7881eb3cbb7079ce (patch)
tree6ffe689260eec3a2abf08214d1f66e884f82083f /lib/gitlab/grape_logging/loggers/queue_duration_logger.rb
parent6e354cb642f911dc71be3d5368f066900fc25970 (diff)
downloadgitlab-ce-16e04e006cf8996883ef0c5b7881eb3cbb7079ce.tar.gz
Log queue duration for Grape API callssh-tag-queue-duration-api-calls
This mimics the same thing the RailsQueueDuration does for Rails controller requests and will help diagnose issues with API delays. Closes #46601
Diffstat (limited to 'lib/gitlab/grape_logging/loggers/queue_duration_logger.rb')
-rw-r--r--lib/gitlab/grape_logging/loggers/queue_duration_logger.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/gitlab/grape_logging/loggers/queue_duration_logger.rb b/lib/gitlab/grape_logging/loggers/queue_duration_logger.rb
new file mode 100644
index 00000000000..0adac79f25a
--- /dev/null
+++ b/lib/gitlab/grape_logging/loggers/queue_duration_logger.rb
@@ -0,0 +1,26 @@
+# This grape_logging module (https://github.com/aserafin/grape_logging) makes it
+# possible to log how much time an API request was queued by Workhorse.
+module Gitlab
+ module GrapeLogging
+ module Loggers
+ class QueueDurationLogger < ::GrapeLogging::Loggers::Base
+ attr_accessor :start_time
+
+ def before
+ @start_time = Time.now
+ end
+
+ def parameters(request, _)
+ proxy_start = request.env['HTTP_GITLAB_WORKHORSE_PROXY_START'].presence
+
+ return {} unless proxy_start && start_time
+
+ # Time in milliseconds since gitlab-workhorse started the request
+ duration = (start_time.to_f * 1_000 - proxy_start.to_f / 1_000_000).round(2)
+
+ { 'queue_duration': duration }
+ end
+ end
+ end
+ end
+end