Skip to content

Commit

Permalink
Check licensing on task start
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme committed Feb 12, 2025
1 parent eb5128f commit 01b88e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit 01b88e4

Please sign in to comment.