Skip to content

Commit 919b0d7

Browse files
adcoelhokibanamachinecnasikaselasticmachinedavismcphee
committed
[ResponseOps] Cases analytics integration tests (#225231)
Integration tests for the cases analytics indexes. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Davis McPhee <davis.mcphee@elastic.co> (cherry picked from commit 7012a3b)
1 parent 32bb66c commit 919b0d7

21 files changed

Lines changed: 1043 additions & 23 deletions

File tree

x-pack/platform/plugins/shared/cases/common/constants/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ export const DEFAULT_FEATURES: CasesFeaturesAllRequired = Object.freeze({
176176
*/
177177

178178
export const CASES_TELEMETRY_TASK_NAME = 'cases-telemetry-task';
179+
export const ANALYTICS_BACKFILL_TASK_TYPE = 'cai:cases_analytics_index_backfill';
180+
export const ANALYTICS_SYNCHRONIZATION_TASK_TYPE = 'cai:cases_analytics_index_synchronization';
179181

180182
/**
181183
* Telemetry

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ describe('AnalyticsIndex', () => {
118118
},
119119
settings: {
120120
index: {
121+
hidden: true,
121122
auto_expand_replicas: '0-1',
122123
mode: 'lookup',
123124
number_of_shards: 1,

x-pack/platform/plugins/shared/cases/server/cases_analytics/analytics_index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class AnalyticsIndex {
9393
this.sourceIndex = sourceIndex;
9494
this.sourceQuery = sourceQuery;
9595
this.indexSettings = {
96+
hidden: true,
9697
// settings are not supported on serverless ES
9798
...(isServerless
9899
? {}

x-pack/platform/plugins/shared/cases/server/cases_analytics/tasks/backfill_task/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
* 2.0.
66
*/
77

8-
export const TASK_TYPE = 'cai:cases_analytics_index_backfill';
98
export const BACKFILL_RUN_AT = 60 * 1000; // milliseconds

x-pack/platform/plugins/shared/cases/server/cases_analytics/tasks/backfill_task/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import type {
1313
} from '@kbn/task-manager-plugin/server';
1414
import type { CoreSetup, ElasticsearchClient } from '@kbn/core/server';
1515
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
16+
import { ANALYTICS_BACKFILL_TASK_TYPE } from '../../../../common/constants';
1617
import type { CasesServerStartDependencies } from '../../../types';
1718
import { CaseAnalyticsIndexBackfillTaskFactory } from './backfill_task_factory';
18-
import { TASK_TYPE, BACKFILL_RUN_AT } from './constants';
19+
import { BACKFILL_RUN_AT } from './constants';
1920

2021
export function registerCAIBackfillTask({
2122
taskManager,
@@ -32,7 +33,7 @@ export function registerCAIBackfillTask({
3233
};
3334

3435
taskManager.registerTaskDefinitions({
35-
[TASK_TYPE]: {
36+
[ANALYTICS_BACKFILL_TASK_TYPE]: {
3637
title: 'Backfill cases analytics indexes.',
3738
maxAttempts: 3,
3839
createTaskRunner: (context: RunContext) => {
@@ -60,7 +61,7 @@ export async function scheduleCAIBackfillTask({
6061
try {
6162
await taskManager.ensureScheduled({
6263
id: taskId,
63-
taskType: TASK_TYPE,
64+
taskType: ANALYTICS_BACKFILL_TASK_TYPE,
6465
params: { sourceIndex, destIndex, sourceQuery },
6566
runAt: new Date(Date.now() + BACKFILL_RUN_AT), // todo, value is short for testing but should run after 5 minutes
6667
state: {},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import type {
1313
TaskManagerStartContract,
1414
} from '@kbn/task-manager-plugin/server';
1515
import type { CoreSetup, ElasticsearchClient } from '@kbn/core/server';
16+
import { ANALYTICS_SYNCHRONIZATION_TASK_TYPE } from '../../../../common/constants';
1617
import type { CasesServerStartDependencies } from '../../../types';
1718
import { AnalyticsIndexSynchronizationTaskFactory } from './synchronization_task_factory';
1819

19-
const TASK_TYPE = 'cai:cases_analytics_index_synchronization';
2020
const SCHEDULE: IntervalSchedule = { interval: '5m' };
2121

2222
export function registerCAISynchronizationTask({
@@ -34,7 +34,7 @@ export function registerCAISynchronizationTask({
3434
};
3535

3636
taskManager.registerTaskDefinitions({
37-
[TASK_TYPE]: {
37+
[ANALYTICS_SYNCHRONIZATION_TASK_TYPE]: {
3838
title: 'Synchronization for the cases analytics index',
3939
createTaskRunner: (context: RunContext) => {
4040
return new AnalyticsIndexSynchronizationTaskFactory({ getESClient, logger }).create(
@@ -64,7 +64,7 @@ export async function scheduleCAISynchronizationTask({
6464
try {
6565
await taskManager.ensureScheduled({
6666
id: taskId,
67-
taskType: TASK_TYPE,
67+
taskType: ANALYTICS_SYNCHRONIZATION_TASK_TYPE,
6868
params: { sourceIndex, destIndex },
6969
schedule: SCHEDULE, // every 5 minutes
7070
state: {},

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ describe('config validation', () => {
1212
it('sets the defaults correctly', () => {
1313
expect(ConfigSchema.validate({})).toMatchInlineSnapshot(`
1414
Object {
15-
"analytics": Object {},
15+
"analytics": Object {
16+
"index": Object {
17+
"enabled": true,
18+
},
19+
},
20+
"enabled": true,
1621
"files": Object {
1722
"allowedMimeTypes": Array [
1823
"image/aces",

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ export const ConfigSchema = schema.object({
4848
}),
4949
}),
5050
analytics: schema.object({
51-
index: schema.maybe(
52-
schema.object({
53-
enabled: schema.boolean({ defaultValue: true }),
54-
})
55-
),
51+
index: schema.object({
52+
enabled: schema.boolean({ defaultValue: true }),
53+
}),
5654
}),
5755
});
5856

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function getConfig(overrides: Partial<ConfigType> = {}): ConfigType {
2929
files: { maxSize: 1, allowedMimeTypes: ALLOWED_MIME_TYPES },
3030
stack: { enabled: true },
3131
incrementalId: { enabled: true, taskIntervalMinutes: 10, taskStartDelayMinutes: 10 },
32-
analytics: {},
32+
analytics: { index: { enabled: true } },
3333
...overrides,
3434
};
3535
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export class CasePlugin
225225
if (this.caseConfig.incrementalId.enabled) {
226226
void this.incrementalIdTaskManager?.setupIncrementIdTask(plugins.taskManager, core);
227227
}
228+
228229
if (this.caseConfig.analytics.index?.enabled) {
229230
scheduleCasesAnalyticsSyncTasks({ taskManager: plugins.taskManager, logger: this.logger });
230231
createCasesAnalyticsIndexes({

0 commit comments

Comments
 (0)