Skip to content

Commit

Permalink
[Screenshotting/Reporting] Remove server side i18n in logs (#124003) (#…
Browse files Browse the repository at this point in the history
…124924)

* removed unnecessary i18n

* .message instead of .toString in jest snapshots

Co-authored-by: Kibana Machine <[email protected]>
(cherry picked from commit 5310c64)
  • Loading branch information
jloleysens authored Feb 8, 2022
1 parent 5134318 commit 708e1ba
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { ByteSizeValue } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { IUiSettingsClient } from 'kibana/server';
import { createEscapeValue } from '../../../../../../../src/plugins/data/common';
import { ReportingConfig } from '../../../';
Expand Down Expand Up @@ -49,11 +48,7 @@ export const getExportSettings = async (
if (setTimezone === 'Browser') {
// if `Browser`, hardcode it to 'UTC' so the export has data that makes sense
logger.warn(
i18n.translate('xpack.reporting.exportTypes.csv.executeJob.dateFormateSetting', {
defaultMessage:
'Kibana Advanced Setting "{dateFormatTimezone}" is set to "Browser". Dates will be formatted as UTC to avoid ambiguity.',
values: { dateFormatTimezone: 'dateFormat:tz' },
})
`Kibana Advanced Setting "dateFormat:tz" is set to "Browser". Dates will be formatted as UTC to avoid ambiguity.`
);
setTimezone = 'UTC';
}
Expand Down
23 changes: 3 additions & 20 deletions x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import { map, truncate } from 'lodash';
import open from 'opn';
import puppeteer, { ElementHandle, EvaluateFn, Page, SerializableOrJSHandle } from 'puppeteer';
Expand Down Expand Up @@ -92,10 +91,7 @@ const WAIT_FOR_DELAY_MS: number = 100;

function getDisallowedOutgoingUrlError(interceptedUrl: string) {
return new Error(
i18n.translate('xpack.screenshotting.chromiumDriver.disallowedOutgoingUrl', {
defaultMessage: `Received disallowed outgoing URL: "{interceptedUrl}". Failing the request and closing the browser.`,
values: { interceptedUrl },
})
`Received disallowed outgoing URL: "${interceptedUrl}". Failing the request and closing the browser.`
);
}

Expand Down Expand Up @@ -323,28 +319,15 @@ export class HeadlessChromiumDriver {
headers,
});
} catch (err) {
logger.error(
i18n.translate(
'xpack.screenshotting.chromiumDriver.failedToCompleteRequestUsingHeaders',
{
defaultMessage: 'Failed to complete a request using headers: {error}',
values: { error: err },
}
)
);
logger.error(`Failed to complete a request using headers: ${err.message}`);
}
} else {
const loggedUrl = isData ? this.truncateUrl(interceptedUrl) : interceptedUrl;
logger.trace(`No custom headers for ${loggedUrl}`);
try {
await client.send('Fetch.continueRequest', { requestId });
} catch (err) {
logger.error(
i18n.translate('xpack.screenshotting.chromiumDriver.failedToCompleteRequest', {
defaultMessage: 'Failed to complete a request: {error}',
values: { error: err },
})
);
logger.error(`Failed to complete a request: ${err.message}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import { getDataPath } from '@kbn/utils';
import { spawn } from 'child_process';
import del from 'del';
Expand Down Expand Up @@ -305,10 +304,7 @@ export class HeadlessChromiumDriverFactory {
const uncaughtExceptionPageError$ = Rx.fromEvent<Error>(page, 'pageerror').pipe(
map((err) => {
logger.warn(
i18n.translate('xpack.screenshotting.browsers.chromium.pageErrorDetected', {
defaultMessage: `Reporting encountered an uncaught error on the page that will be ignored: {err}`,
values: { err: err.toString() },
})
`Reporting encountered an uncaught error on the page that will be ignored: ${err.message}`
);
})
);
Expand Down Expand Up @@ -350,12 +346,7 @@ export class HeadlessChromiumDriverFactory {
getPageExit(browser: Browser, page: Page) {
const pageError$ = Rx.fromEvent<Error>(page, 'error').pipe(
mergeMap((err) => {
return Rx.throwError(
i18n.translate('xpack.screenshotting.browsers.chromium.errorDetected', {
defaultMessage: 'Reporting encountered an error: {err}',
values: { err: err.toString() },
})
);
return Rx.throwError(`Reporting encountered an error: ${err.toString()}`);
})
);

Expand Down Expand Up @@ -383,19 +374,15 @@ export class HeadlessChromiumDriverFactory {
const exit$ = Rx.fromEvent(browserProcess, 'exit').pipe(
map((code) => {
this.logger.error(`Browser exited abnormally, received code: ${code}`);
return i18n.translate('xpack.screenshotting.diagnostic.browserCrashed', {
defaultMessage: `Browser exited abnormally during startup`,
});
return `Browser exited abnormally during startup`;
})
);

const error$ = Rx.fromEvent(browserProcess, 'error').pipe(
map((err) => {
this.logger.error(`Browser process threw an error on startup`);
this.logger.error(err as string | Error);
return i18n.translate('xpack.screenshotting.diagnostic.browserErrored', {
defaultMessage: `Browser process threw an error on startup`,
});
return `Browser process threw an error on startup`;
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';

export const getChromiumDisconnectedError = () =>
new Error(
i18n.translate('xpack.screenshotting.screencapture.browserWasClosed', {
defaultMessage: 'Browser was closed unexpectedly! Check the server logs for more info.',
})
);
new Error('Browser was closed unexpectedly! Check the server logs for more info.');

export { ChromiumArchivePaths } from './paths';
export type { ConditionalHeaders } from './driver';
Expand Down
21 changes: 3 additions & 18 deletions x-pack/plugins/screenshotting/server/config/create_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import { cloneDeep, set, upperFirst } from 'lodash';
import type { Logger } from 'src/core/server';
import { getDefaultChromiumSandboxDisabled } from './default_chromium_sandbox_disabled';
Expand All @@ -27,29 +26,15 @@ export async function createConfig(parentLogger: Logger, config: ConfigType) {
const { os, disableSandbox } = await getDefaultChromiumSandboxDisabled();
const osName = [os.os, os.dist, os.release].filter(Boolean).map(upperFirst).join(' ');

logger.debug(
i18n.translate('xpack.screenshotting.serverConfig.osDetected', {
defaultMessage: `Running on OS: '{osName}'`,
values: { osName },
})
);
logger.debug(`Running on OS: '${osName}'`);

if (disableSandbox === true) {
logger.warn(
i18n.translate('xpack.screenshotting.serverConfig.autoSet.sandboxDisabled', {
defaultMessage: `Chromium sandbox provides an additional layer of protection, but is not supported for {osName} OS. Automatically setting '{configKey}: true'.`,
values: {
configKey: 'xpack.screenshotting.capture.browser.chromium.disableSandbox',
osName,
},
})
`Chromium sandbox provides an additional layer of protection, but is not supported for ${osName} OS. Automatically setting 'xpack.screenshotting.capture.browser.chromium.disableSandbox: true'.`
);
} else {
logger.info(
i18n.translate('xpack.screenshotting.serverConfig.autoSet.sandboxEnabled', {
defaultMessage: `Chromium sandbox provides an additional layer of protection, and is supported for {osName} OS. Automatically enabling Chromium sandbox.`,
values: { osName },
})
`Chromium sandbox provides an additional layer of protection, and is supported for ${osName} OS. Automatically enabling Chromium sandbox.`
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import apm from 'elastic-apm-node';
import type { Logger } from 'src/core/server';
import type { HeadlessChromiumDriver } from '../browsers';
Expand Down Expand Up @@ -83,9 +82,7 @@ export const getElementPositionAndAttributes = async (

if (!elementsPositionAndAttributes?.length) {
throw new Error(
i18n.translate('xpack.screenshotting.screencapture.noElements', {
defaultMessage: `An error occurred while reading the page for visualization panels: no panels were found.`,
})
`An error occurred while reading the page for visualization panels: no panels were found.`
);
}
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import apm from 'elastic-apm-node';
import type { Logger } from 'src/core/server';
import type { HeadlessChromiumDriver } from '../browsers';
Expand All @@ -22,11 +21,7 @@ export const getNumberOfItems = async (
const { renderComplete: renderCompleteSelector, itemsCountAttribute } = layout.selectors;
let itemsCount: number;

logger.debug(
i18n.translate('xpack.screenshotting.screencapture.logWaitingForElements', {
defaultMessage: 'waiting for elements or items count attribute; or not found to interrupt',
})
);
logger.debug('waiting for elements or items count attribute; or not found to interrupt');

try {
// the dashboard is using the `itemsCountAttribute` attribute to let us
Expand Down Expand Up @@ -62,10 +57,7 @@ export const getNumberOfItems = async (
} catch (error) {
logger.error(error);
throw new Error(
i18n.translate('xpack.screenshotting.screencapture.readVisualizationsError', {
defaultMessage: `An error occurred when trying to read the page for visualization panel info: {error}`,
values: { error },
})
`An error occurred when trying to read the page for visualization panel info: ${error.message}`
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import apm from 'elastic-apm-node';
import type { Logger } from 'src/core/server';
import type { HeadlessChromiumDriver } from '../browsers';
Expand Down Expand Up @@ -43,10 +42,7 @@ export const getRenderErrors = async (

if (errorsFound?.length) {
logger.warn(
i18n.translate('xpack.screenshotting.screencapture.renderErrorsFound', {
defaultMessage: 'Found {count} error messages. See report object for more information.',
values: { count: errorsFound.length },
})
`Found ${errorsFound.length} error messages. See report object for more information.`
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import apm from 'elastic-apm-node';
import type { Logger } from 'src/core/server';
import type { HeadlessChromiumDriver } from '../browsers';
Expand Down Expand Up @@ -33,11 +32,7 @@ export const getScreenshots = async (
logger: Logger,
elementsPositionAndAttributes: ElementsPositionAndAttribute[]
): Promise<Screenshot[]> => {
logger.info(
i18n.translate('xpack.screenshotting.screencapture.takingScreenshots', {
defaultMessage: `taking screenshots`,
})
);
logger.info(`taking screenshots`);

const screenshots: Screenshot[] = [];

Expand All @@ -60,14 +55,7 @@ export const getScreenshots = async (
span?.end();
}

logger.info(
i18n.translate('xpack.screenshotting.screencapture.screenshotsTaken', {
defaultMessage: `screenshots taken: {numScreenhots}`,
values: {
numScreenhots: screenshots.length,
},
})
);
logger.info(`screenshots taken: ${screenshots.length}`);

return screenshots;
};
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe('Screenshot Observable Pipeline', () => {
},
},
],
"error": [Error: The "wait for elements" phase encountered an error: Error: An error occurred when trying to read the page for visualization panel info: Error: Mock error!],
"error": [Error: The "wait for elements" phase encountered an error: Error: An error occurred when trying to read the page for visualization panel info: Mock error!],
"screenshots": Array [
Object {
"data": Object {
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('Screenshot Observable Pipeline', () => {
},
},
],
"error": [Error: The "wait for elements" phase encountered an error: Error: An error occurred when trying to read the page for visualization panel info: Error: Mock error!],
"error": [Error: The "wait for elements" phase encountered an error: Error: An error occurred when trying to read the page for visualization panel info: Mock error!],
"screenshots": Array [
Object {
"data": Object {
Expand Down
12 changes: 2 additions & 10 deletions x-pack/plugins/screenshotting/server/screenshots/inject_css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import fs from 'fs';
import { promisify } from 'util';
import apm from 'elastic-apm-node';
Expand All @@ -22,11 +21,7 @@ export const injectCustomCss = async (
layout: Layout
): Promise<void> => {
const span = apm.startSpan('inject_css', 'correction');
logger.debug(
i18n.translate('xpack.screenshotting.screencapture.injectingCss', {
defaultMessage: 'injecting custom css',
})
);
logger.debug('injecting custom css');

const filePath = layout.getCssOverridesPath();
if (!filePath) {
Expand All @@ -50,10 +45,7 @@ export const injectCustomCss = async (
} catch (err) {
logger.error(err);
throw new Error(
i18n.translate('xpack.screenshotting.screencapture.injectCss', {
defaultMessage: `An error occurred when trying to update Kibana CSS for reporting. {error}`,
values: { error: err },
})
`An error occurred when trying to update Kibana CSS for reporting. ${err.message}`
);
}

Expand Down
8 changes: 1 addition & 7 deletions x-pack/plugins/screenshotting/server/screenshots/open_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import apm from 'elastic-apm-node';
import type { Logger } from 'src/core/server';
import type { Layout } from 'src/plugins/screenshot_mode/common';
Expand Down Expand Up @@ -50,12 +49,7 @@ export const openUrl = async (
);
} catch (err) {
logger.error(err);
throw new Error(
i18n.translate('xpack.screenshotting.screencapture.couldntLoadKibana', {
defaultMessage: `An error occurred when trying to open the Kibana URL: {error}`,
values: { error: err },
})
);
throw new Error(`An error occurred when trying to open the Kibana URL: ${err.message}`);
}

span?.end();
Expand Down
Loading

0 comments on commit 708e1ba

Please sign in to comment.