Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
MetricsBackendType = Callable[[str, int | float, dict[str, str] | None, str | None], None]
RoutedRequestType = TimeSeriesRequest | TraceItemTableRequest
ClickhouseQuerySettings = dict[str, Any]
_TIER_BY_CONFIG_VALUE = {tier.value: tier for tier in Tier if tier != Tier.TIER_NO_TIER}


class _OrgOverridableSetting(NamedTuple):
Expand Down Expand Up @@ -323,16 +324,16 @@ def _capture_routing_failure(
scope.fingerprint = [fingerprint_key, exception_name]
sentry_sdk.capture_exception(error)

def _get_default_routing_decision_tier(self) -> Tier:
tier_int = get_option("default_tier", 1)
def _get_initial_tier(self, routing_context: RoutingContext) -> Tier:
tier = _TIER_BY_CONFIG_VALUE.get(get_option("default_tier", 1), Tier.TIER_1)

if tier_int == 512:
return Tier.TIER_512
if tier_int == 64:
return Tier.TIER_64
if tier_int == 8:
return Tier.TIER_8
return Tier.TIER_1
# LOW_PRIORITY routes like NORMAL but is never allowed to read TIER_1.
if (
extract_message_meta(routing_context.in_msg).downsampled_storage_config.mode
== DownsampledStorageConfig.MODE_LOW_PRIORITY
):
tier = max(tier, Tier.TIER_8)
return tier

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low priority flagged as routing mistake

Low Severity

MODE_LOW_PRIORITY now starts at TIER_8 by design, but _emit_routing_mistake still treats any non-TIER_1 query that finishes under the sampled-too-low threshold as a routing_mistake. Fast low-priority queries will emit false sampled_too_low metrics.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 406c7ef. Configure here.


def additional_config_definitions(self) -> list[Configuration]:
return self._overridden_additional_config_definitions
Expand All @@ -358,12 +359,10 @@ def create_minimal_instance(cls, resource_identifier: str) -> ConfigurableCompon
)

def _is_highest_accuracy_mode(self, in_msg_meta: RequestMeta) -> bool:
if in_msg_meta.HasField("downsampled_storage_config"):
return bool(
in_msg_meta.downsampled_storage_config.mode
== DownsampledStorageConfig.MODE_HIGHEST_ACCURACY
)
return False
return bool(
in_msg_meta.downsampled_storage_config.mode
== DownsampledStorageConfig.MODE_HIGHEST_ACCURACY
)

def get_allocation_policies(
self, tenant_ids: dict[str, str | int] | None = None
Expand Down Expand Up @@ -491,7 +490,7 @@ def get_routing_decision(self, routing_context: RoutingContext) -> RoutingDecisi
OutcomesBasedRoutingStrategy,
)

default_tier = self._get_default_routing_decision_tier()
initial_tier = self._get_initial_tier(routing_context)

with traces.start_span(name="decide_tier", attributes={SENTRY_OP: "decide_tier"}) as span:
try:
Expand All @@ -512,7 +511,7 @@ def get_routing_decision(self, routing_context: RoutingContext) -> RoutingDecisi
routing_decision = RoutingDecision(
routing_context=routing_context,
strategy=self,
tier=default_tier,
tier=initial_tier,
clickhouse_settings=combined_allocation_policies_recommendations["settings"],
can_run=combined_allocation_policies_recommendations["can_run"],
is_throttled=combined_allocation_policies_recommendations["is_throttled"],
Expand Down Expand Up @@ -553,7 +552,7 @@ def get_routing_decision(self, routing_context: RoutingContext) -> RoutingDecisi
routing_decision = RoutingDecision(
routing_context=routing_context,
strategy=OutcomesBasedRoutingStrategy(),
tier=default_tier,
tier=initial_tier,
can_run=True,
)
span.set_attribute("decided_tier", routing_decision.tier.name)
Expand Down
22 changes: 22 additions & 0 deletions tests/web/rpc/v1/routing_strategies/test_outcomes_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,28 @@ def test_outcomes_based_routing_highest_accuracy_mode(store_outcomes_fixture: An
assert routing_decision.can_run


@pytest.mark.eap
@pytest.mark.redis_db
def test_outcomes_based_routing_low_priority_mode_starts_at_tier_8(
store_outcomes_fixture: Any,
) -> None:
strategy = OutcomesBasedRoutingStrategy()

request = TraceItemTableRequest(meta=_get_request_meta())
request.meta.downsampled_storage_config.mode = DownsampledStorageConfig.MODE_LOW_PRIORITY
routing_decision = strategy.get_routing_decision(
RoutingContext(
in_msg=request,
timer=Timer("test"),
query_id=uuid.uuid4().hex,
)
)

assert routing_decision.tier == Tier.TIER_8
assert routing_decision.clickhouse_settings == {"max_threads": 10}
assert routing_decision.can_run


@pytest.mark.eap
@pytest.mark.redis_db
def test_outcomes_based_routing_defaults_to_tier1_for_unspecified_item_type(
Expand Down
Loading