Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/sidekiq_logging')
-rw-r--r--spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb47
-rw-r--r--spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb10
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