diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-08 06:08:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-08 06:08:48 +0300 |
commit | baa5da6de5e05bfa0f0d96d26f3ace54041aaf92 (patch) | |
tree | 3870994c882fd02ac117c08c66aa629a3da12b46 /lib/gitlab/instrumentation | |
parent | 044a953eb6b92e39cf32678296aa219176c9ad92 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/instrumentation')
-rw-r--r-- | lib/gitlab/instrumentation/redis_base.rb | 22 | ||||
-rw-r--r-- | lib/gitlab/instrumentation/redis_cluster_validator.rb | 15 |
2 files changed, 10 insertions, 27 deletions
diff --git a/lib/gitlab/instrumentation/redis_base.rb b/lib/gitlab/instrumentation/redis_base.rb index 4f27fce43a4..91ee5885ed2 100644 --- a/lib/gitlab/instrumentation/redis_base.rb +++ b/lib/gitlab/instrumentation/redis_base.rb @@ -5,8 +5,6 @@ require 'redis' module Gitlab module Instrumentation class RedisBase - VALIDATE_ALLOWED_COMMANDS_KEY = 'validate_allowed_commands_flag' - class << self include ::Gitlab::Utils::StrongMemoize include ::Gitlab::Instrumentation::RedisPayload @@ -77,23 +75,13 @@ module Gitlab query_time.round(::Gitlab::InstrumentationHelper::DURATION_PRECISION) end - def validate_allowed_commands? - ::Gitlab::SafeRequestStore.fetch(VALIDATE_ALLOWED_COMMANDS_KEY) do - Feature.enabled?(:validate_allowed_cross_slot_commands, type: :development) - end - end - def redis_cluster_validate!(commands) - return true unless @redis_cluster_validation - - result = ::Gitlab::Instrumentation::RedisClusterValidator.validate(commands, validate_allowed_commands?) - return true if result.nil? - - if !result[:valid] && !result[:allowed] && (Rails.env.development? || Rails.env.test?) - raise RedisClusterValidator::CrossSlotError, "Redis command #{result[:command_name]} arguments hash to different slots. See https://docs.gitlab.com/ee/development/redis.html#multi-key-commands" - end + ::Gitlab::Instrumentation::RedisClusterValidator.validate!(commands) if @redis_cluster_validation + true + rescue ::Gitlab::Instrumentation::RedisClusterValidator::CrossSlotError + raise if Rails.env.development? || Rails.env.test? # raise in test environments to catch violations - result[:valid] + false end def enable_redis_cluster_validation diff --git a/lib/gitlab/instrumentation/redis_cluster_validator.rb b/lib/gitlab/instrumentation/redis_cluster_validator.rb index ad715574ec2..a928d626f38 100644 --- a/lib/gitlab/instrumentation/redis_cluster_validator.rb +++ b/lib/gitlab/instrumentation/redis_cluster_validator.rb @@ -183,8 +183,8 @@ module Gitlab CrossSlotError = Class.new(StandardError) class << self - def validate(commands, validate_allowed_cmd) - return if allow_cross_slot_commands? && !validate_allowed_cmd + def validate!(commands) + return if allow_cross_slot_commands? return if commands.empty? # early exit for single-command (non-pipelined) if it is a single-key-command @@ -192,14 +192,9 @@ module Gitlab return if commands.size == 1 && REDIS_COMMANDS.dig(command_name, :single_key) key_slots = commands.map { |command| key_slots(command) }.flatten - - { - valid: !key_slots.uniq.many?, # rubocop: disable CodeReuse/ActiveRecord - command_name: command_name, - key_count: key_slots.size, - allowed: allow_cross_slot_commands?, - command: commands.first.join(' ') - } + if key_slots.uniq.many? # rubocop: disable CodeReuse/ActiveRecord + raise CrossSlotError, "Redis command #{command_name} arguments hash to different slots. See https://docs.gitlab.com/ee/development/redis.html#multi-key-commands" + end end # Keep track of the call stack to allow nested calls to work. |