Skip to content

Commit 520adfa

Browse files
Rachel ChenRachel Chen
authored andcommitted
got rid of print statements, add new next
1 parent d0d12c2 commit 520adfa

File tree

8 files changed

+20
-76
lines changed

8 files changed

+20
-76
lines changed

.vscode/settings.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@
6666
"python.testing.pytestEnabled": true,
6767
"python.testing.pytestArgs": ["tests"],
6868
"python.analysis.autoImportCompletions": true,
69-
"mypy-type-checker.args": [
70-
"--strict"
71-
],
72-
"cursorpyright.analysis.autoImportCompletions": true
69+
"mypy-type-checker.args": ["--strict"]
7370

7471
}

snuba/admin/notifications/slack/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def build_blocks(
3333
def build_allocation_policy_changed_text(
3434
data: Any, action: AuditLogAction
3535
) -> Optional[str]:
36-
# rachelhandlethis
3736
base = f"*Storage {data['storage']} Allocation Policy Changed:*"
3837

3938
if action == AuditLogAction.ALLOCATION_POLICY_DELETE:

snuba/admin/static/api_client.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,15 @@ function Client(): Client {
518518
let body: string;
519519
let url: string;
520520

521-
if (configurable_component.type === "allocation_policy") {
522-
body = JSON.stringify({ storage: entity.name, policy: configurable_component.name, key, params })
523-
url = baseUrl + "allocation_policy_config";
524-
} else {
521+
if (configurable_component.type === "routing_strategy") {
525522
body = JSON.stringify({ strategy: configurable_component.name, key, params });
526523
url = baseUrl + "routing_strategy_config";
524+
} else if (entity.type === "strategy" && configurable_component.type === "allocation_policy") {
525+
body = JSON.stringify({ strategy: entity.name, policy: configurable_component.name, key, params })
526+
url = baseUrl + "allocation_policy_config_for_strategy";
527+
} else {
528+
body = JSON.stringify({ storage: entity.name, policy: configurable_component.name, key, params })
529+
url = baseUrl + "allocation_policy_config_for_storage";
527530
}
528531

529532
return fetch(url, {

snuba/admin/views.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,6 @@ def configs() -> Response:
721721
assert key != "", "Key cannot be empty string"
722722

723723
except (KeyError, AssertionError) as exc:
724-
print("11111")
725724
return Response(
726725
json.dumps({"error": f"Invalid config: {str(exc)}"}),
727726
400,
@@ -845,7 +844,6 @@ def config(config_key: str) -> Response:
845844
state.set_config_description(config_key, new_desc, user=user)
846845

847846
except (KeyError, AssertionError) as exc:
848-
print("2222222")
849847
return Response(
850848
json.dumps({"error": f"Invalid config: {str(exc)}"}),
851849
400,
@@ -1045,7 +1043,6 @@ def get_routing_strategy_configs(strategy_name: str) -> Response:
10451043
cast(RoutingStrategyConfig, config).to_config_dict()
10461044
for config in configs.values()
10471045
]
1048-
print("isithereRACHELITSHERE", serialized_configs)
10491046
return Response(
10501047
json.dumps(serialized_configs), 200, {"Content-Type": "application/json"}
10511048
)
@@ -1055,32 +1052,25 @@ def get_routing_strategy_configs(strategy_name: str) -> Response:
10551052
@check_tool_perms(tools=[AdminTools.CAPACITY_BASED_ROUTING_SYSTEM])
10561053
def set_routing_strategy_config() -> Response:
10571054
data = json.loads(request.data)
1058-
print("datafsdfsdf", data)
10591055
user = request.headers.get(USER_HEADER_KEY)
10601056

10611057
try:
1062-
print("datafsdfsdf", data, data["strategy"])
10631058
strategy, key = (data["strategy"], data["key"])
10641059
params = data.get("params", {})
1065-
print("params", params)
10661060

10671061
assert isinstance(strategy, str), "Invalid strategy"
10681062
assert isinstance(key, str), "Invalid key"
1069-
print("paramsssss", params)
10701063
assert isinstance(params, dict), "Invalid params"
10711064
assert key != "", "Key cannot be empty string"
10721065

10731066
strategies = list(BaseRoutingStrategy.all_names())
1074-
print("strategies", strategies)
10751067
strategy = next(
10761068
(s for s in strategies if s == strategy),
10771069
None,
10781070
)
1079-
print("strategyyyy", strategy)
10801071
assert strategy is not None, "Strategy not found"
10811072

10821073
except (KeyError, AssertionError) as exc:
1083-
print("333333")
10841074
return Response(
10851075
json.dumps({"error": f"Invalid config: {str(exc)}"}),
10861076
400,
@@ -1100,7 +1090,6 @@ def set_allocation_policy_config_for_strategy() -> Response:
11001090

11011091
try:
11021092
strategy, key, policy_name = (data["strategy"], data["key"], data["policy"])
1103-
print("dkfjlskjflks", data)
11041093

11051094
params = data.get("params", {})
11061095

snuba/query/allocation_policies/__init__.py

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -325,21 +325,11 @@ class AllocationPolicy(ConfigurableComponent, ABC, metaclass=RegisteredClass):
325325
* Every allocation policy takes a `storage_key` in its init. The storage_key is like a pseudo-tenant. In different
326326
environments, storages may be co-located on the same cluster. To facilitate resource sharing, every allocation policy
327327
knows which storage_key it is serving. This is used to create unique keys for saving the config values.
328-
See `__build_runtime_config_key()` for more info.
328+
See `_build_runtime_config_key()` for more info.
329329
* Reiterating that you should no longer use `snuba.state.{get,set}_config()` for runtime configs for a specific Policy. Refer to the Configurations
330330
section of this docstring for more info.
331331
"""
332332

333-
# # This component builds redis strings that are delimited by dots, commas, colons
334-
# # in order to allow those characters to exist in config we replace them with their
335-
# # counterparts on write/read. It may be better to just replace our serialization with JSON
336-
# # instead of what we're doing but this is where we're at rn 1/10/24
337-
# __KEY_DELIMITERS_TO_ESCAPE_SEQUENCES = {
338-
# ".": "__dot_literal__",
339-
# ",": "__comma_literal__",
340-
# ":": "__colon_literal__",
341-
# }
342-
343333
def __init__(
344334
self,
345335
storage_key: StorageKey,
@@ -494,7 +484,7 @@ def get_config_value(
494484
else self.get_configurations()[config_key]
495485
)
496486
return get_runtime_config(
497-
key=self.__build_runtime_config_key(config_key, params),
487+
key=self._build_runtime_config_key(config_key, params),
498488
default=config_definition.default,
499489
config_key=CAPMAN_HASH,
500490
)
@@ -511,7 +501,7 @@ def set_config_value(
511501
# ensure correct type is stored
512502
value = config_definition.value_type(value)
513503
set_runtime_config(
514-
key=self.__build_runtime_config_key(config_key, params),
504+
key=self._build_runtime_config_key(config_key, params),
515505
value=value,
516506
user=user,
517507
force=True,
@@ -554,22 +544,6 @@ def get_current_configs(self) -> list[dict[str, Any]]:
554544

555545
return detailed_configs
556546

557-
def __build_runtime_config_key(self, config: str, params: dict[str, Any]) -> str:
558-
"""
559-
Builds a unique key to be used in the actual datastore containing these configs.
560-
561-
Example return values:
562-
- `"mystorage.MyAllocationPolicy.my_config"` # no params
563-
- `"mystorage.MyAllocationPolicy.my_config.a:1,b:2"` # sorted params
564-
"""
565-
parameters = "."
566-
for param in sorted(list(params.keys())):
567-
param_sanitized = self.__escape_delimiter_chars(param)
568-
value_sanitized = self.__escape_delimiter_chars(params[param])
569-
parameters += f"{param_sanitized}:{value_sanitized},"
570-
parameters = parameters[:-1]
571-
return f"{self.runtime_config_prefix}.{config}{parameters}"
572-
573547
def __deserialize_runtime_config_key(self, key: str) -> tuple[str, dict[str, Any]]:
574548
"""
575549
Given a raw runtime config key, deconstructs it into it's AllocationPolicy config
@@ -600,25 +574,11 @@ def __deserialize_runtime_config_key(self, key: str) -> tuple[str, dict[str, Any
600574

601575
return config_key, params_dict
602576

603-
# def __escape_delimiter_chars(self, key: str) -> str:
604-
# if not isinstance(key, str):
605-
# return key
606-
# for (
607-
# delimiter_char,
608-
# escape_sequence,
609-
# ) in self.__KEY_DELIMITERS_TO_ESCAPE_SEQUENCES.items():
610-
# if escape_sequence in str(key):
611-
# raise InvalidConfig(
612-
# f"{escape_sequence} is not a valid string for a policy config"
613-
# )
614-
# key = key.replace(delimiter_char, escape_sequence)
615-
# return key
616-
617577
def __unescape_delimiter_chars(self, key: str) -> str:
618578
for (
619579
delimiter_char,
620580
escape_sequence,
621-
) in self.__KEY_DELIMITERS_TO_ESCAPE_SEQUENCES.items():
581+
) in self._KEY_DELIMITERS_TO_ESCAPE_SEQUENCES.items():
622582
key = key.replace(escape_sequence, delimiter_char)
623583
return key
624584

@@ -732,9 +692,6 @@ def storage_key(self) -> StorageKey:
732692
def component_namespace(self) -> str:
733693
return "allocation_policy"
734694

735-
# def get_configurations(self) -> list[Configuration]:
736-
# return cast(list[Configuration], self.config_definitions().values())
737-
738695

739696
class PassthroughPolicy(AllocationPolicy):
740697
def _additional_config_definitions(self) -> list[AllocationPolicyConfig]:

snuba/query/allocation_policies/cross_org.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from snuba.datasets.storages.storage_key import StorageKey
77
from snuba.query.allocation_policies import (
88
AllocationPolicyConfig,
9-
InvalidConfig,
109
QueryResultOrError,
1110
QuotaAllowance,
1211
)
1312
from snuba.query.allocation_policies.concurrent_rate_limit import (
1413
BaseConcurrentRateLimitAllocationPolicy,
1514
)
15+
from snuba.query.configuration import InvalidConfig
1616
from snuba.redis import RedisClientKey, get_redis_client
1717
from snuba.state.rate_limit import RateLimitParameters
1818
from snuba.utils.serializable_exception import JsonSerializable

snuba/query/configuration.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ConfigurableComponent:
5757
# in order to allow those characters to exist in config we replace them with their
5858
# counterparts on write/read. It may be better to just replace our serialization with JSON
5959
# instead of what we're doing but this is where we're at rn 1/10/24
60-
__KEY_DELIMITERS_TO_ESCAPE_SEQUENCES = {
60+
_KEY_DELIMITERS_TO_ESCAPE_SEQUENCES = {
6161
".": "__dot_literal__",
6262
",": "__comma_literal__",
6363
":": "__colon_literal__",
@@ -169,21 +169,21 @@ def _validate_config_params(
169169

170170
return config
171171

172-
def __escape_delimiter_chars(self, key: str) -> str:
172+
def _escape_delimiter_chars(self, key: str) -> str:
173173
if not isinstance(key, str):
174174
return key
175175
for (
176176
delimiter_char,
177177
escape_sequence,
178-
) in self.__KEY_DELIMITERS_TO_ESCAPE_SEQUENCES.items():
178+
) in self._KEY_DELIMITERS_TO_ESCAPE_SEQUENCES.items():
179179
if escape_sequence in str(key):
180180
raise InvalidConfig(
181181
f"{escape_sequence} is not a valid string for a config"
182182
)
183183
key = key.replace(delimiter_char, escape_sequence)
184184
return key
185185

186-
def __build_runtime_config_key(self, config: str, params: dict[str, Any]) -> str:
186+
def _build_runtime_config_key(self, config: str, params: dict[str, Any]) -> str:
187187
"""
188188
Builds a unique key to be used in the actual datastore containing these configs.
189189
@@ -193,8 +193,8 @@ def __build_runtime_config_key(self, config: str, params: dict[str, Any]) -> str
193193
"""
194194
parameters = "."
195195
for param in sorted(list(params.keys())):
196-
param_sanitized = self.__escape_delimiter_chars(param)
197-
value_sanitized = self.__escape_delimiter_chars(params[param])
196+
param_sanitized = self._escape_delimiter_chars(param)
197+
value_sanitized = self._escape_delimiter_chars(params[param])
198198
parameters += f"{param_sanitized}:{value_sanitized},"
199199
parameters = parameters[:-1]
200200
return f"{self.runtime_config_prefix}.{config}{parameters}"
@@ -212,7 +212,7 @@ def delete_config_value(
212212
"""
213213
self._validate_config_params(config_key, params)
214214
delete_runtime_config(
215-
key=self.__build_runtime_config_key(config_key, params),
215+
key=self._build_runtime_config_key(config_key, params),
216216
user=user,
217217
config_key=config_key,
218218
)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ def _is_highest_accuracy_mode(self, routing_context: RoutingContext) -> bool:
217217
def get_delete_allocation_policies(self) -> list[AllocationPolicy]:
218218
return []
219219

220-
# @classmethod
221220
def get_allocation_policies(cls) -> list[AllocationPolicy]:
222221
return [
223222
ConcurrentRateLimitAllocationPolicy(

0 commit comments

Comments
 (0)