Skip to content

Commit

Permalink
[Reporting] Add a bit more logging and a few more logging level promo…
Browse files Browse the repository at this point in the history
…tions (#43415)
  • Loading branch information
tsullivan committed Aug 16, 2019
1 parent 0a8926f commit 85cc838
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as Rx from 'rxjs';
import { i18n } from '@kbn/i18n';
import { mergeMap, catchError, map, takeUntil } from 'rxjs/operators';
import { oncePerServer } from '../../../../server/lib/once_per_server';
import { oncePerServer } from '../../../../server/lib';
import { generatePngObservableFactory } from '../lib/generate_png';
import {
decryptJobHeaders,
Expand Down Expand Up @@ -45,7 +45,8 @@ function executeJobFn(server) {
content_type: 'image/png',
content: buffer.toString('base64'),
size: buffer.byteLength,
}))
})),
catchError(err => Rx.throwError(err))
);

const stop$ = Rx.fromEventPattern(cancellationToken.on);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as Rx from 'rxjs';
import { mergeMap, catchError, map, takeUntil } from 'rxjs/operators';
import { i18n } from '@kbn/i18n';
import { oncePerServer } from '../../../../server/lib/once_per_server';
import { oncePerServer } from '../../../../server/lib';
import { generatePdfObservableFactory } from '../lib/generate_pdf';
import { compatibilityShimFactory } from './compatibility_shim';
import {
Expand Down Expand Up @@ -55,7 +55,8 @@ function executeJobFn(server) {
content_type: 'application/pdf',
content: buffer.toString('base64'),
size: buffer.byteLength,
}))
})),
catchError(err => Rx.throwError(err))
);

const stop$ = Rx.fromEventPattern(cancellationToken.on);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ import { HeadlessChromiumDriverFactory } from './driver_factory';
export { paths } from './paths';

export async function createDriverFactory(binaryPath, logger, browserConfig, queueTimeout) {
if (browserConfig.disableSandbox) {
logger.warning(`Enabling the Chromium sandbox provides an additional layer of protection.`);
}

return new HeadlessChromiumDriverFactory(binaryPath, logger, browserConfig, queueTimeout);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,17 @@ export async function createBrowserDriverFactory(server: KbnServer) {
const BROWSER_CONFIG = CAPTURE_CONFIG.browser[BROWSER_TYPE];
const REPORTING_TIMEOUT = config.get('xpack.reporting.queue.timeout');

if (BROWSER_CONFIG.disableSandbox) {
logger.warning(`Enabling the Chromium sandbox provides an additional layer of protection.`);
}
if (BROWSER_AUTO_DOWNLOAD) {
await ensureBrowserDownloaded(BROWSER_TYPE);
}

try {
const browser = BROWSERS_BY_TYPE[BROWSER_TYPE];
const browser = BROWSERS_BY_TYPE[BROWSER_TYPE]; // NOTE: unecessary indirection: this is always a Chromium browser object, as of PhantomJS removal
const { binaryPath } = await installBrowser(logger, browser, DATA_DIR);
const browserDriverFactory = browser.createDriverFactory(
binaryPath,
logger,
BROWSER_CONFIG,
REPORTING_TIMEOUT
);
logger.debug(`Browser installed at ${browserDriverFactory.binaryPath}`);
return browserDriverFactory;
return browser.createDriverFactory(binaryPath, logger, BROWSER_CONFIG, REPORTING_TIMEOUT);
} catch (error) {
if (error.cause && ['EACCES', 'EEXIST'].includes(error.cause.code)) {
logger.error(
Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/reporting/server/browsers/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function installBrowser(
await chmod(binaryPath, '755');
}

logger.debug(`Browser installed at ${binaryPath}`);
return {
binaryPath,
};
Expand Down
5 changes: 3 additions & 2 deletions x-pack/legacy/plugins/reporting/server/lib/enqueue_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function enqueueJobFn(server) {
const browserType = config.get('xpack.reporting.capture.browser.type');
const exportTypesRegistry = server.plugins.reporting.exportTypesRegistry;

return async function enqueueJob(exportTypeId, jobParams, user, headers, request) {
return async function enqueueJob(parentLogger, exportTypeId, jobParams, user, headers, request) {
const logger = parentLogger.clone(['queue-job']);
const exportType = exportTypesRegistry.getById(exportTypeId);
const createJob = exportType.createJobFactory(server);
const payload = await createJob(jobParams, headers, request);
Expand All @@ -31,7 +32,7 @@ function enqueueJobFn(server) {

job.on(esqueueEvents.EVENT_JOB_CREATED, (createdJob) => {
if (createdJob.id === job.id) {
server.log(['reporting', 'esqueue', 'info'], `Successfully queued job: ${createdJob.id}`);
logger.info(`Successfully queued job: ${createdJob.id}`);
resolve(job);
}
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/reporting/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function registerRoutes(server: KbnServer, logger: Logger) {
const user = request.pre.user;
const headers = request.headers;

const job = await enqueueJob(exportTypeId, jobParams, user, headers, request);
const job = await enqueueJob(logger, exportTypeId, jobParams, user, headers, request);

// return the queue's job information
const jobJson = job.toJSON();
Expand Down

0 comments on commit 85cc838

Please sign in to comment.