Skip to content

[ResponseOps] Update task runner to use core services #248866

Merged
darnautov merged 26 commits intoelastic:alerting_v2from
darnautov:refactor-services
Jan 16, 2026
Merged

[ResponseOps] Update task runner to use core services #248866
darnautov merged 26 commits intoelastic:alerting_v2from
darnautov:refactor-services

Conversation

@darnautov
Copy link
Copy Markdown
Contributor

Summary

Updates the rule executor task to use DI container and internal services

Checklist

@darnautov darnautov requested a review from cnasikas January 13, 2026 16:23
@darnautov darnautov marked this pull request as ready for review January 15, 2026 15:22
@darnautov darnautov requested a review from a team as a code owner January 15, 2026 15:22
Copy link
Copy Markdown
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

Great work! It is really nice to see how powerful the DI system is. I left some comments, mostly nits.

});
} catch (error) {
if (abortController.signal.aborted) {
throw new Error('Search has been aborted due to cancelled execution');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it is better to return instead of throwing an error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if we want to exit silently if the task manager aborts 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) ??
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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']>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Why do we need to cast here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so it has the same type signature, e.g. correct argument types etc.

Copy link
Copy Markdown
Member

@cnasikas cnasikas Jan 16, 2026

Choose a reason for hiding this comment

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

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']>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Why do we need to cast here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so it has the same type signature, e.g. correct argument types etc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would expect jest.Mocked<QueryServiceContract>; + satisfies to be enough, no.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod bot requested a review from a team as a code owner January 16, 2026 17:25
@darnautov darnautov merged commit fb0a147 into elastic:alerting_v2 Jan 16, 2026
11 of 13 checks passed
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Jan 16, 2026

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #52 / Cloud Security Posture Tests get rules states API get rules states successfully
  • [job] [logs] FTR Configs #124 / console app console autocomplete feature Autocomplete shouldnt trigger within a multiline block comment
  • [job] [logs] Serverless Entity Analytics - Security Cypress Tests #1 / Entity Analytics Dashboard With anomalies data should enable a job and renders the table with pagination should enable a job and renders the table with pagination
  • [job] [logs] Scout Test Run Builder / selectable with search field
  • [job] [logs] Scout Test Run Builder / serverless-security - EUI testing wrapper: EuiSelectable - selectable with search field

Metrics [docs]

‼️ ERROR: no builds found for mergeBase sha [56b1532]

History

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants