Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const previouslyRegisteredTypes = [
'action_task_params',
'ad_hoc_run_params',
'alert',
'alerting_rule',
'alerting_rule_template',
'api_key_pending_invalidation',
'api_key_to_invalidate',
Expand Down
2 changes: 2 additions & 0 deletions x-pack/platform/plugins/shared/alerting_v2/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { configSchema } from './config';
import { bindOnSetup } from './setup/bind_on_setup';
import { bindRoutes } from './setup/bind_routes';
import { bindServices } from './setup/bind_services';
import { bindOnStart } from './setup/bind_on_start';

export const config: PluginConfigDescriptor<PluginConfig> = {
schema: configSchema,
Expand All @@ -21,6 +22,7 @@ export const module = new ContainerModule((options) => {
bindRoutes(options);
bindServices(options);
bindOnSetup(options);
bindOnStart(options);
});

export type { PluginConfig as AlertingV2Config } from './config';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import type { CoreStart, Logger } from '@kbn/core/server';
import type { TaskManagerSetupContract } from '@kbn/task-manager-plugin/server';
import { schema } from '@kbn/config-schema';

import type { Container } from 'inversify';
import type { PluginConfig } from '../../config';
import type { AlertingServerStartDependencies } from '../../types';
import { createRuleExecutorTaskRunner } from './task_runner';
import type { AlertingResourcesService } from '../services/alerting_resources_service';

export const ALERTING_RULE_EXECUTOR_TASK_TYPE = 'alerting:esql' as const;
export const ALERTING_RULE_EXECUTOR_TASK_TYPE = 'alerting_v2:rule_executor' as const;

export function initializeRuleExecutorTaskDefinition(
logger: Logger,
taskManager: TaskManagerSetupContract,
coreStartServices: Promise<[CoreStart, AlertingServerStartDependencies, unknown]>,
config: PluginConfig,
resourcesService: AlertingResourcesService
container: Container
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.

FYI I updated the task definition to use DI here #248866

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How should I approach it? Merge this PR and then in your PR update with the new task definition?

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.

it's just FYI, I update my PR after we merge this one

) {
taskManager.registerTaskDefinitions({
[ALERTING_RULE_EXECUTOR_TASK_TYPE]: {
Expand All @@ -35,7 +35,7 @@ export function initializeRuleExecutorTaskDefinition(
logger,
coreStartServices,
config,
resourcesService,
container,
}),
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ import type { CoreStart, Logger } from '@kbn/core/server';
import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server';
import type { RunContext } from '@kbn/task-manager-plugin/server';

import type { Container } from 'inversify';
import type { PluginConfig } from '../../config';
import type { AlertingServerStartDependencies } from '../../types';
import { RULE_SAVED_OBJECT_TYPE } from '../../saved_objects';
import type { RuleSavedObjectAttributes } from '../../saved_objects';
import { spaceIdToNamespace } from '../space_id_to_namespace';
import type { RuleExecutorTaskParams } from './types';
import { executeEsqlRule } from './execute_esql';
import { ALERT_EVENTS_INDEX } from './constants';
import { writeEsqlAlerts } from './write_alerts';
import type { AlertingResourcesService } from '../services/alerting_resources_service';
import { ResourceManager } from '../services/resource_service/resource_manager';
import { ALERT_EVENTS_DATA_STREAM } from '../../resources/alert_events';

export function createRuleExecutorTaskRunner({
logger,
coreStartServices,
config,
resourcesService,
container,
}: {
logger: Logger;
coreStartServices: Promise<[CoreStart, AlertingServerStartDependencies, unknown]>;
config: PluginConfig;
resourcesService: AlertingResourcesService;
container: Container;
}) {
return ({ taskInstance, abortController, fakeRequest }: RunContext) => {
return {
Expand All @@ -45,6 +46,7 @@ export function createRuleExecutorTaskRunner({
}

const params = taskInstance.params as RuleExecutorTaskParams;
const resourcesService = container.get(ResourceManager);
// Wait for the plugin-wide resource initialization started during plugin setup.
await resourcesService.waitUntilReady();

Expand Down Expand Up @@ -106,7 +108,7 @@ export function createRuleExecutorTaskRunner({
);

const esClient = coreStart.elasticsearch.client.asInternalUser;
const targetDataStream = ALERT_EVENTS_INDEX;
const targetDataStream = ALERT_EVENTS_DATA_STREAM;

const scheduledAt = taskInstance.scheduledAt;
const scheduledTimestamp =
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { ElasticsearchClient } from '@kbn/core/server';
import type { ServiceIdentifier } from 'inversify';

export const EsServiceInternalToken = Symbol.for(
'alerting_v2.EsServiceInternal'
) as ServiceIdentifier<ElasticsearchClient>;

export const EsServiceScopedToken = Symbol.for(
'alerting_v2.EsServiceScoped'
) as ServiceIdentifier<ElasticsearchClient>;
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { ESQL_SEARCH_STRATEGY, isRunningResponse } from '@kbn/data-plugin/common
import type { ESQLSearchParams, ESQLSearchResponse } from '@kbn/es-types';
import type { IKibanaSearchRequest, IKibanaSearchResponse } from '@kbn/search-types';
import { catchError, filter as rxFilter, lastValueFrom, map, throwError } from 'rxjs';
import { injectable } from 'inversify';
import type { LoggerService } from '../logger_service/logger_service';
import { inject, injectable } from 'inversify';
import { LoggerService } from '../logger_service/logger_service';

interface ExecuteQueryParams {
query: ESQLSearchParams['query'];
Expand All @@ -23,7 +23,7 @@ interface ExecuteQueryParams {
export class QueryService {
constructor(
private readonly searchClient: IScopedSearchClient,
private readonly logger: LoggerService
@inject(LoggerService) private readonly logger: LoggerService
) {}

async executeQuery({ query, filter, params }: ExecuteQueryParams): Promise<ESQLSearchResponse> {
Expand Down
Loading