Skip to content

feat(workflow_engine): Add in hook for producing occurrences from the stateful detector - #80168

Merged
wedamija merged 2 commits into
masterfrom
danf/we-occurrences-hook
Nov 5, 2024
Merged

wedamija merged 2 commits into
masterfrom
danf/we-occurrences-hook

Conversation

@wedamija

@wedamija wedamija commented Nov 2, 2024

Copy link
Copy Markdown
Member

This adds a hook that can be implemented to produce an occurrence specific to the detector that is subclassing the StatefulDetector.

Also change the signature of evaluate to return a dict keyed by groupkey instead of a list. This helps avoid the chance of duplicate results for the same group key.

@wedamija
wedamija requested review from a team and saponifi3d November 2, 2024 00:57
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 2, 2024
@wedamija
wedamija force-pushed the danf/we-return-status-changes branch from b3513f6 to f196c85 Compare November 2, 2024 00:59
@wedamija
wedamija requested a review from a team as a code owner November 2, 2024 00:59
@wedamija
wedamija force-pushed the danf/we-occurrences-hook branch from 461ad20 to 04aced8 Compare November 2, 2024 00:59
@codecov

codecov Bot commented Nov 2, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/workflow_engine/processors/detector.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #80168      +/-   ##
==========================================
- Coverage   78.09%   78.09%   -0.01%     
==========================================
  Files        7185     7185              
  Lines      317446   317448       +2     
  Branches    43748    43747       -1     
==========================================
- Hits       247904   247898       -6     
- Misses      63203    63204       +1     
- Partials     6339     6346       +7     

@saponifi3d saponifi3d left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

) -> list[DetectorEvaluationResult]:
# TODO: Implement
return []
class MetricAlertDetectorHandler(StatefulDetectorHandler[QuerySubscriptionUpdate]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dang, this reads really well. 💯

super().tearDown()
self.sm_comp_patcher.__exit__(None, None, None)

def create_detector_and_conditions(self, type: str | None = None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shuold type be an enum value instead of a string?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little tricky, and I thought maybe the flexibility is better since type on the model is a string. But we could rework it if it makes sense

return build_mock_occurrence_and_event(self, group_key, value, new_status)


class BaseDetectorHandlerTest(BaseGroupTypeTest):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 should we have a separate base test class for workflow engine that has methods to create conditions / detectors / workflows / data sources?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that might make sense, but let's move this logic out as we need it and have shared test data needs

@wedamija
wedamija force-pushed the danf/we-return-status-changes branch from f196c85 to 230aa8e Compare November 5, 2024 18:32
@wedamija
wedamija force-pushed the danf/we-occurrences-hook branch from 04aced8 to 8d6f5c3 Compare November 5, 2024 18:32
@wedamija
wedamija force-pushed the danf/we-return-status-changes branch from 230aa8e to 9d0bb76 Compare November 5, 2024 18:51
@wedamija
wedamija force-pushed the danf/we-occurrences-hook branch from 8d6f5c3 to 9ec1cf7 Compare November 5, 2024 18:51
@wedamija
wedamija force-pushed the danf/we-occurrences-hook branch from 9ec1cf7 to a87d92a Compare November 5, 2024 18:57
@wedamija
wedamija force-pushed the danf/we-return-status-changes branch from 551778e to 0f99ed3 Compare November 5, 2024 20:08
@wedamija
wedamija force-pushed the danf/we-occurrences-hook branch from a87d92a to a4ae39c Compare November 5, 2024 20:08
@wedamija
wedamija force-pushed the danf/we-return-status-changes branch from 0f99ed3 to 64effae Compare November 5, 2024 20:49
@wedamija
wedamija force-pushed the danf/we-occurrences-hook branch from a4ae39c to 05c3858 Compare November 5, 2024 20:49
@wedamija
wedamija force-pushed the danf/we-return-status-changes branch from 64effae to b87fe97 Compare November 5, 2024 21:34
@wedamija
wedamija force-pushed the danf/we-occurrences-hook branch from 05c3858 to 70af48f Compare November 5, 2024 21:34
Base automatically changed from danf/we-return-status-changes to master November 5, 2024 22:30
… stateful detector

This adds a hook that can be implemented to produce an occurrence specific to the detector that is subclassing the StatefulDetector.

Also change the signature of evaluate to return a dict keyed by groupkey instead of a list. This helps avoid the chance of duplicate results for the same group key.
@wedamija
wedamija enabled auto-merge (squash) November 5, 2024 22:45
@wedamija
wedamija merged commit de60b7f into master Nov 5, 2024
@wedamija
wedamija deleted the danf/we-occurrences-hook branch November 5, 2024 23:20
jan-auer added a commit that referenced this pull request Nov 6, 2024
* master: (67 commits)
  feat(dynamic-sampling): Sampling breakdown (#80304)
  feat(profiling): add organizations:continuous-profiling to the list of exposable features (#80236)
  chore(broadcasts): remove cta column from broadcast model (#80201)
  feat(dynamic-sampling): Use sample rates endpoint (#80235)
  feat(issues): Rearrange all events columns, sizes (#80296)
  fix(issues): All event table pagination counts (#80297)
  fix(issues): Preserve query parameters on all events close (#80295)
  feat(issues): Hide "comment" button until focused (#80283)
  fix(sentry-app): Adds better validation for invalid token request bodies (#80289)
  feat(workflow_engine): Add in hook for producing occurrences from the stateful detector (#80168)
  feat(issue summary) New structured issue summary design (#80273)
  feat(workflow_engine): Return status change messages when a stateful detector resolves (#80122)
  feat(insights): Add insights query date range footer hook (#80276)
  ref(crons): Switch to cronsim in sample data generator (#80278)
  feat(issue-details): Hide merged/similar issues for non-error issues (#80284)
  feat(issue summary) Update issue summary model (#80270)
  feat(crons): Add cronsim behind an option (#80271)
  fix(anomaly detection): add alerts analytics reqs to utils/analytics.tsx (#80281)
  feat(trace-explorer): Sort traces by timestamp in EAP (#80274)
  feat(workflow_engine): Implement basic evaluation in `DataCondition` (#80118)
  ...
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 21, 2024

This branch was successfully deployed

1 active deployment
Preview — 8422030e Deployed Nov 5, 2024 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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