66import sentry_sdk
77from google .protobuf .message import Message as ProtobufMessage
88
9+ from snuba import settings
910from snuba .state import get_config
11+ from snuba .web .rpc .storage_routing .common import extract_message_meta
1012from 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