Add latest changes from gitlab-org/gitlab@16-2-stable-ee

This commit is contained in:
GitLab Bot 2023-07-24 23:46:54 +00:00
parent ae5079ea12
commit db353eb79a
2 changed files with 28 additions and 9 deletions

View File

@ -123,7 +123,7 @@ module GitlabSettings
def stringify_keys!
error_msg = "Warning: Do not mutate #{self.class} objects: `#{__method__}`"
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(RuntimeError.new(error_msg), method: __method__)
log_and_raise_dev_exception(error_msg, method: __method__)
to_hash.deep_stringify_keys
end
@ -133,7 +133,7 @@ module GitlabSettings
def symbolize_keys!
error_msg = "Warning: Do not mutate #{self.class} objects: `#{__method__}`"
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(RuntimeError.new(error_msg), method: __method__)
log_and_raise_dev_exception(error_msg, method: __method__)
to_hash.deep_symbolize_keys
end
@ -151,7 +151,7 @@ module GitlabSettings
if @options.respond_to?(name)
error_msg = "Calling a hash method on #{self.class}: `#{name}`"
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(RuntimeError.new(error_msg), method: name)
log_and_raise_dev_exception(error_msg, method: name)
return @options.public_send(name, *args, &block) # rubocop: disable GitlabSecurity/PublicSend
end
@ -164,5 +164,20 @@ module GitlabSettings
@options.respond_to?(name, include_all)
end
private
# We can't call Gitlab::ErrorTracking.track_and_raise_for_dev_exception
# because that method will attempt to load ApplicationContext and
# fail to load User since the Devise is not yet set up in
# `config/initialiers/8_devise.rb`.
def log_and_raise_dev_exception(message, extra = {})
raise message unless Rails.env.production?
# Gitlab::BacktraceCleaner drops config/initializers, so we just limit the
# backtrace to the first 10 lines.
payload = extra.merge(message: message, caller: caller[0..10])
Gitlab::AppJsonLogger.warn(payload)
end
end
end

View File

@ -12,9 +12,11 @@ RSpec.describe GitlabSettings::Options, :aggregate_failures, feature_category: :
it 'returns the unchanged internal hash' do
stub_rails_env('production')
expect(Gitlab::ErrorTracking)
.to receive(:track_and_raise_for_dev_exception)
.with(RuntimeError.new("Warning: Do not mutate GitlabSettings::Options objects: `#{method}`"), method: method)
expect(Gitlab::AppJsonLogger)
.to receive(:warn)
.with(hash_including(
message: "Warning: Do not mutate GitlabSettings::Options objects: `#{method}`",
method: method))
.and_call_original
expect(options.send(method)).to be_truthy
@ -234,9 +236,11 @@ RSpec.describe GitlabSettings::Options, :aggregate_failures, feature_category: :
it 'delegates the method to the internal options hash' do
stub_rails_env('production')
expect(Gitlab::ErrorTracking)
.to receive(:track_and_raise_for_dev_exception)
.with(RuntimeError.new('Calling a hash method on GitlabSettings::Options: `delete`'), method: :delete)
expect(Gitlab::AppJsonLogger)
.to receive(:warn)
.with(hash_including(
message: 'Calling a hash method on GitlabSettings::Options: `delete`',
method: :delete))
.and_call_original
expect { options.foo.delete('bar') }