[Fleet]: add log statement when deleting transform (#81927)
This commit is contained in:
parent
de4e8b05ad
commit
e3a6500854
|
@ -17,6 +17,7 @@ import { CallESAsCurrentUser } from '../../../../types';
|
|||
import { getInstallation } from '../../packages';
|
||||
import { deleteTransforms, deleteTransformRefs } from './remove';
|
||||
import { getAsset } from './common';
|
||||
import { appContextService } from '../../../app_context';
|
||||
|
||||
interface TransformInstallation {
|
||||
installationName: string;
|
||||
|
@ -29,6 +30,7 @@ export const installTransform = async (
|
|||
callCluster: CallESAsCurrentUser,
|
||||
savedObjectsClient: SavedObjectsClientContract
|
||||
) => {
|
||||
const logger = appContextService.getLogger();
|
||||
const installation = await getInstallation({
|
||||
savedObjectsClient,
|
||||
pkgName: installablePackage.name,
|
||||
|
@ -38,6 +40,9 @@ export const installTransform = async (
|
|||
previousInstalledTransformEsAssets = installation.installed_es.filter(
|
||||
({ type, id }) => type === ElasticsearchAssetType.transform
|
||||
);
|
||||
logger.info(
|
||||
`Found previous transform references:\n ${JSON.stringify(previousInstalledTransformEsAssets)}`
|
||||
);
|
||||
}
|
||||
|
||||
// delete all previous transform
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import { SavedObjectsClientContract } from 'kibana/server';
|
||||
import { CallESAsCurrentUser, ElasticsearchAssetType, EsAssetReference } from '../../../../types';
|
||||
import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../../../common/constants';
|
||||
import { appContextService } from '../../../app_context';
|
||||
|
||||
export const stopTransforms = async (transformIds: string[], callCluster: CallESAsCurrentUser) => {
|
||||
for (const transformId of transformIds) {
|
||||
|
@ -23,6 +24,8 @@ export const deleteTransforms = async (
|
|||
callCluster: CallESAsCurrentUser,
|
||||
transformIds: string[]
|
||||
) => {
|
||||
const logger = appContextService.getLogger();
|
||||
logger.info(`Deleting currently installed transform ids ${transformIds}`);
|
||||
await Promise.all(
|
||||
transformIds.map(async (transformId) => {
|
||||
// get the index the transform
|
||||
|
@ -45,14 +48,18 @@ export const deleteTransforms = async (
|
|||
path: `/_transform/${transformId}`,
|
||||
ignore: [404],
|
||||
});
|
||||
|
||||
// expect this to be 1
|
||||
for (const transform of transformResponse.transforms) {
|
||||
await callCluster('transport.request', {
|
||||
method: 'DELETE',
|
||||
path: `/${transform?.dest?.index}`,
|
||||
ignore: [404],
|
||||
});
|
||||
logger.info(`Deleted: ${transformId}`);
|
||||
if (transformResponse?.transforms) {
|
||||
// expect this to be 1
|
||||
for (const transform of transformResponse.transforms) {
|
||||
await callCluster('transport.request', {
|
||||
method: 'DELETE',
|
||||
path: `/${transform?.dest?.index}`,
|
||||
ignore: [404],
|
||||
});
|
||||
}
|
||||
} else {
|
||||
logger.warn(`cannot find transform for ${transformId}`);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { createAppContextStartContractMock } from '../../../../mocks';
|
||||
|
||||
jest.mock('../../packages/get', () => {
|
||||
return { getInstallation: jest.fn(), getInstallationObject: jest.fn() };
|
||||
});
|
||||
|
@ -21,11 +23,13 @@ import { getInstallation, getInstallationObject } from '../../packages';
|
|||
import { getAsset } from './common';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { savedObjectsClientMock } from '../../../../../../../../src/core/server/saved_objects/service/saved_objects_client.mock';
|
||||
import { appContextService } from '../../../app_context';
|
||||
|
||||
describe('test transform install', () => {
|
||||
let legacyScopedClusterClient: jest.Mocked<ILegacyScopedClusterClient>;
|
||||
let savedObjectsClient: jest.Mocked<SavedObjectsClientContract>;
|
||||
beforeEach(() => {
|
||||
appContextService.start(createAppContextStartContractMock());
|
||||
legacyScopedClusterClient = {
|
||||
callAsInternalUser: jest.fn(),
|
||||
callAsCurrentUser: jest.fn(),
|
||||
|
|
Loading…
Reference in a new issue