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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-04 15:15:02 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-04 15:15:02 +0300
commitf00510286b6ccda154c4926503397590a8851939 (patch)
treec4cd69ef2d0d6dd5abf30e3963ac00ead7421a19 /rubocop
parent9e5c2e7342d1393f90e74a2ae4b3f27492c22e1f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb29
1 files changed, 11 insertions, 18 deletions
diff --git a/rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb b/rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb
index 7fe308d6b40..badd81ff138 100644
--- a/rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb
+++ b/rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb
@@ -28,36 +28,29 @@ module RuboCop
HELP_LINK = 'https://docs.gitlab.com/ee/development/sidekiq/worker_attributes.html#job-data-consistency-strategies'
- MSG = <<~MSG
+ MISSING_DATA_CONSISTENCY_MSG = <<~MSG
Should define data_consistency expectation.
-
- It is encouraged for workers to use database replicas as much as possible by declaring
- data_consistency to use the :delayed or :sticky modes. Mode :always will result in the
- worker always hitting the primary database node for both reads and writes, which limits
- scalability.
-
- Some guidelines:
-
- 1. If your worker mostly writes or reads its own writes, use mode :always. TRY TO AVOID THIS.
- 2. If your worker performs mostly reads and can tolerate small delays, use mode :delayed.
- 3. If your worker performs mostly reads but cannot tolerate any delays, use mode :sticky.
-
See #{HELP_LINK} for a more detailed explanation of these settings.
MSG
+ DISCOURAGE_ALWAYS_MSG = "Refrain from using `:always` if possible." \
+ "See #{HELP_LINK} for a more detailed explanation of these settings."
+
def_node_search :application_worker?, <<~PATTERN
`(send nil? :include (const nil? :ApplicationWorker))
PATTERN
- def_node_search :data_consistency_defined?, <<~PATTERN
- `(send nil? :data_consistency ...)
+ def_node_matcher :data_consistency_value, <<~PATTERN
+ `(send nil? :data_consistency $(sym _) ...)
PATTERN
def on_class(node)
- return unless in_worker?(node) && application_worker?(node)
- return if data_consistency_defined?(node)
+ return unless application_worker?(node)
+
+ consistency = data_consistency_value(node)
+ return add_offense(node, message: MISSING_DATA_CONSISTENCY_MSG) if consistency.nil?
- add_offense(node)
+ add_offense(consistency, message: DISCOURAGE_ALWAYS_MSG) if consistency.value == :always
end
end
end