Skip to content

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

Merged
merged 5 commits into from
May 29, 2025

Conversation

saponifi3d
Copy link
Contributor

Description

  • Merge the Grouping handler back into the stateful handler, as I was progressing in refactoring it away, i found myself hardcoding 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)
  • Update the Metric Alert detector to use the new handler.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label May 28, 2025
@@ -10,13 +10,6 @@ class QuerySubscriptionUpdate(TypedDict):
timestamp: datetime


class MetricDetectorUpdate(TypedDict):
Copy link
Contributor Author

@saponifi3d saponifi3d May 28, 2025

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)

Comment on lines +386 to +389
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)}
Copy link
Contributor Author

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...

Copy link
Member

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

@saponifi3d saponifi3d force-pushed the jcallender/aci/stateful-cleanup-2 branch from 129cb23 to 6098396 Compare May 29, 2025 00:06
@saponifi3d saponifi3d marked this pull request as ready for review May 29, 2025 00:11
@saponifi3d saponifi3d requested review from a team as code owners May 29, 2025 00:11
@saponifi3d saponifi3d changed the title ref(workflow_engine): Refactor StatefulDetectorHandler: The Re-merge-en-ing ref(workflow_engine): Refactor StatefulDetectorHandler + StatefulGroupingDetectorHandler May 29, 2025
Copy link

codecov bot commented May 29, 2025

Codecov Report

Attention: Patch coverage is 97.91667% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ntry/workflow_engine/handlers/detector/stateful.py 98.38% 1 Missing ⚠️
...try/workflow_engine/handlers/detector/test_base.py 75.00% 1 Missing ⚠️
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:
Copy link
Contributor Author

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 😭)

Copy link
Member

@evanpurkhiser evanpurkhiser left a 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!

@saponifi3d saponifi3d merged commit adc9450 into master May 29, 2025
61 checks passed
@saponifi3d saponifi3d deleted the jcallender/aci/stateful-cleanup-2 branch May 29, 2025 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants