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
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-16 15:07:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-16 15:07:43 +0300
commitd10a462fedbd7794a83abdba9b4526600f71de5b (patch)
tree4dbd21cb89013d9e07b05bac5101cd13585a8be5 /lib
parent13867d66e92c2fd8962a126db4fbdc32891343c9 (diff)
Add latest changes from gitlab-org/gitlab@masterogolowinski-master-patch-80898
Diffstat (limited to 'lib')
-rw-r--r--lib/api/helpers.rb4
-rw-r--r--lib/container_registry/tag.rb2
-rw-r--r--lib/gitlab/bitbucket_import/importer.rb2
-rw-r--r--lib/gitlab/bitbucket_server_import/importer.rb10
-rw-r--r--lib/gitlab/ci/config.rb2
-rw-r--r--lib/gitlab/ci/config/entry/job.rb19
-rw-r--r--lib/gitlab/ci/config/entry/root.rb6
-rw-r--r--lib/gitlab/ci/config/entry/workflow.rb4
-rw-r--r--lib/gitlab/ci/pipeline/chain/config/process.rb2
-rw-r--r--lib/gitlab/ci/pipeline/chain/evaluate_workflow_rules.rb20
-rw-r--r--lib/gitlab/ci/yaml_processor.rb28
-rw-r--r--lib/gitlab/config/entry/configurable.rb17
-rw-r--r--lib/gitlab/diff/file_collection/base.rb6
-rw-r--r--lib/gitlab/diff/highlight.rb2
-rw-r--r--lib/gitlab/diff/highlight_cache.rb12
-rw-r--r--lib/gitlab/error_tracking.rb (renamed from lib/gitlab/sentry.rb)4
-rw-r--r--lib/gitlab/error_tracking/logger.rb (renamed from lib/gitlab/sentry/logger.rb)2
-rw-r--r--lib/gitlab/file_detector.rb5
-rw-r--r--lib/gitlab/gitaly_client.rb2
-rw-r--r--lib/gitlab/github_import/importer/pull_request_importer.rb2
-rw-r--r--lib/gitlab/gon_helper.rb1
-rw-r--r--lib/gitlab/gpg.rb2
-rw-r--r--lib/gitlab/graphql/calls_gitaly/instrumentation.rb2
-rw-r--r--lib/gitlab/graphql/query_analyzers/logger_analyzer.rb4
-rw-r--r--lib/gitlab/highlight.rb2
-rw-r--r--lib/gitlab/import_export/relation_tree_restorer.rb2
-rw-r--r--lib/gitlab/import_export/shared.rb2
-rw-r--r--lib/gitlab/mail_room.rb15
-rw-r--r--lib/gitlab/shell.rb6
-rw-r--r--lib/gitlab/usage_data_counters/base_counter.rb2
-rw-r--r--lib/sentry/client.rb6
31 files changed, 133 insertions, 62 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index a3648ec3df3..d15784bb1ab 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -384,8 +384,8 @@ module API
def handle_api_exception(exception)
if report_exception?(exception)
define_params_for_grape_middleware
- Gitlab::Sentry.with_context(current_user) do
- Gitlab::Sentry.track_exception(exception, params)
+ Gitlab::ErrorTracking.with_context(current_user) do
+ Gitlab::ErrorTracking.track_exception(exception, params)
end
end
diff --git a/lib/container_registry/tag.rb b/lib/container_registry/tag.rb
index 2cc4c8d8b1c..3c308258a3f 100644
--- a/lib/container_registry/tag.rb
+++ b/lib/container_registry/tag.rb
@@ -83,6 +83,8 @@ module ContainerRegistry
strong_memoize(:created_at) do
DateTime.rfc3339(config['created'])
+ rescue ArgumentError
+ nil
end
end
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb
index 5fbf7be2568..67118aed549 100644
--- a/lib/gitlab/bitbucket_import/importer.rb
+++ b/lib/gitlab/bitbucket_import/importer.rb
@@ -45,7 +45,7 @@ module Gitlab
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 }
- Gitlab::Sentry.log_exception(ex, error)
+ Gitlab::ErrorTracking.log_exception(ex, error)
# Omit the details from the database to avoid blowing up usage in the error column
error.delete(:trace)
diff --git a/lib/gitlab/bitbucket_server_import/importer.rb b/lib/gitlab/bitbucket_server_import/importer.rb
index 1a9ac65e641..b7b2fe115c1 100644
--- a/lib/gitlab/bitbucket_server_import/importer.rb
+++ b/lib/gitlab/bitbucket_server_import/importer.rb
@@ -133,7 +133,7 @@ module Gitlab
log_info(stage: 'import_repository', message: 'finished import')
rescue Gitlab::Shell::Error => e
- Gitlab::Sentry.log_exception(
+ Gitlab::ErrorTracking.log_exception(
e,
stage: 'import_repository', message: 'failed import', error: e.message
)
@@ -167,7 +167,7 @@ module Gitlab
batch.each do |pull_request|
import_bitbucket_pull_request(pull_request)
rescue StandardError => e
- Gitlab::Sentry.log_exception(
+ Gitlab::ErrorTracking.log_exception(
e,
stage: 'import_pull_requests', iid: pull_request.iid, error: e.message
)
@@ -182,7 +182,7 @@ module Gitlab
client.delete_branch(project_key, repository_slug, branch.name, branch.sha)
project.repository.delete_branch(branch.name)
rescue BitbucketServer::Connection::ConnectionError => e
- Gitlab::Sentry.log_exception(
+ Gitlab::ErrorTracking.log_exception(
e,
stage: 'delete_temp_branches', branch: branch.name, error: e.message
)
@@ -297,7 +297,7 @@ module Gitlab
# a regular note.
create_fallback_diff_note(merge_request, comment, position)
rescue StandardError => e
- Gitlab::Sentry.log_exception(
+ Gitlab::ErrorTracking.log_exception(
e,
stage: 'create_diff_note', comment_id: comment.id, error: e.message
)
@@ -338,7 +338,7 @@ module Gitlab
merge_request.notes.create!(pull_request_comment_attributes(replies))
end
rescue StandardError => e
- Gitlab::Sentry.log_exception(
+ Gitlab::ErrorTracking.log_exception(
e,
stage: 'import_standalone_pr_comments', merge_request_id: merge_request.id, comment_id: comment.id, error: e.message
)
diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb
index ef11b8dc530..38ab3475d01 100644
--- a/lib/gitlab/ci/config.rb
+++ b/lib/gitlab/ci/config.rb
@@ -95,7 +95,7 @@ module Gitlab
end
def track_and_raise_for_dev_exception(error)
- Gitlab::Sentry.track_and_raise_for_dev_exception(error, @context.sentry_payload)
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, @context.sentry_payload)
end
# Overriden in EE
diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb
index c2ed448ff91..5164223876a 100644
--- a/lib/gitlab/ci/config/entry/job.rb
+++ b/lib/gitlab/ci/config/entry/job.rb
@@ -120,7 +120,7 @@ module Gitlab
entry :only, Entry::Policy,
description: 'Refs policy this job will be executed for.',
- default: Entry::Policy::DEFAULT_ONLY,
+ default: ::Gitlab::Ci::Config::Entry::Policy::DEFAULT_ONLY,
inherit: false
entry :except, Entry::Policy,
@@ -177,11 +177,18 @@ module Gitlab
@entries.delete(:type)
- # This is something of a hack, see issue for details:
- # https://gitlab.com/gitlab-org/gitlab/issues/31685
- if !only_defined? && has_rules?
- @entries.delete(:only)
- @entries.delete(:except)
+ has_workflow_rules = deps&.workflow&.has_rules?
+
+ # If workflow:rules: or rules: are used
+ # they are considered not compatible
+ # with `only/except` defaults
+ #
+ # Context: https://gitlab.com/gitlab-org/gitlab/merge_requests/21742
+ if has_rules? || has_workflow_rules
+ # Remove only/except defaults
+ # defaults are not considered as defined
+ @entries.delete(:only) unless only_defined?
+ @entries.delete(:except) unless except_defined?
end
end
end
diff --git a/lib/gitlab/ci/config/entry/root.rb b/lib/gitlab/ci/config/entry/root.rb
index 25fb278d9b8..12dd942fc1c 100644
--- a/lib/gitlab/ci/config/entry/root.rb
+++ b/lib/gitlab/ci/config/entry/root.rb
@@ -67,7 +67,7 @@ module Gitlab
entry :workflow, Entry::Workflow,
description: 'List of evaluable rules to determine Pipeline status'
- helpers :default, :jobs, :stages, :types, :variables
+ helpers :default, :jobs, :stages, :types, :variables, :workflow
delegate :before_script_value,
:image_value,
@@ -106,6 +106,10 @@ module Gitlab
self[:default]
end
+ def workflow
+ self[:workflow] if workflow_defined?
+ end
+
private
# rubocop: disable CodeReuse/ActiveRecord
diff --git a/lib/gitlab/ci/config/entry/workflow.rb b/lib/gitlab/ci/config/entry/workflow.rb
index a51a3fbdcd2..1d9007c9b9b 100644
--- a/lib/gitlab/ci/config/entry/workflow.rb
+++ b/lib/gitlab/ci/config/entry/workflow.rb
@@ -18,6 +18,10 @@ module Gitlab
entry :rules, Entry::Rules,
description: 'List of evaluable Rules to determine Pipeline status.',
metadata: { allowed_when: %w[always never] }
+
+ def has_rules?
+ @config.try(:key?, :rules)
+ end
end
end
end
diff --git a/lib/gitlab/ci/pipeline/chain/config/process.rb b/lib/gitlab/ci/pipeline/chain/config/process.rb
index feb5b4556e1..09d1b0edc93 100644
--- a/lib/gitlab/ci/pipeline/chain/config/process.rb
+++ b/lib/gitlab/ci/pipeline/chain/config/process.rb
@@ -21,7 +21,7 @@ module Gitlab
rescue Gitlab::Ci::YamlProcessor::ValidationError => ex
error(ex.message, config_error: true)
rescue => ex
- Gitlab::Sentry.track_exception(ex,
+ Gitlab::ErrorTracking.track_exception(ex,
project_id: project.id,
sha: @pipeline.sha
)
diff --git a/lib/gitlab/ci/pipeline/chain/evaluate_workflow_rules.rb b/lib/gitlab/ci/pipeline/chain/evaluate_workflow_rules.rb
index 0ee9485eebc..81f5733b279 100644
--- a/lib/gitlab/ci/pipeline/chain/evaluate_workflow_rules.rb
+++ b/lib/gitlab/ci/pipeline/chain/evaluate_workflow_rules.rb
@@ -9,7 +9,13 @@ module Gitlab
include Chain::Helpers
def perform!
- return unless Feature.enabled?(:workflow_rules, @pipeline.project)
+ unless feature_enabled?
+ if has_workflow_rules?
+ error("Workflow rules are disabled", config_error: true)
+ end
+
+ return
+ end
unless workflow_passed?
error('Pipeline filtered out by workflow rules.')
@@ -17,13 +23,15 @@ module Gitlab
end
def break?
- return false unless Feature.enabled?(:workflow_rules, @pipeline.project)
-
- !workflow_passed?
+ @pipeline.errors.any? || @pipeline.persisted?
end
private
+ def feature_enabled?
+ Feature.enabled?(:workflow_rules, @pipeline.project, default_enabled: true)
+ end
+
def workflow_passed?
strong_memoize(:workflow_passed) do
workflow_rules.evaluate(@pipeline, global_context).pass?
@@ -40,6 +48,10 @@ module Gitlab
@pipeline, yaml_variables: workflow_config[:yaml_variables])
end
+ def has_workflow_rules?
+ workflow_config[:rules].present?
+ end
+
def workflow_config
@command.config_processor.workflow_attributes || {}
end
diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb
index 6f1ab79064a..7f3f518dfd7 100644
--- a/lib/gitlab/ci/yaml_processor.rb
+++ b/lib/gitlab/ci/yaml_processor.rb
@@ -9,6 +9,12 @@ module Gitlab
attr_reader :stages, :jobs
+ ResultWithErrors = Struct.new(:content, :errors) do
+ def valid?
+ errors.empty?
+ end
+ end
+
def initialize(config, opts = {})
@ci_config = Gitlab::Ci::Config.new(config, **opts)
@config = @ci_config.to_hash
@@ -22,6 +28,18 @@ module Gitlab
raise ValidationError, e.message
end
+ def self.new_with_validation_errors(content, opts = {})
+ return ResultWithErrors.new('', ['Please provide content of .gitlab-ci.yml']) if content.blank?
+
+ config = Gitlab::Ci::Config.new(content, **opts)
+ return ResultWithErrors.new("", config.errors) unless config.valid?
+
+ config = Gitlab::Ci::YamlProcessor.new(content, opts)
+ ResultWithErrors.new(config, [])
+ rescue ValidationError, Gitlab::Ci::Config::ConfigError => e
+ ResultWithErrors.new('', [e.message])
+ end
+
def builds
@jobs.map do |name, _|
build_attributes(name)
@@ -42,6 +60,8 @@ module Gitlab
yaml_variables: transform_to_yaml_variables(job_variables(name)),
needs_attributes: job.dig(:needs, :job),
interruptible: job[:interruptible],
+ only: job[:only],
+ except: job[:except],
rules: job[:rules],
cache: job[:cache],
resource_group_key: job[:resource_group],
@@ -72,13 +92,7 @@ module Gitlab
def stages_attributes
@stages.uniq.map do |stage|
- seeds = stage_builds_attributes(stage).map do |attributes|
- job = @jobs.fetch(attributes[:name].to_sym)
-
- attributes
- .merge(only: job.fetch(:only, {}))
- .merge(except: job.fetch(:except, {}))
- end
+ seeds = stage_builds_attributes(stage)
{ name: stage, index: @stages.index(stage), builds: seeds }
end
diff --git a/lib/gitlab/config/entry/configurable.rb b/lib/gitlab/config/entry/configurable.rb
index bda84dc2cff..d5a093a469a 100644
--- a/lib/gitlab/config/entry/configurable.rb
+++ b/lib/gitlab/config/entry/configurable.rb
@@ -25,7 +25,6 @@ module Gitlab
end
end
- # rubocop: disable CodeReuse/ActiveRecord
def compose!(deps = nil)
return unless valid?
@@ -35,11 +34,7 @@ module Gitlab
# we can end with different config types like String
next unless config.is_a?(Hash)
- factory
- .value(config[key])
- .with(key: key, parent: self)
-
- entries[key] = factory.create!
+ entry_create!(key, config[key])
end
yield if block_given?
@@ -49,6 +44,16 @@ module Gitlab
end
end
end
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ def entry_create!(key, value)
+ factory = self.class
+ .nodes[key]
+ .value(value)
+ .with(key: key, parent: self)
+
+ entries[key] = factory.create!
+ end
# rubocop: enable CodeReuse/ActiveRecord
def skip_config_hash_validation?
diff --git a/lib/gitlab/diff/file_collection/base.rb b/lib/gitlab/diff/file_collection/base.rb
index ea915a6b84b..b1f171c0e7d 100644
--- a/lib/gitlab/diff/file_collection/base.rb
+++ b/lib/gitlab/diff/file_collection/base.rb
@@ -31,7 +31,11 @@ module Gitlab
end
def diff_files
- @diff_files ||= diffs.decorate! { |diff| decorate_diff!(diff) }
+ raw_diff_files
+ end
+
+ def raw_diff_files
+ @raw_diff_files ||= diffs.decorate! { |diff| decorate_diff!(diff) }
end
def diff_file_paths
diff --git a/lib/gitlab/diff/highlight.rb b/lib/gitlab/diff/highlight.rb
index 676743dbd59..0d027809ba8 100644
--- a/lib/gitlab/diff/highlight.rb
+++ b/lib/gitlab/diff/highlight.rb
@@ -35,7 +35,7 @@ module Gitlab
# match the blob, which is a bug. But we shouldn't fail to render
# completely in that case, even though we want to report the error.
rescue RangeError => e
- Gitlab::Sentry.track_and_raise_for_dev_exception(e, issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/45441')
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e, issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/45441')
end
end
diff --git a/lib/gitlab/diff/highlight_cache.rb b/lib/gitlab/diff/highlight_cache.rb
index 10363236234..403effbb0c6 100644
--- a/lib/gitlab/diff/highlight_cache.rb
+++ b/lib/gitlab/diff/highlight_cache.rb
@@ -70,8 +70,6 @@ module Gitlab
def cacheable_files
strong_memoize(:cacheable_files) do
- diff_files = @diff_collection.diff_files
-
diff_files.select { |file| cacheable?(file) && read_file(file).nil? }
end
end
@@ -114,7 +112,7 @@ module Gitlab
def file_paths
strong_memoize(:file_paths) do
- @diff_collection.diffs.collect(&:file_path)
+ diff_files.collect(&:file_path)
end
end
@@ -145,6 +143,14 @@ module Gitlab
def cacheable?(diff_file)
diffable.present? && diff_file.text? && diff_file.diffable?
end
+
+ def diff_files
+ # We access raw_diff_files here, as diff_files will attempt to apply the
+ # highlighting code found in this class, leading to a circular
+ # reference.
+ #
+ @diff_collection.raw_diff_files
+ end
end
end
end
diff --git a/lib/gitlab/sentry.rb b/lib/gitlab/error_tracking.rb
index aa8f6fa12b1..6df9bfad657 100644
--- a/lib/gitlab/sentry.rb
+++ b/lib/gitlab/error_tracking.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Gitlab
- module Sentry
+ module ErrorTracking
class << self
def configure
Raven.configure do |config|
@@ -113,7 +113,7 @@ module Gitlab
Gitlab::ExceptionLogFormatter.format!(exception, log_hash)
- Gitlab::Sentry::Logger.error(log_hash)
+ Gitlab::ErrorTracking::Logger.error(log_hash)
end
end
diff --git a/lib/gitlab/sentry/logger.rb b/lib/gitlab/error_tracking/logger.rb
index fa24b8d17d2..1b081f943aa 100644
--- a/lib/gitlab/sentry/logger.rb
+++ b/lib/gitlab/error_tracking/logger.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Gitlab
- module Sentry
+ module ErrorTracking
class Logger < ::Gitlab::JsonLogger
def self.file_name_noext
'exceptions_json'
diff --git a/lib/gitlab/file_detector.rb b/lib/gitlab/file_detector.rb
index 9fc2217ad43..a386c21983d 100644
--- a/lib/gitlab/file_detector.rb
+++ b/lib/gitlab/file_detector.rb
@@ -36,7 +36,10 @@ module Gitlab
podspec_json: %r{\A[^/]*\.podspec\.json\z},
podspec: %r{\A[^/]*\.podspec\z},
requirements_txt: %r{\A[^/]*requirements\.txt\z},
- yarn_lock: 'yarn.lock'
+ yarn_lock: 'yarn.lock',
+
+ # OpenAPI Specification files
+ openapi: %r{.*(openapi|swagger).*\.(yaml|yml|json)\z}i
}.freeze
# Returns an Array of file types based on the given paths.
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb
index 41207e8cbde..1ce30176644 100644
--- a/lib/gitlab/gitaly_client.rb
+++ b/lib/gitlab/gitaly_client.rb
@@ -67,7 +67,7 @@ module Gitlab
File.read(cert_file).scan(PEM_REGEX).map do |cert|
OpenSSL::X509::Certificate.new(cert).to_pem
rescue OpenSSL::OpenSSLError => e
- Gitlab::Sentry.track_and_raise_for_dev_exception(e, cert_file: cert_file)
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e, cert_file: cert_file)
nil
end.compact
end.uniq.join("\n")
diff --git a/lib/gitlab/github_import/importer/pull_request_importer.rb b/lib/gitlab/github_import/importer/pull_request_importer.rb
index d762ea179e3..6d2aff63a47 100644
--- a/lib/gitlab/github_import/importer/pull_request_importer.rb
+++ b/lib/gitlab/github_import/importer/pull_request_importer.rb
@@ -91,7 +91,7 @@ module Gitlab
project.repository.add_branch(project.creator, source_branch, pull_request.source_branch_sha)
rescue Gitlab::Git::CommandError => e
- Gitlab::Sentry.track_exception(e,
+ Gitlab::ErrorTracking.track_exception(e,
source_branch: source_branch,
project_id: merge_request.project.id,
merge_request_id: merge_request.id)
diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb
index 487dcd58d01..f22c69c531a 100644
--- a/lib/gitlab/gon_helper.rb
+++ b/lib/gitlab/gon_helper.rb
@@ -41,7 +41,6 @@ module Gitlab
# Initialize gon.features with any flags that should be
# made globally available to the frontend
- push_frontend_feature_flag(:suppress_ajax_navigation_errors, default_enabled: true)
push_frontend_feature_flag(:snippets_vue, default_enabled: false)
end
diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb
index 048534e04de..7e6f6a519a6 100644
--- a/lib/gitlab/gpg.rb
+++ b/lib/gitlab/gpg.rb
@@ -110,7 +110,7 @@ module Gitlab
folder_contents = Dir.children(tmp_dir)
# This means we left a GPG-agent process hanging. Logging the problem in
# sentry will make this more visible.
- Gitlab::Sentry.track_and_raise_for_dev_exception(e,
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e,
issue_url: 'https://gitlab.com/gitlab-org/gitlab/issues/20918',
tmp_dir: tmp_dir, contents: folder_contents)
end
diff --git a/lib/gitlab/graphql/calls_gitaly/instrumentation.rb b/lib/gitlab/graphql/calls_gitaly/instrumentation.rb
index 118748d5a56..11d3c50e093 100644
--- a/lib/gitlab/graphql/calls_gitaly/instrumentation.rb
+++ b/lib/gitlab/graphql/calls_gitaly/instrumentation.rb
@@ -32,7 +32,7 @@ module Gitlab
# Will inform you if there needs to be `calls_gitaly: true` as a kwarg in the field declaration
# if there is at least 1 Gitaly call involved with the field resolution.
error = RuntimeError.new("Gitaly is called for field '#{type_object.name}' on #{type_object.owner.try(:name)} - please either specify a constant complexity or add `calls_gitaly: true` to the field declaration")
- Gitlab::Sentry.track_and_raise_for_dev_exception(error)
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error)
end
end
end
diff --git a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
index a6eb35be427..327a9c549d5 100644
--- a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
+++ b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
@@ -18,7 +18,7 @@ module Gitlab
variables: variables
})
rescue => e
- Gitlab::Sentry.track_and_raise_for_dev_exception(e)
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
default_initial_values(query)
end
@@ -38,7 +38,7 @@ module Gitlab
GraphqlLogger.info(memo.except!(:time_started, :query))
rescue => e
- Gitlab::Sentry.track_and_raise_for_dev_exception(e)
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
end
private
diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb
index fdb81e62bd7..22b9a038768 100644
--- a/lib/gitlab/highlight.rb
+++ b/lib/gitlab/highlight.rb
@@ -61,7 +61,7 @@ module Gitlab
tokens = lexer.lex(text, continue: continue)
Timeout.timeout(timeout_time) { @formatter.format(tokens, tag: tag).html_safe }
rescue Timeout::Error => e
- Gitlab::Sentry.track_and_raise_for_dev_exception(e)
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
highlight_plain(text)
rescue
highlight_plain(text)
diff --git a/lib/gitlab/import_export/relation_tree_restorer.rb b/lib/gitlab/import_export/relation_tree_restorer.rb
index d2d0cddfcbb..d9c253788b4 100644
--- a/lib/gitlab/import_export/relation_tree_restorer.rb
+++ b/lib/gitlab/import_export/relation_tree_restorer.rb
@@ -82,7 +82,7 @@ module Gitlab
end
def log_import_failure(relation_key, relation_index, exception)
- Gitlab::Sentry.track_exception(exception,
+ Gitlab::ErrorTracking.track_exception(exception,
project_id: @importable.id, relation_key: relation_key, relation_index: relation_index)
ImportFailure.create(
diff --git a/lib/gitlab/import_export/shared.rb b/lib/gitlab/import_export/shared.rb
index 7bdfd928723..8d81b2af065 100644
--- a/lib/gitlab/import_export/shared.rb
+++ b/lib/gitlab/import_export/shared.rb
@@ -56,7 +56,7 @@ module Gitlab
end
def error(error)
- Gitlab::Sentry.track_exception(error, log_base_data)
+ Gitlab::ErrorTracking.track_exception(error, log_base_data)
add_error_message(error.message)
end
diff --git a/lib/gitlab/mail_room.rb b/lib/gitlab/mail_room.rb
index 78f2d83c1af..f7699ef1718 100644
--- a/lib/gitlab/mail_room.rb
+++ b/lib/gitlab/mail_room.rb
@@ -4,15 +4,21 @@ require 'yaml'
require 'json'
require_relative 'redis/queues' unless defined?(Gitlab::Redis::Queues)
+# This service is run independently of the main Rails process,
+# therefore the `Rails` class and its methods are unavailable.
+
module Gitlab
module MailRoom
+ RAILS_ROOT_DIR = Pathname.new('../..').expand_path(__dir__).freeze
+
DEFAULT_CONFIG = {
enabled: false,
port: 143,
ssl: false,
start_tls: false,
mailbox: 'inbox',
- idle_timeout: 60
+ idle_timeout: 60,
+ log_path: RAILS_ROOT_DIR.join('log', 'mail_room_json.log')
}.freeze
class << self
@@ -33,7 +39,7 @@ module Gitlab
def fetch_config
return {} unless File.exist?(config_file)
- config = YAML.load_file(config_file)[rails_env].deep_symbolize_keys[:incoming_email] || {}
+ config = load_from_yaml || {}
config = DEFAULT_CONFIG.merge(config) do |_key, oldval, newval|
newval.nil? ? oldval : newval
end
@@ -47,6 +53,7 @@ module Gitlab
end
end
+ config[:log_path] = File.expand_path(config[:log_path], RAILS_ROOT_DIR)
config
end
@@ -57,6 +64,10 @@ module Gitlab
def config_file
ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] || File.expand_path('../../config/gitlab.yml', __dir__)
end
+
+ def load_from_yaml
+ YAML.load_file(config_file)[rails_env].deep_symbolize_keys[:incoming_email]
+ end
end
end
end
diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb
index 45de77f77aa..290c4cff329 100644
--- a/lib/gitlab/shell.rb
+++ b/lib/gitlab/shell.rb
@@ -126,7 +126,7 @@ module Gitlab
true
rescue => e
- Gitlab::Sentry.track_exception(e, path: path, new_path: new_path, storage: storage)
+ Gitlab::ErrorTracking.track_exception(e, path: path, new_path: new_path, storage: storage)
false
end
@@ -158,7 +158,7 @@ module Gitlab
true
rescue => e
Rails.logger.warn("Repository does not exist: #{e} at: #{name}.git") # rubocop:disable Gitlab/RailsLogger
- Gitlab::Sentry.track_exception(e, path: name, storage: storage)
+ Gitlab::ErrorTracking.track_exception(e, path: name, storage: storage)
false
end
@@ -267,7 +267,7 @@ module Gitlab
def mv_namespace(storage, old_name, new_name)
Gitlab::GitalyClient::NamespaceService.new(storage).rename(old_name, new_name)
rescue GRPC::InvalidArgument => e
- Gitlab::Sentry.track_exception(e, old_name: old_name, new_name: new_name, storage: storage)
+ Gitlab::ErrorTracking.track_exception(e, old_name: old_name, new_name: new_name, storage: storage)
false
end
diff --git a/lib/gitlab/usage_data_counters/base_counter.rb b/lib/gitlab/usage_data_counters/base_counter.rb
index 461d562a0d4..77fc216738f 100644
--- a/lib/gitlab/usage_data_counters/base_counter.rb
+++ b/lib/gitlab/usage_data_counters/base_counter.rb
@@ -8,7 +8,7 @@ module Gitlab::UsageDataCounters
class << self
def redis_key(event)
- Gitlab::Sentry.track_and_raise_for_dev_exception(UnknownEvent.new, event: event) unless known_events.include?(event.to_s)
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(UnknownEvent.new, event: event) unless known_events.include?(event.to_s)
"USAGE_#{prefix}_#{event}".upcase
end
diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb
index 851896a6429..3df688a1fda 100644
--- a/lib/sentry/client.rb
+++ b/lib/sentry/client.rb
@@ -62,7 +62,7 @@ module Sentry
def handle_mapping_exceptions(&block)
yield
rescue KeyError => e
- Gitlab::Sentry.track_exception(e)
+ Gitlab::ErrorTracking.track_exception(e)
raise MissingKeysError, "Sentry API response is missing keys. #{e.message}"
end
@@ -118,7 +118,7 @@ module Sentry
def handle_request_exceptions
yield
rescue Gitlab::HTTP::Error => e
- Gitlab::Sentry.track_exception(e)
+ Gitlab::ErrorTracking.track_exception(e)
raise_error 'Error when connecting to Sentry'
rescue Net::OpenTimeout
raise_error 'Connection to Sentry timed out'
@@ -129,7 +129,7 @@ module Sentry
rescue Errno::ECONNREFUSED
raise_error 'Connection refused'
rescue => e
- Gitlab::Sentry.track_exception(e)
+ Gitlab::ErrorTracking.track_exception(e)
raise_error "Sentry request failed due to #{e.class}"
end