Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4226d11
CAI creation tests
adcoelho Jun 23, 2025
cb0c246
Updated snapshots
adcoelho Jun 25, 2025
86d0a2c
add activity index backfill tests
adcoelho Jun 25, 2025
7b1f51c
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jun 25, 2025
000f993
Synchronization integration tests.
adcoelho Jun 25, 2025
a30bd01
Merge remote-tracking branch 'upstream/main' into cai-integration-tests
adcoelho Jun 27, 2025
3c1cf93
test changes
adcoelho Jun 30, 2025
1948293
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jun 30, 2025
95187f8
Fix bug with config
cnasikas Jun 30, 2025
1a1be3e
Merge branch 'main' into cai-integration-tests
cnasikas Jun 30, 2025
6cfde6f
Merge branch 'cai-integration-tests' of github.com:adcoelho/kibana in…
cnasikas Jun 30, 2025
f81f440
fixed types
adcoelho Jun 30, 2025
08143b5
update snapshots
adcoelho Jul 1, 2025
e6aa3a5
Merge remote-tracking branch 'upstream/main' into cai-integration-tests
adcoelho Jul 1, 2025
ba8dd66
updated snapshots
adcoelho Jul 2, 2025
1ae167a
Merge remote-tracking branch 'upstream/main' into cai-integration-tests
adcoelho Jul 2, 2025
5eaca3f
add cleanup function
adcoelho Jul 2, 2025
470ff6a
Merge remote-tracking branch 'upstream/main' into cai-integration-tests
adcoelho Jul 2, 2025
5202401
Add missing snapshots
adcoelho Jul 3, 2025
2d64c01
Merge remote-tracking branch 'upstream/main' into cai-integration-tests
adcoelho Jul 3, 2025
79b202b
make indexes hidden
adcoelho Jul 3, 2025
5548af2
Update tests after change to hidden indexes.
adcoelho Jul 4, 2025
7654f6d
Merge remote-tracking branch 'upstream/main' into cai-integration-tests
adcoelho Jul 4, 2025
e768240
Merge branch 'main' into cai-integration-tests
adcoelho Jul 4, 2025
b4d82d7
hide indexes in serverless
adcoelho Jul 7, 2025
b637012
Merge branch 'main' into cai-integration-tests
adcoelho Jul 7, 2025
64ec6cc
Merge branch 'main' into cai-integration-tests
elasticmachine Jul 8, 2025
f5bd029
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine Jul 8, 2025
eb48c58
[Search] Fix search tests timeout failures
davismcphee Jul 8, 2025
6b73576
Merge branch 'main' into cai-integration-tests
cnasikas Jul 9, 2025
e4d77a5
Fix snapshots
cnasikas Jul 9, 2025
5987b11
Remove snapshots
cnasikas Jul 9, 2025
6b7dd82
Merge branch 'main' into cai-integration-tests
adcoelho Jul 9, 2025
3af660d
Increase timeout in specific tests.
adcoelho Jul 9, 2025
5d38fc6
skip flaky tests
adcoelho Jul 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export const DEFAULT_FEATURES: CasesFeaturesAllRequired = Object.freeze({
*/

export const CASES_TELEMETRY_TASK_NAME = 'cases-telemetry-task';
export const ANALYTICS_BACKFILL_TASK_TYPE = 'cai:cases_analytics_index_backfill';
export const ANALYTICS_SYNCHRONIZATION_TASK_TYPE = 'cai:cases_analytics_index_synchronization';

/**
* Telemetry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe('AnalyticsIndex', () => {
},
settings: {
index: {
hidden: true,
auto_expand_replicas: '0-1',
mode: 'lookup',
number_of_shards: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class AnalyticsIndex {
this.sourceIndex = sourceIndex;
this.sourceQuery = sourceQuery;
this.indexSettings = {
hidden: true,
// settings are not supported on serverless ES
...(isServerless
? {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
* 2.0.
*/

export const TASK_TYPE = 'cai:cases_analytics_index_backfill';
export const BACKFILL_RUN_AT = 60 * 1000; // milliseconds
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import type {
} from '@kbn/task-manager-plugin/server';
import type { CoreSetup, ElasticsearchClient } from '@kbn/core/server';
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { ANALYTICS_BACKFILL_TASK_TYPE } from '../../../../common/constants';
import type { CasesServerStartDependencies } from '../../../types';
import { CaseAnalyticsIndexBackfillTaskFactory } from './backfill_task_factory';
import { TASK_TYPE, BACKFILL_RUN_AT } from './constants';
import { BACKFILL_RUN_AT } from './constants';

export function registerCAIBackfillTask({
taskManager,
Expand All @@ -32,7 +33,7 @@ export function registerCAIBackfillTask({
};

taskManager.registerTaskDefinitions({
[TASK_TYPE]: {
[ANALYTICS_BACKFILL_TASK_TYPE]: {
title: 'Backfill cases analytics indexes.',
maxAttempts: 3,
createTaskRunner: (context: RunContext) => {
Expand Down Expand Up @@ -60,7 +61,7 @@ export async function scheduleCAIBackfillTask({
try {
await taskManager.ensureScheduled({
id: taskId,
taskType: TASK_TYPE,
taskType: ANALYTICS_BACKFILL_TASK_TYPE,
params: { sourceIndex, destIndex, sourceQuery },
runAt: new Date(Date.now() + BACKFILL_RUN_AT), // todo, value is short for testing but should run after 5 minutes
state: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import type {
TaskManagerStartContract,
} from '@kbn/task-manager-plugin/server';
import type { CoreSetup, ElasticsearchClient } from '@kbn/core/server';
import { ANALYTICS_SYNCHRONIZATION_TASK_TYPE } from '../../../../common/constants';
import type { CasesServerStartDependencies } from '../../../types';
import { AnalyticsIndexSynchronizationTaskFactory } from './synchronization_task_factory';

const TASK_TYPE = 'cai:cases_analytics_index_synchronization';
const SCHEDULE: IntervalSchedule = { interval: '5m' };

export function registerCAISynchronizationTask({
Expand All @@ -34,7 +34,7 @@ export function registerCAISynchronizationTask({
};

taskManager.registerTaskDefinitions({
[TASK_TYPE]: {
[ANALYTICS_SYNCHRONIZATION_TASK_TYPE]: {
title: 'Synchronization for the cases analytics index',
createTaskRunner: (context: RunContext) => {
return new AnalyticsIndexSynchronizationTaskFactory({ getESClient, logger }).create(
Expand Down Expand Up @@ -64,7 +64,7 @@ export async function scheduleCAISynchronizationTask({
try {
await taskManager.ensureScheduled({
id: taskId,
taskType: TASK_TYPE,
taskType: ANALYTICS_SYNCHRONIZATION_TASK_TYPE,
params: { sourceIndex, destIndex },
schedule: SCHEDULE, // every 5 minutes
state: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ describe('config validation', () => {
it('sets the defaults correctly', () => {
expect(ConfigSchema.validate({})).toMatchInlineSnapshot(`
Object {
"analytics": Object {},
"analytics": Object {
"index": Object {
"enabled": true,
},
},
"enabled": true,
"files": Object {
"allowedMimeTypes": Array [
Expand Down
8 changes: 3 additions & 5 deletions x-pack/platform/plugins/shared/cases/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ export const ConfigSchema = schema.object({
}),
}),
analytics: schema.object({
index: schema.maybe(
schema.object({
enabled: schema.boolean({ defaultValue: true }),
})
),
index: schema.object({
enabled: schema.boolean({ defaultValue: true }),
}),
}),
enabled: schema.boolean({ defaultValue: true }),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getConfig(overrides: Partial<ConfigType> = {}): ConfigType {
files: { maxSize: 1, allowedMimeTypes: ALLOWED_MIME_TYPES },
stack: { enabled: true },
incrementalId: { enabled: true, taskIntervalMinutes: 10, taskStartDelayMinutes: 10 },
analytics: {},
analytics: { index: { enabled: true } },
...overrides,
};
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/platform/plugins/shared/cases/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export class CasePlugin
if (this.caseConfig.incrementalId.enabled) {
void this.incrementalIdTaskManager?.setupIncrementIdTask(plugins.taskManager, core);
}

if (this.caseConfig.analytics.index?.enabled) {
scheduleCasesAnalyticsSyncTasks({ taskManager: plugins.taskManager, logger: this.logger });
createCasesAnalyticsIndexes({
Expand Down
10 changes: 10 additions & 0 deletions x-pack/platform/test/api_integration/apis/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand All @@ -89,6 +90,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand Down Expand Up @@ -116,6 +118,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand Down Expand Up @@ -159,6 +162,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand Down Expand Up @@ -196,6 +200,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand Down Expand Up @@ -258,6 +263,7 @@ export default function ({ getService }: FtrProviderContext) {
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand All @@ -277,6 +283,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand All @@ -298,6 +305,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand Down Expand Up @@ -478,6 +486,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand Down Expand Up @@ -519,6 +528,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.send({
params: {
index: 'search-api-test',
body: {
query: {
match_all: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type SuperTest from 'supertest';

import {
CAI_ACTIVITY_BACKFILL_TASK_ID,
CAI_ACTIVITY_SYNCHRONIZATION_TASK_ID,
CAI_ACTIVITY_SOURCE_INDEX,
CAI_ACTIVITY_INDEX_NAME,
CAI_ACTIVITY_SOURCE_QUERY,
} from '@kbn/cases-plugin/server/cases_analytics/activity_index/constants';
import {
CAI_ATTACHMENTS_BACKFILL_TASK_ID,
CAI_ATTACHMENTS_SYNCHRONIZATION_TASK_ID,
CAI_ATTACHMENTS_SOURCE_INDEX,
CAI_ATTACHMENTS_INDEX_NAME,
CAI_ATTACHMENTS_SOURCE_QUERY,
} from '@kbn/cases-plugin/server/cases_analytics/attachments_index/constants';
import {
CAI_CASES_BACKFILL_TASK_ID,
CAI_CASES_SYNCHRONIZATION_TASK_ID,
CAI_CASES_SOURCE_INDEX,
CAI_CASES_INDEX_NAME,
CAI_CASES_SOURCE_QUERY,
} from '@kbn/cases-plugin/server/cases_analytics/cases_index/constants';
import {
CAI_COMMENTS_BACKFILL_TASK_ID,
CAI_COMMENTS_SYNCHRONIZATION_TASK_ID,
CAI_COMMENTS_SOURCE_INDEX,
CAI_COMMENTS_INDEX_NAME,
CAI_COMMENTS_SOURCE_QUERY,
} from '@kbn/cases-plugin/server/cases_analytics/comments_index/constants';

export const runCasesBackfillTask = async (supertest: SuperTest.Agent) => {
await supertest
.post('/api/analytics_index/backfill/run_soon')
.set('kbn-xsrf', 'xxx')
.send({
taskId: CAI_CASES_BACKFILL_TASK_ID,
sourceIndex: CAI_CASES_SOURCE_INDEX,
destIndex: CAI_CASES_INDEX_NAME,
sourceQuery: JSON.stringify(CAI_CASES_SOURCE_QUERY),
})
.expect(200);
};

export const runCasesSynchronizationTask = async (supertest: SuperTest.Agent) => {
await supertest
.post('/api/analytics_index/synchronization/run_soon')
.set('kbn-xsrf', 'xxx')
.send({ taskId: CAI_CASES_SYNCHRONIZATION_TASK_ID })
.expect(200);
};

export const runAttachmentsBackfillTask = async (supertest: SuperTest.Agent) => {
await supertest
.post('/api/analytics_index/backfill/run_soon')
.set('kbn-xsrf', 'xxx')
.send({
taskId: CAI_ATTACHMENTS_BACKFILL_TASK_ID,
sourceIndex: CAI_ATTACHMENTS_SOURCE_INDEX,
destIndex: CAI_ATTACHMENTS_INDEX_NAME,
sourceQuery: JSON.stringify(CAI_ATTACHMENTS_SOURCE_QUERY),
})
.expect(200);
};

export const runAttachmentsSynchronizationTask = async (supertest: SuperTest.Agent) => {
await supertest
.post('/api/analytics_index/synchronization/run_soon')
.set('kbn-xsrf', 'xxx')
.send({ taskId: CAI_ATTACHMENTS_SYNCHRONIZATION_TASK_ID })
.expect(200);
};

export const runCommentsBackfillTask = async (supertest: SuperTest.Agent) => {
await supertest
.post('/api/analytics_index/backfill/run_soon')
.set('kbn-xsrf', 'xxx')
.send({
taskId: CAI_COMMENTS_BACKFILL_TASK_ID,
sourceIndex: CAI_COMMENTS_SOURCE_INDEX,
destIndex: CAI_COMMENTS_INDEX_NAME,
sourceQuery: JSON.stringify(CAI_COMMENTS_SOURCE_QUERY),
})
.expect(200);
};

export const runCommentsSynchronizationTask = async (supertest: SuperTest.Agent) => {
await supertest
.post('/api/analytics_index/synchronization/run_soon')
.set('kbn-xsrf', 'xxx')
.send({ taskId: CAI_COMMENTS_SYNCHRONIZATION_TASK_ID })
.expect(200);
};

export const runActivityBackfillTask = async (supertest: SuperTest.Agent) => {
await supertest
.post('/api/analytics_index/backfill/run_soon')
.set('kbn-xsrf', 'xxx')
.send({
taskId: CAI_ACTIVITY_BACKFILL_TASK_ID,
sourceIndex: CAI_ACTIVITY_SOURCE_INDEX,
destIndex: CAI_ACTIVITY_INDEX_NAME,
sourceQuery: JSON.stringify(CAI_ACTIVITY_SOURCE_QUERY),
})
.expect(200);
};

export const runActivitySynchronizationTask = async (supertest: SuperTest.Agent) => {
await supertest
.post('/api/analytics_index/synchronization/run_soon')
.set('kbn-xsrf', 'xxx')
.send({ taskId: CAI_ACTIVITY_SYNCHRONIZATION_TASK_ID })
.expect(200);
};
Original file line number Diff line number Diff line change
Expand Up @@ -904,3 +904,52 @@ export const findInternalCaseUserActions = async ({

return userActions;
};

export const deleteAllCaseAnalyticsItems = async (es: Client) => {
await Promise.all([
deleteCasesAnalytics(es),
deleteAttachmentsAnalytics(es),
deleteCommentsAnalytics(es),
deleteActivityAnalytics(es),
]);
};

export const deleteCasesAnalytics = async (es: Client): Promise<void> => {
await es.deleteByQuery({
index: '.internal.cases',
query: { match_all: {} },
wait_for_completion: true,
refresh: true,
conflicts: 'proceed',
});
};

export const deleteAttachmentsAnalytics = async (es: Client): Promise<void> => {
await es.deleteByQuery({
index: '.internal.cases-attachments',
query: { match_all: {} },
wait_for_completion: true,
refresh: true,
conflicts: 'proceed',
});
};

export const deleteCommentsAnalytics = async (es: Client): Promise<void> => {
await es.deleteByQuery({
index: '.internal.cases-comments',
query: { match_all: {} },
wait_for_completion: true,
refresh: true,
conflicts: 'proceed',
});
};

export const deleteActivityAnalytics = async (es: Client): Promise<void> => {
await es.deleteByQuery({
index: '.internal.cases-activity',
query: { match_all: {} },
wait_for_completion: true,
refresh: true,
conflicts: 'proceed',
});
};
Loading