Skip to content
Draft
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
31 changes: 14 additions & 17 deletions x-pack/solutions/observability/plugins/slo/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import type {
} from '@kbn/core/server';
import { DEFAULT_APP_CATEGORIES, SavedObjectsClient } from '@kbn/core/server';
import { i18n } from '@kbn/i18n';
import { LockAcquisitionError, LockManagerService } from '@kbn/lock-manager';
import { AlertsLocatorDefinition, sloFeatureId } from '@kbn/observability-plugin/common';
import { SLO_BURN_RATE_RULE_TYPE_ID, DEPRECATED_ALERTING_CONSUMERS } from '@kbn/rule-data-utils';
import { DEPRECATED_ALERTING_CONSUMERS, SLO_BURN_RATE_RULE_TYPE_ID } from '@kbn/rule-data-utils';
import { mapValues } from 'lodash';
import { LockAcquisitionError, LockManagerService } from '@kbn/lock-manager';
import { LOCK_ID_RESOURCE_INSTALLER } from '../common/constants';
import { getSloClientWithRequest } from './client';
import { registerSloUsageCollector } from './lib/collectors/register';
import { registerBurnRateRule } from './lib/rules/register_burn_rate_rule';
Expand All @@ -36,8 +37,8 @@ import {
} from './services';
import { DefaultSummaryTransformGenerator } from './services/summary_transform_generator/summary_transform_generator';
import { BulkDeleteTask } from './services/tasks/bulk_delete/bulk_delete_task';
import { SloOrphanSummaryCleanupTask } from './services/tasks/orphan_summary_cleanup_task';
import { TempSummaryCleanupTask } from './services/tasks/temp_summary_cleanup_task';
import { OrphanSummaryCleanupTask } from './services/tasks/orphan_summary_cleanup_task/orphan_summary_cleanup_task';
import { TempSummaryCleanupTask } from './services/tasks/temp_summary_cleanup_task/temp_summary_cleanup_task';
import { createTransformGenerators } from './services/transform_generators';
import type {
SLOConfig,
Expand All @@ -46,7 +47,6 @@ import type {
SLOServerSetup,
SLOServerStart,
} from './types';
import { LOCK_ID_RESOURCE_INSTALLER } from '../common/constants';

const sloRuleTypes = [SLO_BURN_RATE_RULE_TYPE_ID];

Expand All @@ -58,7 +58,7 @@ export class SLOPlugin
private readonly config: SLOConfig;
private readonly isServerless: boolean;
private readonly isDev: boolean;
private sloOrphanCleanupTask?: SloOrphanSummaryCleanupTask;
private orphanSummaryCleanupTask?: OrphanSummaryCleanupTask;
private tempSummaryCleanupTask?: TempSummaryCleanupTask;

constructor(private readonly initContext: PluginInitializerContext) {
Expand Down Expand Up @@ -227,11 +227,12 @@ export class SLOPlugin
}
});

this.sloOrphanCleanupTask = new SloOrphanSummaryCleanupTask(
plugins.taskManager,
this.logger,
this.config
);
this.orphanSummaryCleanupTask = new OrphanSummaryCleanupTask({
core,
taskManager: plugins.taskManager,
logFactory: this.initContext.logger,
config: this.config,
});

this.tempSummaryCleanupTask = new TempSummaryCleanupTask({
core,
Expand All @@ -242,21 +243,17 @@ export class SLOPlugin

new BulkDeleteTask({
core,
plugins: mappedPlugins,
taskManager: plugins.taskManager,
logFactory: this.initContext.logger,
});

return {};
}

public start(core: CoreStart, plugins: SLOPluginStartDependencies): SLOServerStart {
const internalSoClient = new SavedObjectsClient(core.savedObjects.createInternalRepository());
const internalEsClient = core.elasticsearch.client.asInternalUser;

this.sloOrphanCleanupTask
?.start(plugins.taskManager, internalSoClient, internalEsClient)
.catch(() => {});

this.orphanSummaryCleanupTask?.start(plugins).catch(() => {});
this.tempSummaryCleanupTask?.start(plugins).catch(() => {});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import { type CoreSetup, type Logger, type LoggerFactory } from '@kbn/core/server';
import type { BulkDeleteParams, BulkDeleteStatusResponse } from '@kbn/slo-schema';
import type { RunContext } from '@kbn/task-manager-plugin/server';
import type { RunContext, TaskManagerSetupContract } from '@kbn/task-manager-plugin/server';
import type { IndicatorTypes } from '../../../domain/models';
import type { SLOPluginSetupDependencies, SLOPluginStartDependencies } from '../../../types';
import type { SLOPluginStartDependencies } from '../../../types';
import { DeleteSLO } from '../../delete_slo';
import { KibanaSavedObjectsSLORepository } from '../../slo_repository';
import { DefaultSummaryTransformGenerator } from '../../summary_transform_generator/summary_transform_generator';
Expand All @@ -23,27 +23,19 @@ export const TYPE = 'slo:bulk-delete-task';
interface TaskSetupContract {
core: CoreSetup<SLOPluginStartDependencies>;
logFactory: LoggerFactory;
plugins: {
[key in keyof SLOPluginSetupDependencies]: {
setup: Required<SLOPluginSetupDependencies>[key];
};
} & {
[key in keyof SLOPluginStartDependencies]: {
start: () => Promise<Required<SLOPluginStartDependencies>[key]>;
};
};
taskManager: TaskManagerSetupContract;
}

export class BulkDeleteTask {
private logger: Logger;

constructor(setupContract: TaskSetupContract) {
const { core, plugins, logFactory } = setupContract;
const { core, taskManager, logFactory } = setupContract;
this.logger = logFactory.get(TYPE);

this.logger.debug('Registering task with [10m] timeout');

plugins.taskManager.setup.registerTaskDefinitions({
taskManager.registerTaskDefinitions({
[TYPE]: {
title: 'SLO bulk delete',
timeout: '10m',
Expand Down
Loading