-
-
Notifications
You must be signed in to change notification settings - Fork 60
ref(cbrs): integrate resource identifier and policy type into AllocationPolicy #7375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cef6448 to
920e872
Compare
920e872 to
36509d4
Compare
|
|
||
| def to_dict(self) -> PolicyData: | ||
| base_data = super().to_dict() | ||
| return PolicyData(**base_data, query_type=self.query_type.value) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without # type: ignore, it says Returning Any from function declared to return "PolicyData". This is because mypy can't guarantee that **base_data will satisfy all PolicyData requirements
Alternatively, I can just do
base_data = super().to_dict()
return PolicyData(
configurable_component_namespace=base_data["configurable_component_namespace"],
configurable_component_config_key=base_data["configurable_component_config_key"],
resource_identifier=base_data["resource_identifier"],
configurations=base_data["configurations"],
optional_config_definitions=base_data["optional_config_definitions"],
query_type=self.query_type.value,
)
3ee6f42 to
fdfde20
Compare
❌ 1 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
fdfde20 to
d1f1ec2
Compare
|
|
||
| class ConfigurableComponentData(TypedDict): | ||
| configurable_component_namespace: str | ||
| configurable_component_config_key: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know at one point we thought that we should set component_name to the class name ie "BytesScannedWindowAllocationPolicy", so we wanted to "flip" component_name and config_key, but RegisteredClass has config_key representing the name of the class so I'd rather be consistent
d1f1ec2 to
bc89713
Compare
| quota_info["quota_used"] = quota_allowance.quota_used | ||
| quota_info["quota_unit"] = quota_allowance.quota_unit | ||
| quota_info["suggestion"] = quota_allowance.suggestion | ||
| quota_info["storage_key"] = str(quota_and_policy.policy.storage_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in person, there was no vision between when using str(storage_key) (ie StorageKey.ERRORS) vs storage_key.value (ie errors), so I made everything use storage_key.value
If I don't do this, then ResourceIdentifier would have to keep track of the type of the underlying resource, because if the resource is StorageKey, then we'll want to use StoragaeKey's __repr__ method.
ResourceIdentifier should just take a string and when you pass in the storage key, convert to a string
f59dd2a to
343cd6d
Compare
| ) | ||
| # make sure we always know which storage key we rejected a query from | ||
| allowance.explanation["storage_key"] = str(self._storage_key) | ||
| allowance.explanation["storage_key"] = self._resource_identifier.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could change the key to be "resource_identifier" instead of "storage_key" but I find it'd be more confusing to have "resource_identifier" in querylog/payloads but then "storage_key" in DD tags (changing the latter, I assume, would break a bunch of DD metrics and I'd rather move the project along...)
| @property | ||
| def resource_identifier(self) -> ResourceIdentifier: | ||
| return ResourceIdentifier(self._storage_key) | ||
| def query_type(self) -> QueryType: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I debated having query_type be an argument to pass into the constructor, but AFAIK the only delete policy that exists is DeleteConcurrentRateLimitAllocationPolicy so this is the simplest way to change this
volokluev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approved with one question
| @classmethod | ||
| def config_key(cls) -> str: | ||
| return cls.__name__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you said that RegisteredClass also has a config_key method but it represents a different thing. Maybe this function should be called something else that's more decriptive?
https://linear.app/getsentry/issue/EAP-77/build-configuration-apis-for-routing-strategy This PR builds the necessary APIs and endpoints in Snuba Admin to retrieve configure routing strategies. This won't introduce any visual changes yet since it just establishes the endpoints DO NOT MERGE UNTIL: #7379, #7375 --------- Co-authored-by: Rachel Chen <rachelchen@PL6VFX9HP4.local> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Allocation policies should be aware of whether they are a "select" policy or a "delete" policy, so that allocation policy payloads can be constructed from the object itself.
This PR also integrates resource identifiers into allocation policies and because allocation policies are no longer goverened by only storage keys, we get rid of the
storage_keyproperty