Skip to content

Commit

Permalink
[Fleet]: add log statement when deleting transform (elastic#81927)
Browse files Browse the repository at this point in the history
[Fleet]: add log statement when deleting transform
  • Loading branch information
nnamdifrankie authored Oct 28, 2020
1 parent 2a4337e commit f88c664
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,7 @@ export const installTransform = async (
callCluster: CallESAsCurrentUser,
savedObjectsClient: SavedObjectsClientContract
) => {
const logger = appContextService.getLogger();
const installation = await getInstallation({
savedObjectsClient,
pkgName: installablePackage.name,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,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
Expand All @@ -47,7 +49,7 @@ export const deleteTransforms = async (
path: `/_transform/${transformId}`,
ignore: [404],
});

logger.info(`Deleted: ${transformId}`);
if (transformResponse?.transforms) {
// expect this to be 1
for (const transform of transformResponse.transforms) {
Expand All @@ -58,7 +60,7 @@ export const deleteTransforms = async (
});
}
} else {
appContextService.getLogger().warn(`cannot find transform for ${transformId}`);
logger.warn(`cannot find transform for ${transformId}`);
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
});
Expand All @@ -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(),
Expand Down

0 comments on commit f88c664

Please sign in to comment.