Skip to content

Commit 0282a73

Browse files
Rachel ChenRachel Chen
authored andcommitted
comments
1 parent 08e009d commit 0282a73

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

snuba/query/allocation_policies/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from typing import List
2+
13
from snuba.query.allocation_policies import QuotaAllowance
24

35

4-
def get_max_bytes_to_read(quota_allowances: dict[str, QuotaAllowance]) -> int:
6+
def get_max_bytes_to_read(quota_allowances: List[QuotaAllowance]) -> int:
57
max_bytes_to_read = min(
6-
[qa.max_bytes_to_read for qa in quota_allowances.values()],
8+
[qa.max_bytes_to_read for qa in quota_allowances],
79
key=lambda mb: float("inf") if mb == 0 else mb,
810
)
911
if max_bytes_to_read != 0:

snuba/web/db_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ def _apply_allocation_policies_quota(
860860
summary: dict[str, Any] = {}
861861
summary["threads_used"] = min_threads_across_policies
862862

863-
max_bytes_to_read = get_max_bytes_to_read(quota_allowances)
863+
max_bytes_to_read = get_max_bytes_to_read(list(quota_allowances.values()))
864864
if max_bytes_to_read != 0:
865865
query_settings.push_clickhouse_setting("max_bytes_to_read", max_bytes_to_read)
866866
summary["max_bytes_to_read"] = max_bytes_to_read

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

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Any,
88
Callable,
99
Dict,
10+
List,
1011
Optional,
1112
TypeAlias,
1213
TypedDict,
@@ -50,7 +51,6 @@
5051
from snuba.query.allocation_policies.utils import get_max_bytes_to_read
5152
from snuba.query.query_settings import HTTPQuerySettings
5253
from snuba.state import record_query
53-
from snuba.state.quota import ResourceQuota
5454
from snuba.utils.metrics.timer import Timer
5555
from snuba.utils.metrics.wrapper import MetricsWrapper
5656
from snuba.utils.registered_class import import_submodules_in_directory
@@ -322,10 +322,7 @@ def merge_clickhouse_settings(
322322
"""
323323

324324
for k, v in routing_decision.clickhouse_settings.items():
325-
if k == "max_threads":
326-
query_settings.set_resource_quota(ResourceQuota(max_threads=v))
327-
else:
328-
query_settings.push_clickhouse_setting(k, v)
325+
query_settings.push_clickhouse_setting(k, v)
329326

330327
def _record_value_in_span_and_DD(
331328
self,
@@ -351,30 +348,22 @@ def _update_routing_decision(
351348
raise NotImplementedError
352349

353350
def _get_combined_allocation_policies_recommendations(
354-
self,
355-
routing_context: RoutingContext,
351+
self, policy_recommendations: List[QuotaAllowance]
356352
) -> CombinedAllocationPoliciesRecommendations:
357-
# decides how to combine the recommendations from the allocation policies with the cluster load
353+
# decides how to combine the recommendations from the allocation policies
358354
settings = {}
359355

360-
max_bytes_to_read = get_max_bytes_to_read(
361-
routing_context.allocation_policies_recommendations
362-
)
356+
max_bytes_to_read = get_max_bytes_to_read(policy_recommendations)
363357
if max_bytes_to_read != 0:
364358
settings["max_bytes_to_read"] = max_bytes_to_read
365359

366360
settings["max_threads"] = min(
367-
[qa.max_threads for qa in routing_context.allocation_policies_recommendations.values()],
361+
[qa.max_threads for qa in policy_recommendations],
368362
)
369363

370364
return CombinedAllocationPoliciesRecommendations(
371-
can_run=all(
372-
qa.can_run for qa in routing_context.allocation_policies_recommendations.values()
373-
),
374-
is_throttled=any(
375-
qa.is_throttled
376-
for qa in routing_context.allocation_policies_recommendations.values()
377-
),
365+
can_run=all(qa.can_run for qa in policy_recommendations),
366+
is_throttled=any(qa.is_throttled for qa in policy_recommendations),
378367
settings=settings,
379368
)
380369

@@ -413,7 +402,9 @@ def get_routing_decision(self, routing_context: RoutingContext) -> RoutingDecisi
413402
self._get_recommendations_from_allocation_policies(routing_context)
414403
)
415404
combined_allocation_policies_recommendations = (
416-
self._get_combined_allocation_policies_recommendations(routing_context)
405+
self._get_combined_allocation_policies_recommendations(
406+
list(routing_context.allocation_policies_recommendations.values())
407+
)
417408
)
418409

419410
routing_decision = RoutingDecision(

0 commit comments

Comments
 (0)