Refactor database selection in SidekiqServerMiddleware
What does this MR do?
Closes #332673 (closed)
To allow for workers to balance reads over database replicas, we introduced logic in SidekiqServerMiddleware
that makes decisions around whether to target the primary or replicas based on the job's data_consistency
requirement. We also need to inject the database_chosen
into the job hash so that we can label metrics with it in Sidekiq ServerMetrics
.
These decisions were made in a single side-effecting getter, which made it difficult to reason about what this method is actually responsible for. I split up these two concerns so that we first select the appropriate database strategy, and only then act on it.
Other changes I made:
- I addressed a related problem introduced in !63209 (merged) that resulted in the
data_consistency
setting being injected into the job hash twice: first in the client middleware, then again in the server middleware (using a different name:data_consistency
instead ofworker_data_consistency
). I removed the redundant assignment and fixedServerMetrics
to readworker_data_consistency
now. The original issue of this label missing from the metric should remain fixed. - I renamed
database_chosen
toload_balancing_strategy
since this is not always a database node value. The new values areprimary
,replica
,retry_primary
andretry_replica
. This label is not used in dashboards yet and just informational, so it's safe to rename. We also decided to expand on these in a follow-up in #333670 (closed).
This MR is just clean-up; nothing should change behaviorally. However, since we renamed a documented metric, we decided to highlight this via a changed
changelog entry.
Does this MR meet the acceptance criteria?
Conformity
-
I have included a changelog entry, or it's not needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.