Skip to content

Commit 7616b58

Browse files
authored
fix(storage-routing): If item type is unspecified, default to spans (#7350)
Requests for Traces do not have item type specified (which makes sense). In order to use tracing, a customer is most likely going to be ingesting spans. Thus, use spans as the default item when unspecified. We can definitely get more sophisticated with this but this will allow us to sample GetTraces calls and solve some timeouts on big customers
1 parent e3b61aa commit 7616b58

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

snuba/web/rpc/storage_routing/routing_strategies/outcomes_based.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,14 @@ def _get_routing_decision(self, routing_context: RoutingContext) -> RoutingDecis
170170
else "normal"
171171
),
172172
)
173-
if (
174-
self._is_highest_accuracy_mode(in_msg_meta)
175-
or in_msg_meta.trace_item_type not in _ITEM_TYPE_TO_OUTCOME
173+
if self._is_highest_accuracy_mode(in_msg_meta) or (
174+
# unspecified item type will be assumed as spans when querying
175+
# for GetTraces, there is no type specified so we assume spans because
176+
# that is necessary for traces anyways
177+
# if the type is specified and we don't know its outcome, route to Tier_1
178+
in_msg_meta.trace_item_type != TraceItemType.TRACE_ITEM_TYPE_UNSPECIFIED
179+
and in_msg_meta.trace_item_type not in _ITEM_TYPE_TO_OUTCOME
176180
):
177-
if span:
178-
span.set_data("tier", routing_decision.tier.name)
179181
return routing_decision
180182
# if we're querying a short enough timeframe, don't bother estimating, route to tier 1 and call it a day
181183
start_ts = in_msg_meta.start_timestamp.seconds

tests/web/rpc/v1/routing_strategies/test_outcomes_based.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,26 @@ def test_outcomes_based_routing_highest_accuracy_mode(store_outcomes_data: Any)
158158
assert routing_decision.tier == Tier.TIER_1
159159
assert routing_decision.clickhouse_settings == {}
160160
assert routing_decision.can_run
161+
162+
163+
@pytest.mark.clickhouse_db
164+
@pytest.mark.redis_db
165+
def test_outcomes_based_routing_defaults_to_spans_for_unspecified_item_type(
166+
store_outcomes_data: Any,
167+
) -> None:
168+
strategy = OutcomesBasedRoutingStrategy()
169+
170+
request = TraceItemTableRequest(meta=_get_request_meta())
171+
request.meta.trace_item_type = TraceItemType.TRACE_ITEM_TYPE_UNSPECIFIED
172+
state.set_config(
173+
"OutcomesBasedRoutingStrategy.max_items_before_downsampling", 50_000
174+
)
175+
routing_decision = strategy.get_routing_decision(
176+
RoutingContext(
177+
in_msg=request,
178+
timer=Timer("test"),
179+
)
180+
)
181+
assert routing_decision.tier == Tier.TIER_512
182+
assert routing_decision.clickhouse_settings == {}
183+
assert routing_decision.can_run

0 commit comments

Comments
 (0)