diff --git a/x-pack/platform/plugins/shared/cases/server/cases_analytics/tasks/synchronization_task/synchronization_task_runner.test.ts b/x-pack/platform/plugins/shared/cases/server/cases_analytics/tasks/synchronization_task/synchronization_task_runner.test.ts index cf45525535120..d9ac1f0f4146c 100644 --- a/x-pack/platform/plugins/shared/cases/server/cases_analytics/tasks/synchronization_task/synchronization_task_runner.test.ts +++ b/x-pack/platform/plugins/shared/cases/server/cases_analytics/tasks/synchronization_task/synchronization_task_runner.test.ts @@ -338,33 +338,6 @@ describe('SynchronizationTaskRunner', () => { }); describe('Error handling', () => { - it('An error is thrown for invalid task state', async () => { - const getESClient = async () => esClient; - - taskRunner = new SynchronizationTaskRunner({ - logger, - getESClient, - taskInstance: { - ...taskInstance, - state: { - // A missing esReindexTaskId should have missing sync times - lastSyncAttempt: 'some-time', - }, - }, - }); - - try { - await taskRunner.run(); - } catch (e) { - expect(isRetryableError(e)).toBe(null); - } - - expect(logger.error).toBeCalledWith( - '[.internal.cases] Synchronization reindex failed. Error: Invalid task state.', - { tags: ['cai-synchronization', 'cai-synchronization-error', '.internal.cases'] } - ); - }); - it('calls throwRetryableError if the esClient throws a retryable error', async () => { esClient.tasks.get.mockRejectedValueOnce(new esErrors.ConnectionError('My retryable error')); diff --git a/x-pack/platform/plugins/shared/cases/server/config.test.ts b/x-pack/platform/plugins/shared/cases/server/config.test.ts index 352faac983f29..9e652cb52ffe1 100644 --- a/x-pack/platform/plugins/shared/cases/server/config.test.ts +++ b/x-pack/platform/plugins/shared/cases/server/config.test.ts @@ -12,6 +12,7 @@ describe('config validation', () => { it('sets the defaults correctly', () => { expect(ConfigSchema.validate({})).toMatchInlineSnapshot(` Object { + "analytics": Object {}, "files": Object { "allowedMimeTypes": Array [ "image/aces", diff --git a/x-pack/platform/plugins/shared/cases/server/config.ts b/x-pack/platform/plugins/shared/cases/server/config.ts index 7e30671ee4734..d0f62ba8824a5 100644 --- a/x-pack/platform/plugins/shared/cases/server/config.ts +++ b/x-pack/platform/plugins/shared/cases/server/config.ts @@ -23,6 +23,13 @@ export const ConfigSchema = schema.object({ stack: schema.object({ enabled: schema.boolean({ defaultValue: true }), }), + analytics: schema.object({ + index: schema.maybe( + schema.object({ + enabled: schema.boolean({ defaultValue: false }), + }) + ), + }), }); export type ConfigType = TypeOf; diff --git a/x-pack/platform/plugins/shared/cases/server/plugin.test.ts b/x-pack/platform/plugins/shared/cases/server/plugin.test.ts index 3fdcf7a8770cf..2ec89e323ab07 100644 --- a/x-pack/platform/plugins/shared/cases/server/plugin.test.ts +++ b/x-pack/platform/plugins/shared/cases/server/plugin.test.ts @@ -28,6 +28,7 @@ function getConfig(overrides = {}) { markdownPlugins: { lens: true }, files: { maxSize: 1, allowedMimeTypes: ALLOWED_MIME_TYPES }, stack: { enabled: true }, + analytics: {}, ...overrides, }; } diff --git a/x-pack/platform/plugins/shared/cases/server/plugin.ts b/x-pack/platform/plugins/shared/cases/server/plugin.ts index 8f0b87bea8f61..f642b77b47390 100644 --- a/x-pack/platform/plugins/shared/cases/server/plugin.ts +++ b/x-pack/platform/plugins/shared/cases/server/plugin.ts @@ -203,16 +203,17 @@ export class CasePlugin if (plugins.taskManager) { scheduleCasesTelemetryTask(plugins.taskManager, this.logger); - scheduleCasesAnalyticsSyncTasks({ taskManager: plugins.taskManager, logger: this.logger }); + if (this.caseConfig.analytics.index?.enabled) { + scheduleCasesAnalyticsSyncTasks({ taskManager: plugins.taskManager, logger: this.logger }); + createCasesAnalyticsIndexes({ + esClient: core.elasticsearch.client.asInternalUser, + logger: this.logger, + isServerless: this.isServerless, + taskManager: plugins.taskManager, + }).catch(() => {}); // it shouldn't reject, but just in case + } } - createCasesAnalyticsIndexes({ - esClient: core.elasticsearch.client.asInternalUser, - logger: this.logger, - isServerless: this.isServerless, - taskManager: plugins.taskManager, - }).catch(() => {}); // it shouldn't reject, but just in case - this.userProfileService.initialize({ spaces: plugins.spaces, // securityPluginSetup will be set to a defined value in the setup() function