Commit dd8862f9 authored by Stan Hu's avatar Stan Hu

Merge branch 'make-retry-an-integer-in-sidekiq-logs' into 'master'

Make retry an integer in Sidekiq logs

See merge request gitlab-org/gitlab!31347
parents aa41d80d ef67613d
......@@ -19,6 +19,7 @@ module Gitlab
output[:message] = data
when Hash
convert_to_iso8601!(data)
convert_retry_to_integer!(data)
stringify_args!(data)
output.merge!(data)
end
......@@ -41,6 +42,20 @@ module Gitlab
Time.at(timestamp).utc.iso8601(3)
end
def convert_retry_to_integer!(payload)
payload['retry'] =
case payload['retry']
when Integer
payload['retry']
when false, nil
0
when true
Sidekiq::JobRetry::DEFAULT_MAX_RETRY_ATTEMPTS
else
-1
end
end
def stringify_args!(payload)
payload['args'] = Gitlab::Utils::LogLimitedArray.log_limited_array(payload['args'].map(&:to_s)) if payload['args']
end
......
......@@ -34,7 +34,8 @@ describe Gitlab::SidekiqLogging::JSONFormatter do
'started_at' => timestamp_iso8601,
'retried_at' => timestamp_iso8601,
'failed_at' => timestamp_iso8601,
'completed_at' => timestamp_iso8601
'completed_at' => timestamp_iso8601,
'retry' => 0
}
)
......@@ -57,6 +58,26 @@ describe Gitlab::SidekiqLogging::JSONFormatter do
expect(subject['args']).to eq(["1", "test", "2", %({"test"=>1})])
end
context 'when the job has a non-integer value for retry' do
using RSpec::Parameterized::TableSyntax
where(:retry_in_job, :retry_in_logs) do
3 | 3
true | 25
false | 0
nil | 0
'string' | -1
end
with_them do
it 'logs as the correct integer' do
hash_input['retry'] = retry_in_job
expect(subject['retry']).to eq(retry_in_logs)
end
end
end
end
describe 'with a String' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment