diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/gitlab/sidekiq_logging | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab/sidekiq_logging')
-rw-r--r-- | spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb | 47 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb | 10 |
2 files changed, 45 insertions, 12 deletions
diff --git a/spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb b/spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb index 283140d7fdf..10354147cf9 100644 --- a/spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb +++ b/spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb @@ -14,6 +14,7 @@ describe Gitlab::SidekiqLogging::JSONFormatter do let(:hash_input) do { foo: 1, + 'class' => 'PostReceive', 'bar' => 'test', 'created_at' => timestamp, 'enqueued_at' => timestamp, @@ -42,21 +43,47 @@ describe Gitlab::SidekiqLogging::JSONFormatter do expect(subject).to eq(expected_output) end - context 'when the job args are bigger than the maximum allowed' do - it 'keeps args from the front until they exceed the limit' do - half_limit = Gitlab::Utils::LogLimitedArray::MAXIMUM_ARRAY_LENGTH / 2 - hash_input['args'] = [1, 2, 'a' * half_limit, 'b' * half_limit, 3] + it 'removes jobstr from the hash' do + hash_input[:jobstr] = 'job string' - expected_args = hash_input['args'].take(3).map(&:to_s) + ['...'] + expect(subject).not_to include('jobstr') + end - expect(subject['args']).to eq(expected_args) - end + it 'does not modify the input hash' do + input = { 'args' => [1, 'string'] } + + output = Gitlab::Json.parse(described_class.new.call('INFO', now, 'my program', input)) + + expect(input['args']).to eq([1, 'string']) + expect(output['args']).to eq(['1', '[FILTERED]']) end - it 'properly flattens arguments to a String' do - hash_input['args'] = [1, "test", 2, { 'test' => 1 }] + context 'job arguments' do + context 'when the arguments are bigger than the maximum allowed' do + it 'keeps args from the front until they exceed the limit' do + half_limit = Gitlab::Utils::LogLimitedArray::MAXIMUM_ARRAY_LENGTH / 2 + hash_input['args'] = [1, 2, 'a' * half_limit, 'b' * half_limit, 3] + + expected_args = hash_input['args'].take(3).map(&:to_s) + ['...'] + + expect(subject['args']).to eq(expected_args) + end + end + + context 'when the job has non-integer arguments' do + it 'only allows permitted non-integer arguments through' do + hash_input['args'] = [1, 'foo', 'bar'] + hash_input['class'] = 'WebHookWorker' - expect(subject['args']).to eq(["1", "test", "2", %({"test"=>1})]) + expect(subject['args']).to eq(['1', '[FILTERED]', 'bar']) + end + end + + it 'properly flattens arguments to a String' do + hash_input['args'] = [1, "test", 2, { 'test' => 1 }] + + expect(subject['args']).to eq(["1", "test", "2", %({"test"=>1})]) + end end context 'when the job has a non-integer value for retry' do diff --git a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb index a4bbb51baae..a456f814e78 100644 --- a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb +++ b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb @@ -21,7 +21,10 @@ describe Gitlab::SidekiqLogging::StructuredLogger do "correlation_id" => 'cid', "error_message" => "wrong number of arguments (2 for 3)", "error_class" => "ArgumentError", - "error_backtrace" => [] + "error_backtrace" => [], + "db_count" => 1, + "db_write_count" => 0, + "db_cached_count" => 0 } end @@ -197,7 +200,10 @@ describe Gitlab::SidekiqLogging::StructuredLogger do let(:expected_end_payload_with_db) do expected_end_payload.merge( - 'db_duration_s' => a_value >= 0.1 + 'db_duration_s' => a_value >= 0.1, + 'db_count' => 1, + 'db_cached_count' => 0, + 'db_write_count' => 0 ) end |