diff options
author | Stan Hu <stanhu@gmail.com> | 2018-05-26 07:00:26 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-05-28 23:56:42 +0300 |
commit | 16e04e006cf8996883ef0c5b7881eb3cbb7079ce (patch) | |
tree | 6ffe689260eec3a2abf08214d1f66e884f82083f /spec/lib/gitlab/grape_logging | |
parent | 6e354cb642f911dc71be3d5368f066900fc25970 (diff) |
Log queue duration for Grape 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 'spec/lib/gitlab/grape_logging')
-rw-r--r-- | spec/lib/gitlab/grape_logging/loggers/queue_duration_logger_spec.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/lib/gitlab/grape_logging/loggers/queue_duration_logger_spec.rb b/spec/lib/gitlab/grape_logging/loggers/queue_duration_logger_spec.rb new file mode 100644 index 00000000000..f47b9dd3498 --- /dev/null +++ b/spec/lib/gitlab/grape_logging/loggers/queue_duration_logger_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe Gitlab::GrapeLogging::Loggers::QueueDurationLogger do + subject { described_class.new } + + describe ".parameters" do + let(:start_time) { Time.new(2018, 01, 01) } + + describe 'when no proxy time is available' do + let(:mock_request) { OpenStruct.new(env: {}) } + + it 'returns an empty hash' do + expect(subject.parameters(mock_request, nil)).to eq({}) + end + end + + describe 'when a proxy time is available' do + let(:mock_request) do + OpenStruct.new( + env: { + 'HTTP_GITLAB_WORKHORSE_PROXY_START' => (start_time - 1.hour).to_i * (10**9) + } + ) + end + + it 'returns the correct duration in ms' do + Timecop.freeze(start_time) do + subject.before + + expect(subject.parameters(mock_request, nil)).to eq( { 'queue_duration': 1.hour.to_f * 1000 }) + end + end + end + end +end |