-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
ref(workflow_engine): Refactor StatefulDetectorHandler + StatefulGroupingDetectorHandler #92457
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
@@ -10,13 +10,6 @@ class QuerySubscriptionUpdate(TypedDict): | |||
timestamp: datetime | |||
|
|||
|
|||
class MetricDetectorUpdate(TypedDict): |
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.
sorry i snuck this into the pr, i noticed it's redundant with QuerySubscriptionUpdate
and updated the use (it just ended up being a few lines)
if self._is_detector_group_value(data_values): | ||
group_data_values = cast(dict[DetectorGroupKey, DataPacketEvaluationType], data_values) | ||
else: | ||
group_data_values = {None: cast(DataPacketEvaluationType, data_values)} |
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.
is there a better way to handle this w/o using cast? i couldn't figure out anything...
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.
Yes I think you can inform the type system that your _is_detector_group_value
function is doing discrimination using a TypeGuard
129cb23
to
6098396
Compare
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## master #92457 +/- ##
===========================================
+ Coverage 45.71% 87.89% +42.17%
===========================================
Files 10216 10232 +16
Lines 585548 586279 +731
Branches 22785 22785
===========================================
+ Hits 267687 515299 +247612
+ Misses 317431 70550 -246881
Partials 430 430 |
event_data=event_data, | ||
) | ||
|
||
def _is_detector_group_value(self, value) -> bool: |
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.
is there another way i can tell if this is a DataPacketEvaluationType
or dict[DetectorGroupKey, DataPacketEvaluationType]
? (i can't use isinstance
on DataPacketEvaluationType
because it's generic 😭)
c5833ea
to
2a2614c
Compare
ccbca69
to
798fc67
Compare
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.
This is working well for uptime detectors!
Description
none
a lot for the shared helpers. So refactored this to merge them a bit more together, this will take away the difficulty for implementing a stateful detector handler, but not reduce all the complexity in the class (seems like a reasonable tradeoff for now)