Skip to content
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

[Response Ops][Alerting] Refactor ExecutionHandler stage 1 #186666

Merged
merged 6 commits into from
Jul 22, 2024

Conversation

ymao1
Copy link
Contributor

@ymao1 ymao1 commented Jun 21, 2024

Resolves #186533

Summary

Stage 1 of ExecutionHandler refactor:

  • Rename ExecutionHandler to ActionScheduler.
  • Create schedulers to handle the 3 different action types (SummaryActionScheduler, SystemActionScheduler, PerAlertActionScheduler)
  • Splits ExecutionHandler.generateExecutables function into the appropriate action type class and combine the returned executables from each scheduler class.

GH is not recognizing the rename from ExecutionHandler to ActionScheduler so I've called out the primary difference between the two files (other than the rename) which is to get the executables from each scheduler class instead of from a generateExecutables function. Removed the generateExecutables fn from the ActionScheduler and any associated private helper functions.

@ymao1 ymao1 force-pushed the refactor-execution-handler-stage-1 branch from dbeb39e to 110d9e2 Compare July 2, 2024 01:42
);
this.previousStartedAt = context.previousStartedAt;

for (const [_, scheduler] of Object.entries(schedulers)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This grabs every scheduler from the schedulers/index.ts file

Copy link
Member

Choose a reason for hiding this comment

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

I think the schedulers calculation, and sorting, can probably be done in static code, not even in the constructor. Minor perf improvement :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried moving schedulers into a static variable

static schedulers: Array<
    IActionScheduler<State, Context, ActionGroupIds, RecoveryActionGroupId>
  > = [];

but I get a TS warning: Static members cannot reference class type parameters

}

// sort schedulers by priority
this.schedulers.sort((a, b) => a.priority - b.priority);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

and then sorts them by self-identified priority

});

const executables = [];
for (const scheduler of this.schedulers) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only change to the run function. Previously, it called

const executables = await this.generateExecutables(alerts, throttledSummaryActions);

@@ -51,100 +47,16 @@ const actionsClient = actionsClientMock.create();
const alertsClient = alertsClientMock.create();
const mockActionsPlugin = actionsMock.createStart();
const apiKey = Buffer.from('123:abc').toString('base64');
const ruleType: NormalizedRuleType<
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved these to a test_fixtures file

queryOptions: GetSummarizedAlertsParams;
}

export const getSummarizedAlerts = async <
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a private function in ExecutionHandler class. Moved to a reusable helper function

@ymao1 ymao1 self-assigned this Jul 2, 2024
@ymao1 ymao1 changed the title Refactor execution handler stage 1 [Response Ops][Alerting] Refactor ExecutionHandler stage 1 Jul 2, 2024
@ymao1 ymao1 added Feature:Alerting Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.16.0 release_note:skip Skip the PR/issue when compiling release notes labels Jul 2, 2024
@ymao1 ymao1 marked this pull request as ready for review July 2, 2024 15:46
@ymao1 ymao1 requested a review from a team as a code owner July 2, 2024 15:46
@elasticmachine
Copy link
Contributor

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

@ymao1
Copy link
Contributor Author

ymao1 commented Jul 8, 2024

@elasticmachine merge upstream

Copy link
Contributor

@js-jankisalvi js-jankisalvi left a comment

Choose a reason for hiding this comment

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

Looks good.
Since it is a refactor, verified in local that creating rule with system actions, adding maintenance window for alerts is working same as before.

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

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

LGTM, left one comment about a micro-optimization

);
this.previousStartedAt = context.previousStartedAt;

for (const [_, scheduler] of Object.entries(schedulers)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the schedulers calculation, and sorting, can probably be done in static code, not even in the constructor. Minor perf improvement :-)

@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 16, 2024

💔 Build Failed

Failed CI Steps

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
alerting 93 94 +1

Total ESLint disabled count

id before after diff
alerting 97 98 +1

History

cc @ymao1

@ymao1
Copy link
Contributor Author

ymao1 commented Jul 22, 2024

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
alerting 93 94 +1

Total ESLint disabled count

id before after diff
alerting 97 98 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @ymao1

@ymao1 ymao1 merged commit f19af22 into elastic:main Jul 22, 2024
36 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jul 22, 2024
@ymao1 ymao1 deleted the refactor-execution-handler-stage-1 branch July 22, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Response Ops][Alerting] Refactor ExecutionHandler Pt 1
6 participants