[ResponseOps] Update task runner to use core services #248866
[ResponseOps] Update task runner to use core services #248866darnautov merged 26 commits intoelastic:alerting_v2from
Conversation
cnasikas
left a comment
There was a problem hiding this comment.
Great work! It is really nice to see how powerful the DI system is. I left some comments, mostly nits.
x-pack/platform/plugins/shared/alerting_v2/server/lib/rule_executor/build_alert_events.ts
Outdated
Show resolved
Hide resolved
x-pack/platform/plugins/shared/alerting_v2/server/lib/rule_executor/build_alert_events.test.ts
Outdated
Show resolved
Hide resolved
x-pack/platform/plugins/shared/alerting_v2/server/lib/rule_executor/task_definition.ts
Outdated
Show resolved
Hide resolved
x-pack/platform/plugins/shared/alerting_v2/server/lib/rule_executor/task_definition.ts
Outdated
Show resolved
Hide resolved
x-pack/platform/plugins/shared/alerting_v2/server/lib/rule_executor/task_definition.ts
Outdated
Show resolved
Hide resolved
| }); | ||
| } catch (error) { | ||
| if (abortController.signal.aborted) { | ||
| throw new Error('Search has been aborted due to cancelled execution'); |
There was a problem hiding this comment.
Maybe it is better to return instead of throwing an error.
There was a problem hiding this comment.
Not sure if we want to exit silently if the task manager aborts 🤔
There was a problem hiding this comment.
What are we trying to achieve by throwing an error here?
| const scheduledAt = taskInstance.scheduledAt; | ||
| const scheduledTimestamp = | ||
| (typeof scheduledAt === 'string' ? scheduledAt : undefined) ?? | ||
| (taskInstance.startedAt instanceof Date ? taskInstance.startedAt.toISOString() : undefined) ?? |
There was a problem hiding this comment.
nit: Could we extract this to a function to make it more readable? Also, the taskInstance.scheduledAt is typed as Date. Is it wrong?
| error(params: ErrorParams): void; | ||
| } | ||
|
|
||
| export const LoggerServiceToken = Symbol.for( |
There was a problem hiding this comment.
nit: Maybe we can follow the same pattern as with the other tokens and have a tokens.ts file or the opposite, but to be consistent.
| export function createMockQueryService() { | ||
| type QueryServiceMock = jest.Mocked<QueryServiceContract>; | ||
| const queryService = { | ||
| executeQuery: jest.fn() as jest.MockedFunction<QueryServiceContract['executeQuery']>, |
There was a problem hiding this comment.
nit: Why do we need to cast here?
There was a problem hiding this comment.
so it has the same type signature, e.g. correct argument types etc.
There was a problem hiding this comment.
I would expect jest.Mocked<QueryServiceContract>; + satisfies to be enough, no.
| export function createMockRulesSavedObjectService() { | ||
| type RulesSavedObjectServiceMock = jest.Mocked<RulesSavedObjectServiceContract>; | ||
| const rulesSavedObjectService = { | ||
| create: jest.fn() as jest.MockedFunction<RulesSavedObjectServiceContract['create']>, |
There was a problem hiding this comment.
nit: Why do we need to cast here?
There was a problem hiding this comment.
so it has the same type signature, e.g. correct argument types etc.
There was a problem hiding this comment.
I would expect jest.Mocked<QueryServiceContract>; + satisfies to be enough, no.
There was a problem hiding this comment.
when you use jest.fn() it has no clue about method arguments. You get a TS error like [tsc] 1456 mockResolvedValue(value: ResolvedValue<T>): this; proc [tsc] ~~~~~~~~~~~~~~~~~~~~~~~ proc [tsc] An argument for 'value' was not provided.
…tion_tests/ci_checks
💔 Build Failed
Failed CI Steps
Test Failures
Metrics [docs]
History
|
Summary
Updates the rule executor task to use DI container and internal services
Checklist