Skip to content

Commit

Permalink
Fix screenshotting
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Nov 14, 2023
1 parent acfcad3 commit 19d789f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
1 change: 1 addition & 0 deletions packages/kbn-reporting/export_types/pdf/generate_pdf_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function generatePdfObservableV2(
getFullRedirectAppUrl(config, serverInfo, job.spaceId, job.forceNow),
locator,
]) as unknown as UrlOrUrlWithContext[];

const screenshots$ = getScreenshots({ ...options, urls }).pipe(
tap(({ metrics }) => {
if (metrics.cpu) {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-reporting/export_types/pdf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
*/

export { PdfExportType } from './printable_pdf_v2';
export { PdfV1ExportType } from './deprecated';
export { PdfV1ExportType } from './printable_pdf';
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class PdfV1ExportType extends ExportType<JobParamsPDFDeprecated, TaskPayl
apmGetAssets?.end();

apmGeneratePdf = apmTrans.startSpan('generate-pdf-pipeline', 'execute');
// make a new function that will call reporting.getScreenshots

const snapshotFn = () =>
this.startDeps.screenshotting!.getScreenshots({
format: 'pdf',
Expand All @@ -109,6 +109,7 @@ export class PdfV1ExportType extends ExportType<JobParamsPDFDeprecated, TaskPayl
headers,
layout,
});

return generatePdfObservable(snapshotFn, {
format: 'pdf',
title,
Expand Down
27 changes: 17 additions & 10 deletions packages/kbn-reporting/export_types/pdf/printable_pdf_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
REPORTING_REDIRECT_LOCATOR_STORE_KEY,
REPORTING_TRANSACTION_TYPE,
} from '@kbn/reporting-common';
import type { TaskRunResult, UrlOrUrlLocatorTuple } from '@kbn/reporting-common/types';
Expand Down Expand Up @@ -114,19 +115,25 @@ export class PdfExportType extends ExportType<JobParamsPDFV2, TaskPayloadPDFV2>
apmGetAssets?.end();

apmGeneratePdf = apmTrans.startSpan('generate-pdf-pipeline', 'execute');

const snapshotFn = () =>
this.startDeps.screenshotting!.getScreenshots({
format: 'pdf',
title,
logo,
browserTimezone,
headers,
layout,
urls: urls.map((url) =>
typeof url === 'string'
? url
: [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }]
),
});
return generatePdfObservableV2(
this.config,
this.getServerInfo(),
() =>
this.startDeps.screenshotting!.getScreenshots({
format: 'pdf',
title,
logo,
browserTimezone,
headers,
layout,
urls,
}),
snapshotFn,
payload,
locatorParams,
{
Expand Down
29 changes: 13 additions & 16 deletions packages/kbn-reporting/export_types/png/png_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
REPORTING_REDIRECT_LOCATOR_STORE_KEY,
REPORTING_TRANSACTION_TYPE,
} from '@kbn/reporting-common';
import type { LocatorParams, TaskRunResult } from '@kbn/reporting-common/types';
Expand All @@ -38,7 +39,6 @@ import {
TaskPayloadPNGV2,
} from '@kbn/reporting-export-types-png-common';
import { decryptJobHeaders, getFullRedirectAppUrl, ExportType } from '@kbn/reporting-server';
import type { Context } from '@kbn/screenshotting-plugin/server/browsers';
import { SerializableRecord } from '@kbn/utility-types';

import { generatePngObservable } from './generate_png';
Expand Down Expand Up @@ -105,27 +105,24 @@ export class PngExportType extends ExportType<JobParamsPNGV2, TaskPayloadPNGV2>
payload.forceNow
);

const [locatorParams] = payload.locatorParams as unknown as Context[];
const [locatorParams] = payload.locatorParams;

apmGetAssets?.end();
apmGeneratePng = apmTrans.startSpan('generate-png-pipeline', 'execute');

return generatePngObservable(
() =>
this.startDeps.screenshotting!.getScreenshots({
format: 'png',
headers,
layout: { ...payload.layout, id: 'preserve_layout' },
urls: [[url, locatorParams]],
}),
jobLogger,
{
const snapshotFn = () =>
this.startDeps.screenshotting!.getScreenshots({
format: 'png',
headers,
browserTimezone: payload.browserTimezone,
layout: { ...payload.layout, id: 'preserve_layout' },
urls: [[url, locatorParams]],
}
);
urls: [[url, { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: locatorParams }]],
});

return generatePngObservable(snapshotFn, jobLogger, {
headers,
browserTimezone: payload.browserTimezone,
layout: { ...payload.layout, id: 'preserve_layout' },
});
}),
tap(({ buffer }) => stream.write(buffer)),
map(({ metrics, warnings }) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ export class Screenshots {
getScreenshots(options: PdfScreenshotOptions): Observable<PdfScreenshotResult>;
getScreenshots(options: ScreenshotOptions): Observable<ScreenshotResult>;
getScreenshots(options: ScreenshotOptions): Observable<ScreenshotResult> {
console.log('urls', JSON.stringify({ urls: options.urls}));

if (this.systemHasInsufficientMemory()) {
return throwError(() => new errors.InsufficientMemoryAvailableOnCloudError());
}
Expand Down

0 comments on commit 19d789f

Please sign in to comment.