Skip to content

Commit 698a3fe

Browse files
authored
[ResponseOps] Cases analytics index configuration option (#223241)
**Merging into a feature branch** ## Summary This PR adds a configuration option to enable the cases analytics index logic. `xpack.cases.analyticsIndex.enabled: true` The task types are registered, but by default, no task is scheduled, and no index is created. ## How to review **The previous PRs are not merged yet, so only commits after bd6f2b8 should be reviewed.**
1 parent 7b1e564 commit 698a3fe

File tree

5 files changed

+18
-35
lines changed

5 files changed

+18
-35
lines changed

x-pack/platform/plugins/shared/cases/server/cases_analytics/tasks/synchronization_task/synchronization_task_runner.test.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -338,33 +338,6 @@ describe('SynchronizationTaskRunner', () => {
338338
});
339339

340340
describe('Error handling', () => {
341-
it('An error is thrown for invalid task state', async () => {
342-
const getESClient = async () => esClient;
343-
344-
taskRunner = new SynchronizationTaskRunner({
345-
logger,
346-
getESClient,
347-
taskInstance: {
348-
...taskInstance,
349-
state: {
350-
// A missing esReindexTaskId should have missing sync times
351-
lastSyncAttempt: 'some-time',
352-
},
353-
},
354-
});
355-
356-
try {
357-
await taskRunner.run();
358-
} catch (e) {
359-
expect(isRetryableError(e)).toBe(null);
360-
}
361-
362-
expect(logger.error).toBeCalledWith(
363-
'[.internal.cases] Synchronization reindex failed. Error: Invalid task state.',
364-
{ tags: ['cai-synchronization', 'cai-synchronization-error', '.internal.cases'] }
365-
);
366-
});
367-
368341
it('calls throwRetryableError if the esClient throws a retryable error', async () => {
369342
esClient.tasks.get.mockRejectedValueOnce(new esErrors.ConnectionError('My retryable error'));
370343

x-pack/platform/plugins/shared/cases/server/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('config validation', () => {
1212
it('sets the defaults correctly', () => {
1313
expect(ConfigSchema.validate({})).toMatchInlineSnapshot(`
1414
Object {
15+
"analytics": Object {},
1516
"files": Object {
1617
"allowedMimeTypes": Array [
1718
"image/aces",

x-pack/platform/plugins/shared/cases/server/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ export const ConfigSchema = schema.object({
2323
stack: schema.object({
2424
enabled: schema.boolean({ defaultValue: true }),
2525
}),
26+
analytics: schema.object({
27+
index: schema.maybe(
28+
schema.object({
29+
enabled: schema.boolean({ defaultValue: false }),
30+
})
31+
),
32+
}),
2633
});
2734

2835
export type ConfigType = TypeOf<typeof ConfigSchema>;

x-pack/platform/plugins/shared/cases/server/plugin.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function getConfig(overrides = {}) {
2828
markdownPlugins: { lens: true },
2929
files: { maxSize: 1, allowedMimeTypes: ALLOWED_MIME_TYPES },
3030
stack: { enabled: true },
31+
analytics: {},
3132
...overrides,
3233
};
3334
}

x-pack/platform/plugins/shared/cases/server/plugin.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,17 @@ export class CasePlugin
203203

204204
if (plugins.taskManager) {
205205
scheduleCasesTelemetryTask(plugins.taskManager, this.logger);
206-
scheduleCasesAnalyticsSyncTasks({ taskManager: plugins.taskManager, logger: this.logger });
206+
if (this.caseConfig.analytics.index?.enabled) {
207+
scheduleCasesAnalyticsSyncTasks({ taskManager: plugins.taskManager, logger: this.logger });
208+
createCasesAnalyticsIndexes({
209+
esClient: core.elasticsearch.client.asInternalUser,
210+
logger: this.logger,
211+
isServerless: this.isServerless,
212+
taskManager: plugins.taskManager,
213+
}).catch(() => {}); // it shouldn't reject, but just in case
214+
}
207215
}
208216

209-
createCasesAnalyticsIndexes({
210-
esClient: core.elasticsearch.client.asInternalUser,
211-
logger: this.logger,
212-
isServerless: this.isServerless,
213-
taskManager: plugins.taskManager,
214-
}).catch(() => {}); // it shouldn't reject, but just in case
215-
216217
this.userProfileService.initialize({
217218
spaces: plugins.spaces,
218219
// securityPluginSetup will be set to a defined value in the setup() function

0 commit comments

Comments
 (0)