Skip to content

Commit

Permalink
Add logging to importer. Closes issue #192212 (#192234)
Browse files Browse the repository at this point in the history
## Summary
Hello, this closes issue #192212 by adding a custom logger to the
importer, making debugging issues easier.
### Checklist

Delete any items that are not applicable to this PR.

- [N/A] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [N/A]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios TODO
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed TODO
- [N/A] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [N/A] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [N/A] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [N/A] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [N/A] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### For maintainers

- [X] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
(no API changes)

---------

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
kyracho and elasticmachine authored Oct 8, 2024
1 parent 3862012 commit c36a894
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -46,6 +50,7 @@ export class SavedObjectsImporter implements ISavedObjectsImporter {
}
return hooks;
}, {} as Record<string, SavedObjectsImportHook[]>);
this.#log = logger;
}

public import({
Expand All @@ -57,6 +62,7 @@ export class SavedObjectsImporter implements ISavedObjectsImporter {
compatibilityMode,
managed,
}: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse> {
this.#log.debug('Starting the import process');
return importSavedObjectsFromStream({
readStream,
createNewCopies,
Expand All @@ -80,6 +86,7 @@ export class SavedObjectsImporter implements ISavedObjectsImporter {
retries,
managed,
}: SavedObjectsResolveImportErrorsOptions): Promise<SavedObjectsImportResponse> {
this.#log.debug('Resolving import errors');
return resolveSavedObjectsImportErrors({
readStream,
createNewCopies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export class SavedObjectsService
savedObjectsClient,
typeRegistry: this.typeRegistry,
importSizeLimit: options?.importSizeLimit ?? this.config!.maxImportExportSize,
logger: this.logger.get('importer'),
}),
getTypeRegistry: () => this.typeRegistry,
getDefaultIndex: () => MAIN_SAVED_OBJECT_INDEX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import supertest from 'supertest';
import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server';
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';
import type { ICoreUsageStatsClient } from '@kbn/core-usage-data-base-server-internal';
import type { Logger, LogLevelId } from '@kbn/logging';
import {
coreUsageStatsClientMock,
coreUsageDataServiceMock,
Expand Down Expand Up @@ -56,6 +57,17 @@ describe(`POST ${URL}`, () => {
references: [],
managed: false,
};
const mockLogger: jest.Mocked<Logger> = {
debug: jest.fn(),
info: jest.fn(),
error: jest.fn(),
warn: jest.fn(),
trace: jest.fn(),
fatal: jest.fn(),
log: jest.fn(),
isLevelEnabled: jest.fn((level: LogLevelId) => true),
get: jest.fn(() => mockLogger),
};

beforeEach(async () => {
({ server, httpSetup, handlerContext } = await setupServer());
Expand All @@ -76,6 +88,7 @@ describe(`POST ${URL}`, () => {
savedObjectsClient,
typeRegistry: handlerContext.savedObjects.typeRegistry,
importSizeLimit: 10000,
logger: mockLogger,
});
handlerContext.savedObjects.getImporter = jest
.fn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jest.mock('uuid');
import supertest from 'supertest';
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';
import type { ICoreUsageStatsClient } from '@kbn/core-usage-data-base-server-internal';
import type { Logger, LogLevelId } from '@kbn/logging';
import {
coreUsageStatsClientMock,
coreUsageDataServiceMock,
Expand Down Expand Up @@ -61,6 +62,17 @@ describe(`POST ${URL}`, () => {
references: [],
managed: false,
};
const mockLogger: jest.Mocked<Logger> = {
debug: jest.fn(),
info: jest.fn(),
error: jest.fn(),
warn: jest.fn(),
trace: jest.fn(),
fatal: jest.fn(),
log: jest.fn(),
isLevelEnabled: jest.fn((level: LogLevelId) => true),
get: jest.fn(() => mockLogger),
};

beforeEach(async () => {
({ server, httpSetup, handlerContext } = await setupServer());
Expand All @@ -82,6 +94,7 @@ describe(`POST ${URL}`, () => {
savedObjectsClient,
typeRegistry: handlerContext.savedObjects.typeRegistry,
importSizeLimit: 10000,
logger: mockLogger,
});

handlerContext.savedObjects.getImporter = jest
Expand Down

0 comments on commit c36a894

Please sign in to comment.