Skip to content

Commit 9e9a48b

Browse files
78024: move transform out of dataset (#78216)
* 78024: move transform out of dataset * Change index prefix * 78024: fix tests, remove vestiges * 78024: remove index defined in the transform when transform is removed. * 78024: clean up * 78024: fix build * 78024: add comment * 78024: remove test I added * 78024: more removal, will add in next PR Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent f73bc48 commit 9e9a48b

File tree

11 files changed

+154
-107
lines changed

11 files changed

+154
-107
lines changed

x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/transform/install.ts

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { SavedObjectsClientContract } from 'kibana/server';
99
import { saveInstalledEsRefs } from '../../packages/install';
1010
import * as Registry from '../../registry';
1111
import {
12-
Dataset,
1312
ElasticsearchAssetType,
1413
EsAssetReference,
1514
RegistryPackage,
@@ -24,12 +23,7 @@ interface TransformInstallation {
2423
content: string;
2524
}
2625

27-
interface TransformPathDataset {
28-
path: string;
29-
dataset: Dataset;
30-
}
31-
32-
export const installTransformForDataset = async (
26+
export const installTransform = async (
3327
registryPackage: RegistryPackage,
3428
paths: string[],
3529
callCluster: CallESAsCurrentUser,
@@ -51,53 +45,32 @@ export const installTransformForDataset = async (
5145
callCluster,
5246
previousInstalledTransformEsAssets.map((asset) => asset.id)
5347
);
54-
// install the latest dataset
55-
const datasets = registryPackage.datasets;
56-
if (!datasets?.length) return [];
57-
const installNameSuffix = `${registryPackage.version}`;
5848

49+
const installNameSuffix = `${registryPackage.version}`;
5950
const transformPaths = paths.filter((path) => isTransform(path));
6051
let installedTransforms: EsAssetReference[] = [];
6152
if (transformPaths.length > 0) {
62-
const transformPathDatasets = datasets.reduce<TransformPathDataset[]>((acc, dataset) => {
63-
transformPaths.forEach((path) => {
64-
if (isDatasetTransform(path, dataset.path)) {
65-
acc.push({ path, dataset });
66-
}
53+
const transformRefs = transformPaths.reduce<EsAssetReference[]>((acc, path) => {
54+
acc.push({
55+
id: getTransformNameForInstallation(registryPackage, path, installNameSuffix),
56+
type: ElasticsearchAssetType.transform,
6757
});
58+
6859
return acc;
6960
}, []);
7061

71-
const transformRefs = transformPathDatasets.reduce<EsAssetReference[]>(
72-
(acc, transformPathDataset) => {
73-
if (transformPathDataset) {
74-
acc.push({
75-
id: getTransformNameForInstallation(transformPathDataset, installNameSuffix),
76-
type: ElasticsearchAssetType.transform,
77-
});
78-
}
79-
return acc;
80-
},
81-
[]
82-
);
83-
8462
// get and save transform refs before installing transforms
8563
await saveInstalledEsRefs(savedObjectsClient, registryPackage.name, transformRefs);
8664

87-
const transforms: TransformInstallation[] = transformPathDatasets.map(
88-
(transformPathDataset: TransformPathDataset) => {
89-
return {
90-
installationName: getTransformNameForInstallation(
91-
transformPathDataset,
92-
installNameSuffix
93-
),
94-
content: getAsset(transformPathDataset.path).toString('utf-8'),
95-
};
96-
}
97-
);
65+
const transforms: TransformInstallation[] = transformPaths.map((path: string) => {
66+
return {
67+
installationName: getTransformNameForInstallation(registryPackage, path, installNameSuffix),
68+
content: getAsset(path).toString('utf-8'),
69+
};
70+
});
9871

9972
const installationPromises = transforms.map(async (transform) => {
100-
return installTransform({ callCluster, transform });
73+
return handleTransformInstall({ callCluster, transform });
10174
});
10275

10376
installedTransforms = await Promise.all(installationPromises).then((results) => results.flat());
@@ -123,20 +96,10 @@ export const installTransformForDataset = async (
12396

12497
const isTransform = (path: string) => {
12598
const pathParts = Registry.pathParts(path);
126-
return pathParts.type === ElasticsearchAssetType.transform;
99+
return !path.endsWith('/') && pathParts.type === ElasticsearchAssetType.transform;
127100
};
128101

129-
const isDatasetTransform = (path: string, datasetName: string) => {
130-
const pathParts = Registry.pathParts(path);
131-
return (
132-
!path.endsWith('/') &&
133-
pathParts.type === ElasticsearchAssetType.transform &&
134-
pathParts.dataset !== undefined &&
135-
datasetName === pathParts.dataset
136-
);
137-
};
138-
139-
async function installTransform({
102+
async function handleTransformInstall({
140103
callCluster,
141104
transform,
142105
}: {
@@ -160,9 +123,12 @@ async function installTransform({
160123
}
161124

162125
const getTransformNameForInstallation = (
163-
transformDataset: TransformPathDataset,
126+
registryPackage: RegistryPackage,
127+
path: string,
164128
suffix: string
165129
) => {
166-
const filename = transformDataset?.path.split('/')?.pop()?.split('.')[0];
167-
return `${transformDataset.dataset.type}-${transformDataset.dataset.name}-${filename}-${suffix}`;
130+
const pathPaths = path.split('/');
131+
const filename = pathPaths?.pop()?.split('.')[0];
132+
const folderName = pathPaths?.pop();
133+
return `${registryPackage.name}.${folderName}-${filename}-${suffix}`;
168134
};

x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/transform/remove.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,35 @@ export const deleteTransforms = async (
2525
) => {
2626
await Promise.all(
2727
transformIds.map(async (transformId) => {
28+
// get the index the transform
29+
const transformResponse: {
30+
count: number;
31+
transforms: Array<{
32+
dest: {
33+
index: string;
34+
};
35+
}>;
36+
} = await callCluster('transport.request', {
37+
method: 'GET',
38+
path: `/_transform/${transformId}`,
39+
});
40+
2841
await stopTransforms([transformId], callCluster);
2942
await callCluster('transport.request', {
3043
method: 'DELETE',
3144
query: 'force=true',
3245
path: `/_transform/${transformId}`,
3346
ignore: [404],
3447
});
48+
49+
// expect this to be 1
50+
for (const transform of transformResponse.transforms) {
51+
await callCluster('transport.request', {
52+
method: 'DELETE',
53+
path: `/${transform?.dest?.index}`,
54+
ignore: [404],
55+
});
56+
}
3557
})
3658
);
3759
};

0 commit comments

Comments
 (0)