summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-01-22 14:45:50 +0000
committerStan Hu <stanhu@gmail.com>2019-01-22 14:45:50 +0000
commit39348adbc982d2058cf5e2bcb954b2c0eb76cd19 (patch)
tree357a4a35c8924ca278985b2baf45eea146720775 /lib
parenta5fb45adcebf84b555e180bf3ec896f73cbaa89c (diff)
parent9d2be75674c5d073bc8020a4ace1b7bff5bb16fb (diff)
downloadgitlab-ce-39348adbc982d2058cf5e2bcb954b2c0eb76cd19.tar.gz
Merge branch '56547-limit-sidekiq-logging-based-on-argument-size' into 'master'
Resolve "Limit sidekiq logging based on argument size" Closes #56547 See merge request gitlab-org/gitlab-ce!24493
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/sidekiq_logging/structured_logger.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/gitlab/sidekiq_logging/structured_logger.rb b/lib/gitlab/sidekiq_logging/structured_logger.rb
index e86db8db3a1..fdc0d518c59 100644
--- a/lib/gitlab/sidekiq_logging/structured_logger.rb
+++ b/lib/gitlab/sidekiq_logging/structured_logger.rb
@@ -5,6 +5,7 @@ module Gitlab
class StructuredLogger
START_TIMESTAMP_FIELDS = %w[created_at enqueued_at].freeze
DONE_TIMESTAMP_FIELDS = %w[started_at retried_at failed_at completed_at].freeze
+ MAXIMUM_JOB_ARGUMENTS_LENGTH = 10.kilobytes
def call(job, queue)
started_at = current_time
@@ -64,6 +65,7 @@ module Gitlab
job['pid'] = ::Process.pid
job.delete('args') unless ENV['SIDEKIQ_LOG_ARGUMENTS']
+ job['args'] = limited_job_args(job['args']) if job['args']
convert_to_iso8601(job, START_TIMESTAMP_FIELDS)
@@ -93,6 +95,21 @@ module Gitlab
Time.at(timestamp).utc.iso8601(3)
end
+
+ def limited_job_args(args)
+ return unless args.is_a?(Array)
+
+ total_length = 0
+ limited_args = args.take_while do |arg|
+ total_length += arg.to_json.length
+
+ total_length <= MAXIMUM_JOB_ARGUMENTS_LENGTH
+ end
+
+ limited_args.push('...') if total_length > MAXIMUM_JOB_ARGUMENTS_LENGTH
+
+ limited_args
+ end
end
end
end