Skip to content

feat(ACI): Make rule stats and group history endpoints backwards compatible#110282

Merged
ceorourke merged 4 commits into
masterfrom
ceorourke/ISWF-2190
Mar 10, 2026
Merged

feat(ACI): Make rule stats and group history endpoints backwards compatible#110282
ceorourke merged 4 commits into
masterfrom
ceorourke/ISWF-2190

Conversation

@ceorourke

Copy link
Copy Markdown
Member

Update the ProjectRuleStatsIndexEndpoint and ProjectRuleGroupHistoryIndexEndpoint to accept a workflow ID. Thankfully we already had the functions they call updated to use workflows so this wasn't too large of a change.

@ceorourke ceorourke requested a review from a team as a code owner March 10, 2026 00:43
@linear-code

linear-code Bot commented Mar 10, 2026

Copy link
Copy Markdown

@ceorourke ceorourke requested review from a team and kcons March 10, 2026 00:43
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 10, 2026
Comment thread tests/sentry/rules/history/endpoints/test_project_rule_stats.py

@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! my biggest question is around the tests and the workflow history being saved to the db, that + green seems good to me!

alert_rule_workflow = AlertRuleWorkflow.objects.get(rule_id=rule.id)
workflow = alert_rule_workflow.workflow

if isinstance(target, Workflow):

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: it might be nice to use this logic branch to create a new method that just handles workflows, and then another method that jut handles the Rule variant.

That could help with testing / readability of the code, and allow us to narrow the type of target to Rule / Workflow for any other methods being used.


# make a couple in a different workflow to ensure we're not mixing them up
for i in range(2):
wfh = WorkflowFireHistory(

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.

Suggested change
wfh = WorkflowFireHistory(
wfh = WorkflowFireHistory.objects.create(

Should this be creating / saving these objects to the DB so that it can persist for the tests?

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.

Yeah oops, I copied the previous test that creates RuleFireHistory objects in bulk and forgot to update this 👍

Comment thread src/sentry/rules/history/backends/postgres.py

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

"""

with connection.cursor() as cursor:
cursor.execute(query, [workflow.id, start, end, limit, offset])

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.

Pagination cursor shadowed by database cursor variable

Low Severity

The with connection.cursor() as cursor: on line 91 shadows the cursor pagination parameter from fetch_workflow_groups (line 68). While this happens to work because the database cursor binding is local to data_fn and the pagination cursor is only used at line 103 outside data_fn, the name collision is confusing. The neighboring fetch_workflow_stats method uses db_cursor for the database cursor, making this inconsistency especially noticeable.

Additional Locations (1)
Fix in Cursor Fix in Web

@ceorourke ceorourke merged commit e6be161 into master Mar 10, 2026
55 checks passed
@ceorourke ceorourke deleted the ceorourke/ISWF-2190 branch March 10, 2026 20:25
saponifi3d pushed a commit that referenced this pull request Mar 18, 2026
kcons added a commit that referenced this pull request Mar 18, 2026
…rds compatible (#110282)" (#111038)

This reverts commit e6be161.

The endpoint was already mostly backward compatible, so following our
standard pattern results in a regression.
ceorourke added a commit that referenced this pull request Mar 20, 2026
…atible (#111159)

Redo of #110282 to make the rule
stats and group history endpoints backwards compatible by being flexible
enough to handle either a `Rule` or a `Workflow`. The previous PR was
reverted because I incorrectly assumed `Rule` objects were using
`RuleFireHistory`, but it is correct to continue to combine those
results with `WorkflowFireHistory` for now.

For both methods the basic logic is as follows:
- If passed a workflow, try to fetch the rule ID via `AlertRuleWorkflow`
and fetch combined results. If the workflow was single written, fetch
`WorkflowFireHistory` results only.
- If passed a rule, try to fetch the workflow via `AlertRuleWorkflow`
and fetch combined results. If the rule for some reason doesn't have a
workflow, fetch `RuleFireHistory` results only (this maintains the
existing behavior).
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 26, 2026
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