-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add logging to importer. Closes issue #192212 #192234
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e5111ac
Add logging to importer
kyracho 6530626
Merge branch 'elastic:main' into add-logging-to-importer
kyracho d909a11
change saved_objects_importer.ts
kyracho 0c9f032
change saved_objects_importer.ts
kyracho 30c29dc
Merge branch 'main' into add-logging-to-importer
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
import type { SavedObjectsImportResponse } from '@kbn/core-saved-objects-common'; | ||
import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; | ||
import type { Logger } from '@kbn/logging'; | ||
import type { | ||
ISavedObjectTypeRegistry, | ||
ISavedObjectsImporter, | ||
|
@@ -27,15 +28,18 @@ export class SavedObjectsImporter implements ISavedObjectsImporter { | |
readonly #typeRegistry: ISavedObjectTypeRegistry; | ||
readonly #importSizeLimit: number; | ||
readonly #importHooks: Record<string, SavedObjectsImportHook[]>; | ||
readonly #log: Logger; | ||
|
||
constructor({ | ||
savedObjectsClient, | ||
typeRegistry, | ||
importSizeLimit, | ||
logger, | ||
}: { | ||
savedObjectsClient: SavedObjectsClientContract; | ||
typeRegistry: ISavedObjectTypeRegistry; | ||
importSizeLimit: number; | ||
logger: Logger; | ||
}) { | ||
this.#savedObjectsClient = savedObjectsClient; | ||
this.#typeRegistry = typeRegistry; | ||
|
@@ -46,9 +50,10 @@ export class SavedObjectsImporter implements ISavedObjectsImporter { | |
} | ||
return hooks; | ||
}, {} as Record<string, SavedObjectsImportHook[]>); | ||
this.#log = logger; | ||
} | ||
|
||
public import({ | ||
public async import({ | ||
readStream, | ||
createNewCopies, | ||
namespace, | ||
|
@@ -57,40 +62,56 @@ export class SavedObjectsImporter implements ISavedObjectsImporter { | |
compatibilityMode, | ||
managed, | ||
}: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse> { | ||
return importSavedObjectsFromStream({ | ||
readStream, | ||
createNewCopies, | ||
namespace, | ||
overwrite, | ||
refresh, | ||
compatibilityMode, | ||
objectLimit: this.#importSizeLimit, | ||
savedObjectsClient: this.#savedObjectsClient, | ||
typeRegistry: this.#typeRegistry, | ||
importHooks: this.#importHooks, | ||
managed, | ||
}); | ||
this.#log.debug('Starting the import process'); | ||
try { | ||
const result = await importSavedObjectsFromStream({ | ||
readStream, | ||
createNewCopies, | ||
namespace, | ||
overwrite, | ||
refresh, | ||
compatibilityMode, | ||
objectLimit: this.#importSizeLimit, | ||
savedObjectsClient: this.#savedObjectsClient, | ||
typeRegistry: this.#typeRegistry, | ||
importHooks: this.#importHooks, | ||
managed, | ||
}); | ||
this.#log.info(`Successfully imported ${result.successCount} objects`); | ||
return result; | ||
} catch (error) { | ||
this.#log.error('Import failed', error); | ||
throw error; | ||
} | ||
} | ||
|
||
public resolveImportErrors({ | ||
public async resolveImportErrors({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can't 'simply' change this.... |
||
readStream, | ||
createNewCopies, | ||
compatibilityMode, | ||
namespace, | ||
retries, | ||
managed, | ||
}: SavedObjectsResolveImportErrorsOptions): Promise<SavedObjectsImportResponse> { | ||
return resolveSavedObjectsImportErrors({ | ||
readStream, | ||
createNewCopies, | ||
compatibilityMode, | ||
namespace, | ||
retries, | ||
objectLimit: this.#importSizeLimit, | ||
savedObjectsClient: this.#savedObjectsClient, | ||
typeRegistry: this.#typeRegistry, | ||
importHooks: this.#importHooks, | ||
managed, | ||
}); | ||
this.#log.debug('Resolving import errors'); | ||
try { | ||
const result = await resolveSavedObjectsImportErrors({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar comment as for |
||
readStream, | ||
createNewCopies, | ||
compatibilityMode, | ||
namespace, | ||
retries, | ||
objectLimit: this.#importSizeLimit, | ||
savedObjectsClient: this.#savedObjectsClient, | ||
typeRegistry: this.#typeRegistry, | ||
importHooks: this.#importHooks, | ||
managed, | ||
}); | ||
this.#log.info(`Resolved errors for ${result.successCount} objects`); | ||
return result; | ||
} catch (error) { | ||
this.#log.error('Error resolving import errors', error); | ||
throw error; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awaiting a resolved promise from
importSavedObjectsFromStream
is a problem when importing many saved objects and can cause Kibana to run out of memory.import shouldn't await on
importSavedObjectsFromStream
, we have to stick with calling the method directly.I'd rather move the log line to before returning
importSavedObjectsFromStream
and revert the other changes here,There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See node streams for more info