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

basic enhancements for import logging #196056

Merged
merged 11 commits into from
Nov 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,17 @@ describe('#importSavedObjectsFromStream', () => {
let savedObjectsClient: jest.Mocked<SavedObjectsClientContract>;
let typeRegistry: jest.Mocked<ISavedObjectTypeRegistry>;
const namespace = 'some-namespace';

const mockLog = {
kyracho marked this conversation as resolved.
Show resolved Hide resolved
trace: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
fatal: jest.fn(),
log: jest.fn(),
error: jest.fn(),
get: jest.fn(),
isLevelEnabled: jest.fn(),
};
const setupOptions = ({
createNewCopies = false,
getTypeImpl = (type: string) =>
Expand Down Expand Up @@ -102,6 +112,7 @@ describe('#importSavedObjectsFromStream', () => {
createNewCopies,
importHooks,
managed,
log: mockLog,
};
};
const createObject = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
ISavedObjectTypeRegistry,
SavedObjectsImportHook,
} from '@kbn/core-saved-objects-server';
import type { Logger } from '@kbn/logging';
import {
checkReferenceOrigins,
validateReferences,
Expand Down Expand Up @@ -59,6 +60,7 @@ export interface ImportSavedObjectsOptions {
* If provided, Kibana will apply the given option to the `managed` property.
*/
managed?: boolean;
log: Logger;
}

/**
Expand All @@ -79,7 +81,9 @@ export async function importSavedObjectsFromStream({
refresh,
compatibilityMode,
managed,
log,
}: ImportSavedObjectsOptions): Promise<SavedObjectsImportResponse> {
log.debug(`Importing with overwrite ${overwrite ? 'enabled' : 'disabled'} and size limit ${objectLimit}`);
let errorAccumulator: SavedObjectsImportFailure[] = [];
const supportedTypes = typeRegistry.getImportableAndExportableTypes().map((type) => type.name);

Expand All @@ -90,6 +94,7 @@ export async function importSavedObjectsFromStream({
supportedTypes,
managed,
});
log.debug(`Importing types: ${[...new Set(collectSavedObjectsResult.collectedObjects.map((obj) => obj.type))].join(', ')}`);
errorAccumulator = [...errorAccumulator, ...collectSavedObjectsResult.errors];
// Map of all IDs for objects that we are attempting to import, and any references that are not included in the read stream;
// each value is empty by default
Expand Down Expand Up @@ -197,7 +202,11 @@ export async function importSavedObjectsFromStream({
objects: createSavedObjectsResult.createdObjects,
importHooks,
});

if (errorAccumulator.length > 0) {
log.error(`Failed to import saved objects. ${errorAccumulator.length} errors: ${JSON.stringify(errorAccumulator)}`);
} else {
log.info(`Successfully imported ${createSavedObjectsResult.createdObjects.length} saved objects.`);
}
return {
successCount: createSavedObjectsResult.createdObjects.length,
success: errorAccumulator.length === 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class SavedObjectsImporter implements ISavedObjectsImporter {
compatibilityMode,
managed,
}: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse> {
this.#log.debug('Starting the import process');
return importSavedObjectsFromStream({
readStream,
createNewCopies,
Expand All @@ -75,7 +74,8 @@ export class SavedObjectsImporter implements ISavedObjectsImporter {
typeRegistry: this.#typeRegistry,
importHooks: this.#importHooks,
managed,
});
log: this.#log,
})
}

public resolveImportErrors({
Expand Down