From 01b88e49b61a0a3bcef5cdc4912e854079032379 Mon Sep 17 00:00:00 2001 From: Kevin Delemme Date: Wed, 12 Feb 2025 10:35:17 -0500 Subject: [PATCH] Check licensing on task start --- .../plugins/slo/server/plugin.ts | 2 +- .../tasks/temp_summary_cleanup_task.ts | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/x-pack/solutions/observability/plugins/slo/server/plugin.ts b/x-pack/solutions/observability/plugins/slo/server/plugin.ts index 9e3c30d46c1af..b46e52081d9da 100644 --- a/x-pack/solutions/observability/plugins/slo/server/plugin.ts +++ b/x-pack/solutions/observability/plugins/slo/server/plugin.ts @@ -189,7 +189,7 @@ export class SLOPlugin ?.start(plugins.taskManager, internalSoClient, internalEsClient) .catch(() => {}); - this.tempSummaryCleanupTask?.start({ taskManager: plugins.taskManager }).catch(() => {}); + this.tempSummaryCleanupTask?.start(plugins).catch(() => {}); return { getSloClientWithRequest: (request: KibanaRequest) => { diff --git a/x-pack/solutions/observability/plugins/slo/server/services/tasks/temp_summary_cleanup_task.ts b/x-pack/solutions/observability/plugins/slo/server/services/tasks/temp_summary_cleanup_task.ts index 7778ff21f19c6..d582c8841a38e 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/tasks/temp_summary_cleanup_task.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/tasks/temp_summary_cleanup_task.ts @@ -7,13 +7,9 @@ import { errors } from '@elastic/elasticsearch'; import { type CoreSetup, type Logger, type LoggerFactory } from '@kbn/core/server'; -import { - ConcreteTaskInstance, - TaskManagerSetupContract, - TaskManagerStartContract, -} from '@kbn/task-manager-plugin/server'; +import { ConcreteTaskInstance, TaskManagerSetupContract } from '@kbn/task-manager-plugin/server'; import { getDeleteTaskRunResult } from '@kbn/task-manager-plugin/server/task'; -import { SLOConfig } from '../../types'; +import { SLOConfig, SLOPluginStartDependencies } from '../../types'; import { CleanUpTempSummary } from '../management/clean_up_temp_summary'; export const TYPE = 'slo:temp-summary-cleanup-task'; @@ -59,22 +55,28 @@ export class TempSummaryCleanupTask { }); } - public async start({ taskManager }: { taskManager: TaskManagerStartContract }) { - if (!taskManager) { + public async start(plugins: SLOPluginStartDependencies) { + const hasCorrectLicense = (await plugins.licensing.getLicense()).hasAtLeast('platinum'); + if (!hasCorrectLicense) { + this.logger.debug('Platinum license is required'); + return; + } + + if (!plugins.taskManager) { this.logger.error('Missing required service during start'); return; } if (!this.config.tempSummaryCleanupTaskEnabled) { this.logger.info('Unscheduling task'); - return await taskManager.removeIfExists(this.taskId); + return await plugins.taskManager.removeIfExists(this.taskId); } this.logger.info('Scheduling task with [1h] interval'); this.wasStarted = true; try { - await taskManager.ensureScheduled({ + await plugins.taskManager.ensureScheduled({ id: this.taskId, taskType: TYPE, scope: ['observability', 'slo'],