Skip to content

Commit 8c9e148

Browse files
robester0403kibanamachinebhapas
authored
[Automatic_Import_V2] Add Saved Objects Service (#239451)
## Summary This PR adds: AutomaticImportSavedObjectService which manages the Integration and Data Stream saved objects. The two saved objects serves as a base service for storing information on integrations and their associated data streams. The saved object service allows for saving of progress, multiple data streams, and intermediary states. Integration and Data Stream schemas are provided. Dictates handling of CRUD in the Automatic Import environment and manages the relationships between Integration and Saved objects. Integration tests for important scenarios of using AutomaticImportSavedObjectService. ## Impact - Foundational saved object service for Automatic Import V2 to save progress of integrations and data stream coming from our agentic processes. ## Running Integration tests `yarn test:jest_integration x-pack/platform/plugins/shared/automatic_import_v2/server/integration_tests/saved_objects_service.test.ts` --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Bharat Pasupula <[email protected]> Co-authored-by: Bharat Pasupula <[email protected]>
1 parent 7a610b1 commit 8c9e148

File tree

20 files changed

+2721
-20
lines changed

20 files changed

+2721
-20
lines changed

packages/kbn-check-saved-objects-cli/current_fields.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,22 @@
309309
"title",
310310
"version"
311311
],
312+
"data_stream-config": [
313+
"created_by",
314+
"data_stream_id",
315+
"integration_id",
316+
"job_info",
317+
"job_info.job_id",
318+
"job_info.job_type",
319+
"job_info.status",
320+
"metadata",
321+
"metadata.created_at",
322+
"metadata.sample_count",
323+
"metadata.version",
324+
"result",
325+
"result.field_mapping",
326+
"result.ingest_pipeline"
327+
],
312328
"dynamic-config-overrides": [],
313329
"endpoint:unified-user-artifact-manifest": [
314330
"artifactIds",
@@ -786,6 +802,17 @@
786802
"use_space_awareness_migration_started_at",
787803
"use_space_awareness_migration_status"
788804
],
805+
"integration-config": [
806+
"created_by",
807+
"data_stream_count",
808+
"integration_id",
809+
"metadata",
810+
"metadata.created_at",
811+
"metadata.description",
812+
"metadata.title",
813+
"metadata.version",
814+
"status"
815+
],
789816
"intercept_interaction_record": [],
790817
"intercept_trigger_record": [
791818
"firstRegisteredAt",

packages/kbn-check-saved-objects-cli/current_mappings.json

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,13 @@
639639
},
640640
"observables": {
641641
"properties": {
642-
"typeKey": {
642+
"description": {
643643
"type": "keyword"
644644
},
645-
"value": {
645+
"typeKey": {
646646
"type": "keyword"
647647
},
648-
"description": {
648+
"value": {
649649
"type": "keyword"
650650
}
651651
},
@@ -1073,6 +1073,40 @@
10731073
}
10741074
}
10751075
},
1076+
"data_stream-config": {
1077+
"dynamic": false,
1078+
"properties": {
1079+
"created_by": {
1080+
"type": "keyword"
1081+
},
1082+
"data_stream_id": {
1083+
"type": "keyword"
1084+
},
1085+
"integration_id": {
1086+
"type": "keyword"
1087+
},
1088+
"job_info": {
1089+
"properties": {
1090+
"job_id": {
1091+
"type": "keyword"
1092+
},
1093+
"job_type": {
1094+
"type": "keyword"
1095+
},
1096+
"status": {
1097+
"type": "keyword"
1098+
}
1099+
},
1100+
"type": "nested"
1101+
},
1102+
"metadata": {
1103+
"properties": {}
1104+
},
1105+
"result": {
1106+
"properties": {}
1107+
}
1108+
}
1109+
},
10761110
"dynamic-config-overrides": {
10771111
"dynamic": false,
10781112
"properties": {}
@@ -2618,6 +2652,26 @@
26182652
}
26192653
}
26202654
},
2655+
"integration-config": {
2656+
"dynamic": false,
2657+
"properties": {
2658+
"created_by": {
2659+
"type": "keyword"
2660+
},
2661+
"data_stream_count": {
2662+
"type": "integer"
2663+
},
2664+
"integration_id": {
2665+
"type": "keyword"
2666+
},
2667+
"metadata": {
2668+
"properties": {}
2669+
},
2670+
"status": {
2671+
"type": "keyword"
2672+
}
2673+
}
2674+
},
26212675
"intercept_interaction_record": {
26222676
"dynamic": false,
26232677
"properties": {}

x-pack/platform/plugins/shared/automatic_import_v2/kibana.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"actions",
2121
"stackConnectors",
2222
"inference",
23+
"security"
2324
],
2425
}
2526
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { SavedObject } from '@kbn/core/server';
9+
import type {
10+
DataStreamAttributes,
11+
IntegrationAttributes,
12+
} from '../services/saved_objects/schemas/types';
13+
import {
14+
DATA_STREAM_SAVED_OBJECT_TYPE,
15+
INTEGRATION_SAVED_OBJECT_TYPE,
16+
TASK_STATUSES,
17+
} from '../services/saved_objects/constants';
18+
19+
export const mockIntegrationData: IntegrationAttributes = {
20+
integration_id: 'test-integration-id',
21+
data_stream_count: 2,
22+
created_by: 'test-user',
23+
status: TASK_STATUSES.pending,
24+
metadata: {
25+
title: 'Test Integration',
26+
description: 'A test integration',
27+
created_at: '2024-01-01T00:00:00.000Z',
28+
version: '0.0.0',
29+
},
30+
};
31+
32+
export const mockDataStreamData: DataStreamAttributes = {
33+
integration_id: 'test-integration-id',
34+
data_stream_id: 'test-data-stream-id',
35+
created_by: 'test-user',
36+
job_info: {
37+
job_id: 'test-job-id',
38+
job_type: 'test-job-type',
39+
status: TASK_STATUSES.pending,
40+
},
41+
metadata: {
42+
sample_count: 100,
43+
version: '0.0.0',
44+
created_at: '2024-01-01T00:00:00.000Z',
45+
},
46+
result: {
47+
ingest_pipeline: 'test-pipeline',
48+
field_mapping: {
49+
'test-field': 'test-value',
50+
},
51+
},
52+
};
53+
54+
export const mockSavedObject: SavedObject<IntegrationAttributes> = {
55+
id: 'test-integration-id',
56+
type: INTEGRATION_SAVED_OBJECT_TYPE,
57+
attributes: mockIntegrationData,
58+
references: [],
59+
version: '1',
60+
};
61+
62+
export const mockDataStreamSavedObject: SavedObject<DataStreamAttributes> = {
63+
id: 'test-data-stream-id',
64+
type: DATA_STREAM_SAVED_OBJECT_TYPE,
65+
attributes: mockDataStreamData,
66+
references: [],
67+
version: '1',
68+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { SecurityServiceStart } from '@kbn/core/server';
9+
10+
export const createMockSecurity = (
11+
username = 'test-user',
12+
email = '[email protected]',
13+
fullName = 'Test User',
14+
roles = ['admin']
15+
): jest.Mocked<SecurityServiceStart> => {
16+
return {
17+
authc: {
18+
getCurrentUser: jest.fn().mockReturnValue({
19+
username,
20+
email,
21+
full_name: fullName,
22+
roles,
23+
}),
24+
},
25+
audit: {
26+
asScoped: jest.fn(),
27+
withoutRequest: {
28+
enabled: false,
29+
log: jest.fn(),
30+
},
31+
},
32+
} as any;
33+
};

0 commit comments

Comments
 (0)