Skip to content

Commit e8fbb8b

Browse files
Rachel ChenRachel Chen
authored andcommitted
class_name
1 parent 8a60c45 commit e8fbb8b

File tree

6 files changed

+33
-41
lines changed

6 files changed

+33
-41
lines changed

snuba/admin/capacity_management_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def convert(policy_data: PolicyData) -> dict[str, Any]:
77
"We need to convert the policy data to the format that the frontend expects. This will be removed once we update the frontend"
88
return {
9-
"policy_name": policy_data["configurable_component_config_key"],
9+
"policy_name": policy_data["configurable_component_class_name"],
1010
"configs": policy_data["configurations"],
1111
"optional_config_definitions": policy_data["optional_config_definitions"],
1212
"query_type": policy_data["query_type"],

snuba/admin/notifications/slack/utils.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
)
1313

1414

15-
def build_blocks(
16-
data: Any, action: AuditLogAction, timestamp: str, user: str
17-
) -> List[Any]:
15+
def build_blocks(data: Any, action: AuditLogAction, timestamp: str, user: str) -> List[Any]:
1816
if action in RUNTIME_CONFIG_ACTIONS:
1917
text = build_runtime_config_text(data, action)
2018
elif action in MIGRATION_ACTIONS:
@@ -32,17 +30,15 @@ def build_blocks(
3230
return [section, build_context(user, timestamp, action)]
3331

3432

35-
def build_configurable_component_changed_text(
36-
data: Any, action: AuditLogAction
37-
) -> Optional[str]:
33+
def build_configurable_component_changed_text(data: Any, action: AuditLogAction) -> Optional[str]:
3834

39-
base = f"*Resource {data['resource_identifier']} Configurable Component {data['configurable_component_config_key']} Changed:*"
35+
base = f"*Resource {data['resource_identifier']} Configurable Component {data['configurable_component_class_name']} Changed:*"
4036

4137
if action == AuditLogAction.CONFIGURABLE_COMPONENT_DELETE:
42-
removed = f"~```'{data['configurable_component_config_key']}.{data['key']}({data.get('params', {})})'```~"
38+
removed = f"~```'{data['configurable_component_class_name']}.{data['key']}({data.get('params', {})})'```~"
4339
return f"{base} :put_litter_in_its_place:\n\n{removed}"
4440
elif action == AuditLogAction.CONFIGURABLE_COMPONENT_UPDATE:
45-
updated = f"```'{data['configurable_component_config_key']}.{data['key']}({data.get('params', {})})' = '{data['value']}'```"
41+
updated = f"```'{data['configurable_component_class_name']}.{data['key']}({data.get('params', {})})' = '{data['value']}'```"
4642
return f"{base} :up: :date:\n\n{updated}"
4743
else:
4844
# todo: raise error, cause slack won't accept this
@@ -85,9 +81,7 @@ def build_migration_run_text(data: Any, action: AuditLogAction) -> Optional[str]
8581
else:
8682
return None
8783

88-
text = (
89-
f"*Migration:* \n\n{action_text} (force={data['force']}, fake={data['fake']})"
90-
)
84+
text = f"*Migration:* \n\n{action_text} (force={data['force']}, fake={data['fake']})"
9185

9286
if action in [
9387
AuditLogAction.REVERSED_MIGRATION_FAILED,

snuba/admin/views.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -993,15 +993,15 @@ def set_configuration() -> Response:
993993

994994
try:
995995
configurable_component_namespace = data["configurable_component_namespace"]
996-
configurable_component_config_key = data["configurable_component_config_key"]
996+
configurable_component_class_name = data["configurable_component_class_name"]
997997
resource_name = data["resource_name"]
998998
assert isinstance(
999-
configurable_component_config_key, str
1000-
), f"Invalid configurable_component_config_key: {configurable_component_config_key}"
999+
configurable_component_class_name, str
1000+
), f"Invalid configurable_component_class_name: {configurable_component_class_name}"
10011001
assert isinstance(resource_name, str), f"Invalid resource_name {resource_name}"
10021002
configurable_component = (
10031003
ConfigurableComponent.get_component_class(configurable_component_namespace)
1004-
.get_from_name(configurable_component_config_key)
1004+
.get_from_name(configurable_component_class_name)
10051005
.create_minimal_instance(resource_name)
10061006
)
10071007

@@ -1025,7 +1025,7 @@ def set_configuration() -> Response:
10251025
AuditLogAction.CONFIGURABLE_COMPONENT_DELETE,
10261026
{
10271027
"resource_identifier": resource_name,
1028-
"configurable_component_config_key": configurable_component.config_key(),
1028+
"configurable_component_class_name": configurable_component.class_name(),
10291029
"key": key,
10301030
},
10311031
notify=True,
@@ -1043,7 +1043,7 @@ def set_configuration() -> Response:
10431043
AuditLogAction.CONFIGURABLE_COMPONENT_UPDATE,
10441044
{
10451045
"resource_identifier": resource_name,
1046-
"configurable_component_config_key": configurable_component.config_key(),
1046+
"configurable_component_class_name": configurable_component.class_name(),
10471047
"key": key,
10481048
"value": value,
10491049
"params": str(params),

snuba/configs/configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class InvalidConfig(Exception):
2121

2222
class ConfigurableComponentData(TypedDict):
2323
configurable_component_namespace: str
24-
configurable_component_config_key: str
24+
configurable_component_class_name: str
2525
resource_identifier: str
2626
configurations: list[dict[str, Any]]
2727
optional_config_definitions: list[dict[str, Any]]
@@ -454,7 +454,7 @@ def class_name(cls) -> str:
454454
def to_dict(self) -> ConfigurableComponentData:
455455
return ConfigurableComponentData(
456456
configurable_component_namespace=self.component_namespace(),
457-
configurable_component_config_key=self.class_name(),
457+
configurable_component_class_name=self.class_name(),
458458
resource_identifier=self.resource_identifier.value,
459459
configurations=self.get_current_configs(),
460460
optional_config_definitions=self.get_optional_config_definitions_json(),

tests/admin/notifications/test_build_blocks.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
pytest.param(
1616
{
1717
"resource_identifier": "errors",
18-
"configurable_component_config_key": "BytesScannedWindowAllocationPolicy",
18+
"configurable_component_class_name": "BytesScannedWindowAllocationPolicy",
1919
"key": "org_limit_bytes_scanned_override",
2020
"value": "420",
2121
"params": "{'org_id': 1}",
@@ -27,7 +27,7 @@
2727
pytest.param(
2828
{
2929
"resource_identifier": "errors",
30-
"configurable_component_config_key": "BytesScannedWindowAllocationPolicy",
30+
"configurable_component_class_name": "BytesScannedWindowAllocationPolicy",
3131
"key": "org_limit_bytes_scanned_override",
3232
"params": "{'org_id': 1}",
3333
},
@@ -37,9 +37,7 @@
3737
),
3838
],
3939
)
40-
def test_build_blocks(
41-
data: dict[str, Any], action: AuditLogAction, expected: str
42-
) -> None:
40+
def test_build_blocks(data: dict[str, Any], action: AuditLogAction, expected: str) -> None:
4341

4442
res = build_blocks(
4543
data,

tests/admin/test_api.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def test_get_routing_strategy_configs(admin_api: FlaskClient) -> None:
492492
strategy_data = response.json
493493

494494
# Check strategy-level data
495-
assert strategy_data["configurable_component_config_key"] == "FakeRoutingStrategy"
495+
assert strategy_data["configurable_component_class_name"] == "FakeRoutingStrategy"
496496
assert len(strategy_data["configurations"]) == 2
497497
assert {
498498
"name": "some_default_config",
@@ -516,7 +516,7 @@ def test_get_routing_strategy_configs(admin_api: FlaskClient) -> None:
516516
assert len(strategy_data["policies_data"]) == 2
517517

518518
# First policy
519-
assert strategy_data["policies_data"][0]["configurable_component_config_key"] == "FakePolicy"
519+
assert strategy_data["policies_data"][0]["configurable_component_class_name"] == "FakePolicy"
520520
assert strategy_data["policies_data"][0]["query_type"] == "select"
521521
assert len(strategy_data["policies_data"][0]["configurations"]) == 4
522522
assert {
@@ -562,7 +562,7 @@ def test_get_routing_strategy_configs(admin_api: FlaskClient) -> None:
562562

563563
# Second policy
564564
assert (
565-
strategy_data["policies_data"][1]["configurable_component_config_key"] == "FakeDeletePolicy"
565+
strategy_data["policies_data"][1]["configurable_component_class_name"] == "FakeDeletePolicy"
566566
)
567567
assert strategy_data["policies_data"][1]["query_type"] == "delete"
568568
assert len(strategy_data["policies_data"][1]["configurations"]) == 4
@@ -721,7 +721,7 @@ def mock_record(user: Any, action: Any, data: Any, notify: Any) -> None:
721721
data=json.dumps(
722722
{
723723
"configurable_component_namespace": "AllocationPolicy",
724-
"configurable_component_config_key": "BytesScannedWindowAllocationPolicy",
724+
"configurable_component_class_name": "BytesScannedWindowAllocationPolicy",
725725
"resource_name": "errors",
726726
"key": "org_limit_bytes_scanned_override",
727727
"params": {"org_id": 1},
@@ -763,7 +763,7 @@ def mock_record(user: Any, action: Any, data: Any, notify: Any) -> None:
763763
data=json.dumps(
764764
{
765765
"configurable_component_namespace": "AllocationPolicy",
766-
"configurable_component_config_key": "BytesScannedWindowAllocationPolicy",
766+
"configurable_component_class_name": "BytesScannedWindowAllocationPolicy",
767767
"resource_name": "errors",
768768
"key": "org_limit_bytes_scanned_override",
769769
"params": {"org_id": 1},
@@ -811,7 +811,7 @@ def mock_record(user: Any, action: Any, data: Any, notify: Any) -> None:
811811
data=json.dumps(
812812
{
813813
"configurable_component_namespace": "BaseRoutingStrategy",
814-
"configurable_component_config_key": "FakeRoutingStrategy",
814+
"configurable_component_class_name": "FakeRoutingStrategy",
815815
"resource_name": "FakeRoutingStrategy",
816816
"key": "fake_strategy_config",
817817
"value": "75",
@@ -828,7 +828,7 @@ def mock_record(user: Any, action: Any, data: Any, notify: Any) -> None:
828828

829829
# Verify the config was set correctly
830830
strategy_data = response.json
831-
assert strategy_data["configurable_component_config_key"] == "FakeRoutingStrategy"
831+
assert strategy_data["configurable_component_class_name"] == "FakeRoutingStrategy"
832832
assert {
833833
"name": "fake_strategy_config",
834834
"type": "int",
@@ -844,7 +844,7 @@ def mock_record(user: Any, action: Any, data: Any, notify: Any) -> None:
844844
data=json.dumps(
845845
{
846846
"configurable_component_namespace": "BaseRoutingStrategy",
847-
"configurable_component_config_key": "FakeRoutingStrategy",
847+
"configurable_component_class_name": "FakeRoutingStrategy",
848848
"resource_name": "FakeRoutingStrategy",
849849
"key": "fake_strategy_config",
850850
}
@@ -859,7 +859,7 @@ def mock_record(user: Any, action: Any, data: Any, notify: Any) -> None:
859859

860860
# The config should be back to its default value
861861
strategy_data = response.json
862-
assert strategy_data["configurable_component_config_key"] == "FakeRoutingStrategy"
862+
assert strategy_data["configurable_component_class_name"] == "FakeRoutingStrategy"
863863
assert {
864864
"name": "fake_strategy_config",
865865
"type": "int",
@@ -898,7 +898,7 @@ def mock_get_from_name(strategy_name: str) -> Type[BaseRoutingStrategy]:
898898
data=json.dumps(
899899
{
900900
"configurable_component_namespace": "AllocationPolicy",
901-
"configurable_component_config_key": "FakePolicy",
901+
"configurable_component_class_name": "FakePolicy",
902902
"resource_name": "FakeRoutingStrategy",
903903
"key": "fake_optional_config",
904904
"params": {"org_id": 1},
@@ -916,16 +916,16 @@ def mock_get_from_name(strategy_name: str) -> Type[BaseRoutingStrategy]:
916916
assert response.json is not None
917917

918918
strategy_data = response.json
919-
assert strategy_data["configurable_component_config_key"] == "FakeRoutingStrategy"
919+
assert strategy_data["configurable_component_class_name"] == "FakeRoutingStrategy"
920920
assert len(strategy_data["policies_data"]) == 2
921921

922922
fake_policy = next(
923923
policy
924924
for policy in strategy_data["policies_data"]
925-
if policy["configurable_component_config_key"] == "FakePolicy"
925+
if policy["configurable_component_class_name"] == "FakePolicy"
926926
)
927927

928-
assert fake_policy["configurable_component_config_key"] == "FakePolicy"
928+
assert fake_policy["configurable_component_class_name"] == "FakePolicy"
929929
assert {
930930
"default": -1,
931931
"description": "",
@@ -941,7 +941,7 @@ def mock_get_from_name(strategy_name: str) -> Type[BaseRoutingStrategy]:
941941
data=json.dumps(
942942
{
943943
"configurable_component_namespace": "AllocationPolicy",
944-
"configurable_component_config_key": "FakePolicy",
944+
"configurable_component_class_name": "FakePolicy",
945945
"resource_name": "FakeRoutingStrategy",
946946
"key": "fake_optional_config",
947947
"params": {"org_id": 1},
@@ -959,7 +959,7 @@ def mock_get_from_name(strategy_name: str) -> Type[BaseRoutingStrategy]:
959959
fake_policy = next(
960960
policy
961961
for policy in strategy_data["policies_data"]
962-
if policy["configurable_component_config_key"] == "FakePolicy"
962+
if policy["configurable_component_class_name"] == "FakePolicy"
963963
)
964964

965965
# The config should be back to its default value

0 commit comments

Comments
 (0)