Skip to content

Commit 031bf0d

Browse files
xurui-cRachel ChenRachel Chen
authored
fix(cbrs): set request in routing decision (#7241)
fixes https://sentry.sentry.io/issues/6678390448/?project=300688&query=&referrer=issue-stream&stream_index=1 --------- Co-authored-by: Rachel Chen <[email protected]> Co-authored-by: Rachel Chen <[email protected]>
1 parent 7221838 commit 031bf0d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

snuba/web/rpc/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ def execute(self, in_msg: Tin) -> Tout:
157157
span = scope.span
158158
if span is not None:
159159
span.description = self.config_key()
160-
self.routing_context = RoutingContext(timer=self._timer, in_msg=in_msg)
160+
self.routing_decision.routing_context = RoutingContext(
161+
timer=self._timer, in_msg=in_msg
162+
)
161163

162164
self.__before_execute(in_msg)
163165
error = None
@@ -218,7 +220,7 @@ def __before_execute(self, in_msg: Tin) -> None:
218220
)
219221
self.routing_decision.strategy = selected_strategy
220222
self.routing_decision = selected_strategy.get_routing_decision(
221-
self.routing_context
223+
self.routing_decision.routing_context
222224
)
223225
self._timer.mark("rpc_start")
224226
self._before_execute(in_msg)

snuba/web/rpc/storage_routing/routing_strategy_selector.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import sentry_sdk
77
from google.protobuf.message import Message as ProtobufMessage
88

9+
from snuba import settings
910
from snuba.state import get_config
11+
from snuba.web.rpc.storage_routing.common import extract_message_meta
1012
from snuba.web.rpc.storage_routing.routing_strategies.outcomes_based import (
1113
OutcomesBasedRoutingStrategy,
1214
)
@@ -88,7 +90,8 @@ class RoutingStrategySelector:
8890
def get_storage_routing_config(
8991
self, in_msg: ProtobufMessage
9092
) -> StorageRoutingConfig:
91-
organization_id = str(in_msg.meta.organization_id) # type: ignore
93+
in_msg_meta = extract_message_meta(in_msg)
94+
organization_id = str(in_msg_meta.organization_id)
9295
try:
9396
overrides = json.loads(
9497
str(get_config(_STORAGE_ROUTING_CONFIG_OVERRIDE_KEY, "{}"))
@@ -106,7 +109,8 @@ def select_routing_strategy(
106109
self, routing_context: RoutingContext
107110
) -> BaseRoutingStrategy:
108111
try:
109-
combined_org_and_project_ids = f"{routing_context.in_msg.meta.organization_id}:{'.'.join(str(pid) for pid in sorted(routing_context.in_msg.meta.project_ids))}" # type: ignore
112+
in_msg_meta = extract_message_meta(routing_context.in_msg)
113+
combined_org_and_project_ids = f"{in_msg_meta.organization_id}:{'.'.join(str(pid) for pid in sorted(in_msg_meta.project_ids))}"
110114
bucket = (
111115
int(hashlib.md5(combined_org_and_project_ids.encode()).hexdigest(), 16)
112116
% _NUM_BUCKETS
@@ -121,6 +125,8 @@ def select_routing_strategy(
121125
if bucket < cumulative_buckets:
122126
return BaseRoutingStrategy.get_from_name(strategy_name)()
123127
except Exception as e:
128+
if settings.RAISE_ON_ROUTING_STRATEGY_FAILURES:
129+
raise e
124130
sentry_sdk.capture_message(f"Error selecting routing strategy: {e}")
125131
return OutcomesBasedRoutingStrategy()
126132

0 commit comments

Comments
 (0)