Repository navigation
feat(workflow_engine): Support group-less action invocation - #131090
Conversation
c194918 to
ea1da2e
Compare
ea1da2e to
e42eca5
Compare
3ba2795 to
00a80c4
Compare
00a80c4 to
c8e9b88
Compare
|
|
||
|
|
||
| class IntegrationActionHandler(ActionHandler, ABC): | ||
| class IssueNotificationActionHandler(ActionHandler): |
There was a problem hiding this comment.
🤔 i think this breaks liskov substitution principle; (the L in SOLID) -- this base class couldn't replace the parent class, because it forces the the input types.
Is there something we could add to the ActionHandler to enforce for us? that way instead of using inheritance to do these definitions, everything is clearly outlines.
That could look something like:
class ActionHandler(Generic[T]):
def validate_data(data: T) -> None:It could also look something like:
class ActionHandler:
on_validation: []where on_validation is a list of methods to call to validate the data.
i personally prefer the latter; because it allows for more options per handler. here's kinda the way the latter might play out.
So instead of: class EmailActionHandler(IssueNotificationActionHandler): we can say;
class EmailActionHandler(ActionHandler):
on_validation: [ActionHandler.ISSUE_REQUIRED.validate],^ that way all the action handlers have the same shape / basic structures.
Claude should also be able to help give a few other ideas if you want to dive into this.
There was a problem hiding this comment.
sure, refactored for the action handlers to contain validators to run
a46f2cc to
0d88a80
Compare
Keep real detector and organization context while requiring handlers to opt in to group-less execution. Refs ISWF-3705
Restore the processor organization lookup while retaining cached ownership validation for actions. Enabling evaluation emission for unannotated preprod, processing-errors, and legacy uptime detectors is separate work. Refs ISWF-3705
Remove the unused annotation fast path and keep task tracking in the PR description. Refs ISWF-3705
Replace the group-less capability flag with handler-owned validation before dispatch and execution. Notification handlers require a group and detector project; Seer requires only a group. Keep organization ownership validation in the action model. Refs ISWF-3705
Reuse the invocation test for group-less execution and mock Seer at its execution boundary. Refs ISWF-3705
Name the shared base for its issue-group and project-scoped detector requirements. Refs ISWF-3705
Declare event checks before dispatch and detector checks after resolution. Seer shares the group check with issue actions while keeping its own detector requirements.
0d88a80 to
b365838
Compare
saponifi3d
left a comment
There was a problem hiding this comment.
lgtm, the comments are things that i think we might want to improve if we have the time to do so.
The most critical thing to check before merging is that actions.exclude will use the django cache for actions and not issue an additional query to the db.
| event_validators = (require_issue_group,) | ||
| invocation_validators = (require_project_scoped_detector,) |
There was a problem hiding this comment.
nice! i really like how declarative this is now 🎉
| require_issue_group, | ||
| require_project_scoped_detector, |
There was a problem hiding this comment.
nit: might be nice to add these to a class / enum so they're namespaced; ActionValidators.ISSUE_REQUIRED for example could namespace the validate method for requiring an issue. In the future, if we have other things around the action + an issue, we could add them to that class.
There was a problem hiding this comment.
added a new src/sentry/workflow_engine/handlers/action_validators.py for now (open to thoughts if there's a better location) and made the imports namespaced on module (i.e. action_validators.require_issue_group and action_validators.require_project_scoped_detector)
|
|
||
| CACHE_TTL = 60 * 10 | ||
|
|
||
| def get_organization_id(self) -> int | None: |
There was a problem hiding this comment.
there's already a method: _get_detector_organization in processors/detector.py that does this -- could we reuse that instead of introducing another? or replace the other with this one -- i do kinda like it being attached to the detector directly, and i think that's where most folks would look first.
The other has a nice win that it checks the detector cache first, if it doesn't find it then it loads the org from the cache too.
| "event_id": event_data.event_id, | ||
| }, | ||
| ) | ||
| return actions.exclude(id__in=unsupported_ids) if unsupported_ids else actions |
There was a problem hiding this comment.
🤔 does django make a second query for actions since we've already iterated them or will this use the cache'd data and then filter that? (might be worth confirming that it doesn't do another query, mostly because this layer would be called enough that it might add significant load to the db if there's an additional query).
There was a problem hiding this comment.
good catch, looks like this creates a new queryset so when a handler rejects an action another SELECT runs (but in the regular path of all actions being supported the original queryset gets reused)
i changed this so unsupported actions just get skipped while iterating the original queryset instead of calculating a new one
| def require_issue_group(event_data: WorkflowEventData) -> None: | ||
| if event_data.group is None: | ||
| raise UnsupportedActionEvent("This action requires an issue group") | ||
|
|
||
|
|
||
| def require_project_scoped_detector(invocation: ActionInvocation) -> None: | ||
| if invocation.detector.project_id is None: | ||
| raise UnsupportedActionEvent("This action requires a project-scoped detector") |
There was a problem hiding this comment.
hmm, probably a nit, but i don't feel like these should be in types.py but i'm not sure of a better place for them to live right now, maybe handlers/action/utils.py or something like that?
we can probably also treat this comment as a nit, and then find a good place to have ActionHandler + these co-located.
There was a problem hiding this comment.
added a new src/sentry/workflow_engine/handlers/action_validators.py for now
Validate handlers during deduplication to avoid a second query on rejection. Count rejections by action type. Refs ISWF-3705
A disabled action with a retired type must not block dispatch of active actions. Refs ISWF-3705
Refs https://linear.app/getsentry/issue/ISWF-3705/support-group-less-action-invocation-and-inbox-frequency-semantics.
Allow an action to run without an issue group or project when its required detector belongs to the event’s organization. Handlers declare reusable event validators for checks before dispatch and invocation validators for checks that need a resolved detector. Issue notifications require a group and a project-scoped detector. Seer requires a group.
https://app.notion.com/p/sentry/Investigation-Events-Workflow-Engine-40c8b10e4b5d80d18c4ed6c802d55d64