diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-11 00:08:28 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-11 00:08:28 +0000 |
commit | 7873bb3c1a2870761c243ea4ebe96f249ad5a319 (patch) | |
tree | 89ddef4a2e4b9cb47d41f6ff8ff68bda8777c938 /lib | |
parent | 667f6fbc8df6c23f69bc6adba15204f8559bcc3a (diff) | |
download | gitlab-ce-7873bb3c1a2870761c243ea4ebe96f249ad5a319.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/import_export/relation_tree_restorer.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/sidekiq_logging/json_formatter.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/sidekiq_logging/structured_logger.rb | 20 |
3 files changed, 19 insertions, 22 deletions
diff --git a/lib/gitlab/import_export/relation_tree_restorer.rb b/lib/gitlab/import_export/relation_tree_restorer.rb index d9c253788b4..886087bc73a 100644 --- a/lib/gitlab/import_export/relation_tree_restorer.rb +++ b/lib/gitlab/import_export/relation_tree_restorer.rb @@ -75,9 +75,6 @@ module Gitlab save_id_mapping(relation_key, data_hash, relation_object) rescue => e - # re-raise if not enabled - raise e unless Feature.enabled?(:import_graceful_failures, @importable.group, default_enabled: true) - log_import_failure(relation_key, relation_index, e) end diff --git a/lib/gitlab/sidekiq_logging/json_formatter.rb b/lib/gitlab/sidekiq_logging/json_formatter.rb index 88888c5994e..e0b0d684bea 100644 --- a/lib/gitlab/sidekiq_logging/json_formatter.rb +++ b/lib/gitlab/sidekiq_logging/json_formatter.rb @@ -3,6 +3,8 @@ module Gitlab module SidekiqLogging class JSONFormatter + TIMESTAMP_FIELDS = %w[created_at enqueued_at started_at retried_at failed_at completed_at].freeze + def call(severity, timestamp, progname, data) output = { severity: severity, @@ -13,11 +15,27 @@ module Gitlab when String output[:message] = data when Hash + convert_to_iso8601!(data) output.merge!(data) end output.to_json + "\n" end + + private + + def convert_to_iso8601!(payload) + TIMESTAMP_FIELDS.each do |key| + value = payload[key] + payload[key] = format_time(value) if value.present? + end + end + + def format_time(timestamp) + return timestamp unless timestamp.is_a?(Numeric) + + Time.at(timestamp).utc.iso8601(3) + end end end end diff --git a/lib/gitlab/sidekiq_logging/structured_logger.rb b/lib/gitlab/sidekiq_logging/structured_logger.rb index 2baa16abe27..8e7626b8eb6 100644 --- a/lib/gitlab/sidekiq_logging/structured_logger.rb +++ b/lib/gitlab/sidekiq_logging/structured_logger.rb @@ -6,8 +6,6 @@ require 'active_record/log_subscriber' module Gitlab module SidekiqLogging 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) @@ -65,8 +63,6 @@ module Gitlab payload['job_status'] = 'done' end - convert_to_iso8601(payload, DONE_TIMESTAMP_FIELDS) - payload['db_duration'] = ActiveRecord::LogSubscriber.runtime payload['db_duration_s'] = payload['db_duration'] / 1000 @@ -79,7 +75,7 @@ module Gitlab # ignore `cpu_s` if the platform does not support Process::CLOCK_THREAD_CPUTIME_ID (time[:cputime] == 0) # supported OS version can be found at: https://www.rubydoc.info/stdlib/core/2.1.6/Process:clock_gettime payload['cpu_s'] = time[:cputime].round(6) if time[:cputime] > 0 - payload['completed_at'] = Time.now.utc + payload['completed_at'] = Time.now.utc.to_f end def parse_job(job) @@ -91,17 +87,9 @@ module Gitlab 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) - job end - def convert_to_iso8601(payload, keys) - keys.each do |key| - payload[key] = format_time(payload[key]) if payload[key] - end - end - def elapsed(t0) t1 = get_time { @@ -121,12 +109,6 @@ module Gitlab Gitlab::Metrics::System.monotonic_time end - def format_time(timestamp) - return timestamp if timestamp.is_a?(String) - - Time.at(timestamp).utc.iso8601(3) - end - def limited_job_args(args) return unless args.is_a?(Array) |