Skip to content

Commit

Permalink
[8.x] Add logging to importer. Closes issue #192212 (#192234) (#195339)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [Add logging to importer. Closes issue #192212
(#192234)](#192234)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kyra
Cho","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-08T01:58:32Z","message":"Add
logging to importer. Closes issue #192212 (#192234)\n\n##
Summary\r\nHello, this closes issue #192212 by adding a custom logger to
the\r\nimporter, making debugging issues easier.\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [N/A] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[N/A]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios TODO\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed TODO\r\n- [N/A] Any UI touched in this
PR is usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [N/A] Any
UI touched in this PR does not create any new axe failures\r\n(run axe
in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[N/A] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[N/A] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[N/A] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
For maintainers\r\n\r\n- [X] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n(no
API changes)\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"c36a8943982b92afd593a521d5a0bf2de06deb01","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","💝community","v9.0.0","backport:prev-minor","v8.16.0"],"title":"Add
logging to importer. Closes issue
#192212","number":192234,"url":"https://github.com/elastic/kibana/pull/192234","mergeCommit":{"message":"Add
logging to importer. Closes issue #192212 (#192234)\n\n##
Summary\r\nHello, this closes issue #192212 by adding a custom logger to
the\r\nimporter, making debugging issues easier.\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [N/A] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[N/A]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios TODO\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed TODO\r\n- [N/A] Any UI touched in this
PR is usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [N/A] Any
UI touched in this PR does not create any new axe failures\r\n(run axe
in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[N/A] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[N/A] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[N/A] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
For maintainers\r\n\r\n- [X] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n(no
API changes)\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"c36a8943982b92afd593a521d5a0bf2de06deb01"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192234","number":192234,"mergeCommit":{"message":"Add
logging to importer. Closes issue #192212 (#192234)\n\n##
Summary\r\nHello, this closes issue #192212 by adding a custom logger to
the\r\nimporter, making debugging issues easier.\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [N/A] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[N/A]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios TODO\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed TODO\r\n- [N/A] Any UI touched in this
PR is usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [N/A] Any
UI touched in this PR does not create any new axe failures\r\n(run axe
in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[N/A] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[N/A] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[N/A] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
For maintainers\r\n\r\n- [X] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n(no
API changes)\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"c36a8943982b92afd593a521d5a0bf2de06deb01"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kyra Cho <[email protected]>
  • Loading branch information
kibanamachine and kyracho authored Oct 8, 2024
1 parent fcd831c commit 0bdfdbf
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 0bdfdbf

Please sign in to comment.