Skip to content

[Alerting] Alerting v2: Refactor rule executor to use a pipeline pattern#250161

Merged
cnasikas merged 10 commits intoelastic:alerting_v2from
cnasikas:alerting_v2_executor_pattern
Jan 28, 2026
Merged

[Alerting] Alerting v2: Refactor rule executor to use a pipeline pattern#250161
cnasikas merged 10 commits intoelastic:alerting_v2from
cnasikas:alerting_v2_executor_pattern

Conversation

@cnasikas
Copy link
Copy Markdown
Member

@cnasikas cnasikas commented Jan 23, 2026

Summary

This PR refactors the rule executor to use a pipeline pattern. This will help us work in parallel, isolate piece of code, easier testing, and avoid touching the core logic of the executor in the future. More details in the README.md file.

Fixes: https://github.com/elastic/rna-program/issues/75

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

@cnasikas cnasikas self-assigned this Jan 23, 2026
@cnasikas cnasikas added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// labels Jan 23, 2026
@cnasikas cnasikas force-pushed the alerting_v2_executor_pattern branch 5 times, most recently from 2ebbe33 to a3cc724 Compare January 26, 2026 10:02
@cnasikas cnasikas marked this pull request as ready for review January 26, 2026 10:02
@cnasikas cnasikas requested a review from a team as a code owner January 26, 2026 10:02
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

Comment on lines +123 to +147
bind(WaitForResourcesStep).toSelf().inSingletonScope();
bind(FetchRuleStep).toSelf().inRequestScope();
bind(ValidateRuleStep).toSelf().inSingletonScope();
bind(BuildQueryStep).toSelf().inSingletonScope();
bind(ExecuteQueryStep).toSelf().inRequestScope();
bind(BuildAlertsStep).toSelf().inSingletonScope();
bind(StoreAlertsStep).toSelf().inSingletonScope();

/**
* Bind steps array (order defines execution order)
* Steps can be wrapped with decorators for per-step behavior
* For example: new AuditLoggingDecorator(get(ValidateRuleStep), auditService)
*/

bind(RuleExecutionStepsToken)
.toDynamicValue(({ get }) => [
get(WaitForResourcesStep),
get(FetchRuleStep),
get(ValidateRuleStep),
get(BuildQueryStep),
get(ExecuteQueryStep),
get(BuildAlertsStep),
get(StoreAlertsStep),
])
.inRequestScope();
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.

Would it be possible to refactor to use ServiceIdentifier similar to Route, to get easier setup?

bind(ExecutorStep).toConstantValue(WaitForResourcesStep)

@cnasikas cnasikas requested review from a team as code owners January 26, 2026 10:39
@cnasikas cnasikas removed request for a team January 26, 2026 10:40
* Use decorators when you need per-step control without adding conditionals
* to middleware.
*/
export abstract class RuleStepDecorator implements RuleExecutionStep {
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.

is it used anywhere?

Copy link
Copy Markdown
Member Author

@cnasikas cnasikas Jan 26, 2026

Choose a reason for hiding this comment

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

Not yet. It is an abstract class that can be used to create decorators. I can remove it and implement it when we need a decorator. What do you prefer?

Copy link
Copy Markdown
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Jan 28, 2026

💔 Build Failed

Failed CI Steps

History

cc @cnasikas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t//

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants