-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Conversation
dbeb39e
to
110d9e2
Compare
); | ||
this.previousStartedAt = context.previousStartedAt; | ||
|
||
for (const [_, scheduler] of Object.entries(schedulers)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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< |
There was a problem hiding this comment.
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 < |
There was a problem hiding this comment.
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
x-pack/plugins/alerting/server/task_runner/action_scheduler/rule_action_helper.ts
Show resolved
Hide resolved
ExecutionHandler
stage 1
Pinging @elastic/response-ops (Team:ResponseOps) |
@elasticmachine merge upstream |
There was a problem hiding this 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.
x-pack/plugins/alerting/server/task_runner/action_scheduler/rule_action_helper.ts
Show resolved
Hide resolved
…ion-handler-stage-1
There was a problem hiding this 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)) { |
There was a problem hiding this comment.
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 :-)
…ion-handler-stage-1
💔 Build Failed
Failed CI Steps
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
cc @ymao1 |
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @ymao1 |
Resolves #186533
Summary
Stage 1 of
ExecutionHandler
refactor:ExecutionHandler
toActionScheduler
.SummaryActionScheduler
,SystemActionScheduler
,PerAlertActionScheduler
)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
toActionScheduler
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 agenerateExecutables
function. Removed thegenerateExecutables
fn from theActionScheduler
and any associated private helper functions.