@@ -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
0 commit comments