Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration override enabled #1833

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0ca5068
update OTEL metrics queries with the correct ss40 metrics schema
YANG-DB May 2, 2024
eba835d
Merge remote-tracking branch 'origin/main' into fix-otel-data-pep-met…
YANG-DB May 3, 2024
2bfd7f6
update OTEL integration with dev console instructions for index templ…
YANG-DB May 4, 2024
71408de
update OTEL integration with details getting started tutorial
YANG-DB May 5, 2024
afa4105
update OTEL integration with details getting started tutorial
YANG-DB May 5, 2024
5282f9a
update OTEL integration with details getting started tutorial
YANG-DB May 5, 2024
f9d474a
update OTEL integration with details getting started tutorial
YANG-DB May 5, 2024
5d066e5
update OTEL integration with details getting started tutorial
YANG-DB May 5, 2024
412077d
update OTEL integration with details getting started tutorial
YANG-DB May 6, 2024
f9df7e7
update OTEL integration with details getting started tutorial
YANG-DB May 6, 2024
3471ee4
update OTEL integration with details getting started tutorial
YANG-DB May 7, 2024
dae71d9
update OTEL integration with details getting started tutorial
YANG-DB May 8, 2024
bae4232
update OTEL integration with details getting started tutorial
YANG-DB May 17, 2024
a40f94c
Merge remote-tracking branch 'origin/main' into update-otel-integration
YANG-DB May 17, 2024
a4f8669
add override field to indicate an asset should keep its original ID i…
YANG-DB May 17, 2024
56633c5
add override field to indicate an asset should keep its original ID i…
YANG-DB May 17, 2024
0414f92
add override field to indicate an asset should keep its original ID i…
YANG-DB May 17, 2024
e1c91b4
update test
YANG-DB May 17, 2024
77361fc
Merge branch 'main' into integration-override-enabled
YANG-DB Jun 12, 2024
8910bb6
Merge branch 'main' into integration-override-enabled
YANG-DB Jul 4, 2024
08d0722
Merge branch 'main' into integration-override-enabled
YANG-DB Sep 9, 2024
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
4 changes: 3 additions & 1 deletion server/adaptors/integrations/__test__/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ describe('IntegrationInstanceBuilder', () => {
const remappedAssets = [
{
id: 'remapped-asset1',
override: false,
references: [{ id: 'remapped-ref1' }],
},
{
id: 'remapped-asset2',
override: false,
references: [{ id: 'remapped-ref2' }],
},
];
Expand Down Expand Up @@ -111,7 +113,7 @@ describe('IntegrationInstanceBuilder', () => {
// sampleIntegration.deepCheck = jest.fn().mockResolvedValue({ ok: true, value: mockTemplate });
sampleIntegration.getAssets = jest.fn().mockResolvedValue({
ok: true,
value: [{ type: 'savedObjectBundle', data: remappedAssets }],
value: [{ type: 'savedObjectBundle', override: false, data: remappedAssets }],
});
sampleIntegration.getConfig = jest.fn().mockResolvedValue({ ok: true, value: mockTemplate });

Expand Down
32 changes: 20 additions & 12 deletions server/adaptors/integrations/integrations_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface BuilderOptions {

interface SavedObject {
id: string;
override: boolean;
type: string;
attributes: { title: string };
references: Array<{ id: string }>;
Expand Down Expand Up @@ -124,8 +125,14 @@ export class IntegrationInstanceBuilder {
}
return includeWorkflows.some((w) => asset.workflows?.includes(w));
})
.map((asset) => (asset as { type: 'savedObjectBundle'; data: object[] }).data)
.flat() as SavedObject[];
.flatMap((asset) =>
(asset as { type: 'savedObjectBundle'; data: object[]; override: boolean }).data.map(
(item) => ({
...item,
override: asset.override ?? false, // default to false
})
)
) as SavedObject[];
}

remapDataSource(assets: SavedObject[], dataSource: string | undefined): SavedObject[] {
Expand All @@ -142,21 +149,22 @@ export class IntegrationInstanceBuilder {
const toRemap = assets.filter((asset) => asset.id);
const idMap = new Map<string, string>();
return toRemap.map((item) => {
if (!idMap.has(item.id)) {
idMap.set(item.id, uuidv4());
}
item.id = idMap.get(item.id)!;
for (let ref = 0; ref < item.references.length; ref++) {
const refId = item.references[ref].id;
if (!idMap.has(refId)) {
idMap.set(refId, uuidv4());
if (!item.override) {
if (!idMap.has(item.id)) {
idMap.set(item.id, uuidv4());
}
item.id = idMap.get(item.id)!;
for (let ref = 0; ref < item.references.length; ref++) {
const refId = item.references[ref].id;
if (!idMap.has(refId)) {
idMap.set(refId, uuidv4());
}
item.references[ref].id = idMap.get(refId)!;
}
item.references[ref].id = idMap.get(refId)!;
}
return item;
});
}

async postAssets(assets: SavedObjectsBulkCreateObject[]): Promise<AssetReference[]> {
try {
const response = await this.client.bulkCreate(assets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class IntegrationReader {
case 'savedObjectBundle':
resultValue.push({
type: 'savedObjectBundle',
override: asset.override,
workflows: asset.workflows,
data: JSON.parse(serializedResult.value.data),
});
Expand Down
3 changes: 2 additions & 1 deletion server/adaptors/integrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ interface IntegrationAsset {
version: string;
extension: string;
type: SupportedAssetType;
override: boolean;
workflows?: string[];
}

Expand All @@ -70,7 +71,7 @@ interface IntegrationWorkflow {
}

type ParsedIntegrationAsset =
| { type: 'savedObjectBundle'; workflows?: string[]; data: object[] }
| { type: 'savedObjectBundle'; workflows?: string[]; data: object[]; override?: boolean }
| { type: 'query'; workflows?: string[]; query: string; language: string };

interface SerializedIntegrationAsset extends IntegrationAsset {
Expand Down
1 change: 1 addition & 0 deletions server/adaptors/integrations/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const templateSchema: JSONSchemaType<IntegrationConfig> = {
name: { type: 'string' },
version: { type: 'string' },
extension: { type: 'string' },
override: { type: 'boolean', nullable: true },
type: { type: 'string' },
data: { type: 'string', nullable: true },
workflows: {
Expand Down
Loading