summaryrefslogtreecommitdiff
path: root/lib/gitlab/bitbucket_import/importer.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-06-19 10:44:04 -0700
committerStan Hu <stanhu@gmail.com>2019-06-19 12:04:24 -0700
commit30f52b690f3dc373f1ec98d9def9d9d2cd37832a (patch)
treedb45c48023360ad8f9c294db8395d0c5b702efb0 /lib/gitlab/bitbucket_import/importer.rb
parent0d2537bfa942f4bf198241bfbc5c4083929f3e46 (diff)
downloadgitlab-ce-30f52b690f3dc373f1ec98d9def9d9d2cd37832a.tar.gz
Avoid storing backtraces from Bitbucket Cloud imports in the databasesh-clean-up-bitbucket-import-errors
We noticed in https://gitlab.com/gitlab-com/gl-infra/production/issues/908 some Bitbucket imports took over a second to load their projects row because `import_error` was huge due to errors. To prevent this, we now: 1. Clean the backtraces 2. Log the details into importer.log 3. Omit the details from the database
Diffstat (limited to 'lib/gitlab/bitbucket_import/importer.rb')
-rw-r--r--lib/gitlab/bitbucket_import/importer.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb
index c9f0ed66a54..8047ef4fa15 100644
--- a/lib/gitlab/bitbucket_import/importer.rb
+++ b/lib/gitlab/bitbucket_import/importer.rb
@@ -11,6 +11,7 @@ module Gitlab
{ title: 'task', color: '#7F8C8D' }].freeze
attr_reader :project, :client, :errors, :users
+ attr_accessor :logger
def initialize(project)
@project = project
@@ -19,6 +20,7 @@ module Gitlab
@labels = {}
@errors = []
@users = {}
+ @logger = Gitlab::Import::Logger.build
end
def execute
@@ -41,6 +43,18 @@ module Gitlab
}.to_json)
end
+ def store_pull_request_error(pull_request, ex)
+ backtrace = Gitlab::Profiler.clean_backtrace(ex.backtrace)
+ error = { type: :pull_request, iid: pull_request.iid, errors: ex.message, trace: backtrace, raw_response: pull_request.raw }
+
+ log_error(error)
+ # Omit the details from the database to avoid blowing up usage in the error column
+ error.delete(:trace)
+ error.delete(:raw_response)
+
+ errors << error
+ end
+
def gitlab_user_id(project, username)
find_user_id(username) || project.creator_id
end
@@ -176,7 +190,7 @@ module Gitlab
import_pull_request_comments(pull_request, merge_request) if merge_request.persisted?
rescue StandardError => e
- errors << { type: :pull_request, iid: pull_request.iid, errors: e.message, trace: e.backtrace.join("\n"), raw_response: pull_request.raw }
+ store_pull_request_error(pull_request, e)
end
end
@@ -254,6 +268,18 @@ module Gitlab
updated_at: comment.updated_at
}
end
+
+ def log_error(details)
+ logger.error(log_base_data.merge(details))
+ end
+
+ def log_base_data
+ {
+ class: self.class.name,
+ project_id: project.id,
+ project_path: project.full_path
+ }
+ end
end
end
end