You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ref(cbrs): introduce RegisteredClass into ConfigurableComponent (#7379)
Retrieve configurable component by doing
## option 1
`ConfigurableComponent.get_component_class(namespace).get_from_name(class_name)`
ex)
`ConfigurableComponent.get_component_class("AllocationPolicy").get_from_name("BytesScannedWindowPolicy")`
## option 2
`AllocationPolicy.get_from_name(class_name)`
ex) `AllocationPolicy.get_from_name("BytesScannedWindowPolicy)`
Option 1 is used for the set configuration endpoint - the frontend code
will pass in the namespace and the class name, so use option 1 to get
the configurable component
Option 2 is already used in existing code so I'm going to preserve that
Note:
When you print out `ConfigurableComponent.all_names()`, you get
```
['AllocationPolicy.AllocationPolicy', 'AllocationPolicy.PassthroughPolicy', 'AllocationPolicy.BaseConcurrentRateLimitAllocationPolicy', 'AllocationPolicy.ConcurrentRateLimitAllocationPolicy', 'AllocationPolicy.DeleteConcurrentRateLimitAllocationPolicy', 'AllocationPolicy.ReferrerGuardRailPolicy', 'AllocationPolicy.CrossOrgQueryAllocationPolicy', 'AllocationPolicy.BytesScannedRejectingPolicy', 'AllocationPolicy.BytesScannedWindowAllocationPolicy', 'RoutingStrategy.BaseRoutingStrategy', 'RoutingStrategy.OutcomesBasedRoutingStrategy']
```
At one point I did think about doing
`ConfigurableComponent.get_from_name(namespace, class_name)`, similar to
[RPCEndpoint.get_from_name(name,
version)](https://github.com/getsentry/snuba/blob/master/snuba/web/rpc/__init__.py#L133-L137).
But I decided against it because
we either change existing `AllocationPolicy.get_from_name(blah)` to
`ConfigurableComponent.get_from_name("AllocationPolicy", "blah")`
throughout the code base, or within each subclass's `get_from_name`
method, we call `super().get_from_name(subclass's namespace, name)`, and
then we cast it to type subclass, and we make namespace an optional
param. Maybe this works, but I already coded up the existing approach
and I don't see a clear advantage here
---------
Co-authored-by: Rachel Chen <[email protected]>
Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
0 commit comments