Skip to content

Commit

Permalink
[Reporting] Fix missing force now behaviour for v2 reports (#114516)
Browse files Browse the repository at this point in the history
* fix missing force now behaviour for v2 reports

* added jest test

* updated jest test snapshot to match removal of forceNow injection from locator params

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
jloleysens and kibanamachine authored Oct 12, 2021
1 parent 4f89393 commit afe81bb
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export { omitBlockedHeaders } from './omit_blocked_headers';
export { validateUrls } from './validate_urls';
export { generatePngObservableFactory } from './generate_png';
export { getCustomLogo } from './get_custom_logo';
export { setForceNow } from './set_force_now';

export interface TimeRangeParams {
min?: Date | string | number | null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { get } from 'lodash';
import { ReportingConfig } from '../../../config/config';
import { getFullRedirectAppUrl } from './get_full_redirect_app_url';

describe('getFullRedirectAppUrl', () => {
let config: ReportingConfig;

beforeEach(() => {
const values = {
server: {
basePath: 'test',
},
kibanaServer: {
protocol: 'http',
hostname: 'localhost',
port: '1234',
},
};
config = {
get: jest.fn((...args: string[]) => get(values, args)),
kbnConfig: {
get: jest.fn((...args: string[]) => get(values, args)),
},
};
});

test('smoke test', () => {
expect(getFullRedirectAppUrl(config, 'test', undefined)).toBe(
'http://localhost:1234/test/s/test/app/management/insightsAndAlerting/reporting/r'
);
});

test('adding forceNow', () => {
expect(getFullRedirectAppUrl(config, 'test', 'TEST with a space')).toBe(
'http://localhost:1234/test/s/test/app/management/insightsAndAlerting/reporting/r?forceNow=TEST%20with%20a%20space'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { ReportingConfig } from '../../..';
import { getRedirectAppPath } from '../../../../common/constants';
import { buildKibanaPath } from '../../../../common/build_kibana_path';

export function getFullRedirectAppUrl(config: ReportingConfig, spaceId?: string) {
export function getFullRedirectAppUrl(
config: ReportingConfig,
spaceId?: string,
forceNow?: string
) {
const [basePath, protocol, hostname, port] = [
config.kbnConfig.get('server', 'basePath'),
config.get('kibanaServer', 'protocol'),
Expand All @@ -29,5 +33,6 @@ export function getFullRedirectAppUrl(config: ReportingConfig, spaceId?: string)
hostname,
port,
pathname: path,
query: forceNow ? { forceNow } : undefined,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ test(`passes browserTimezone to generatePng`, async () => {
"warning": [Function],
},
Array [
"localhost:80undefined/app/management/insightsAndAlerting/reporting/r",
"localhost:80undefined/app/management/insightsAndAlerting/reporting/r?forceNow=test",
Object {
"id": "test",
"params": Object {
"forceNow": "test",
},
"params": Object {},
"version": "test",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
getConditionalHeaders,
omitBlockedHeaders,
generatePngObservableFactory,
setForceNow,
} from '../common';
import { getFullRedirectAppUrl } from '../common/v2/get_full_redirect_app_url';
import { TaskPayloadPNGV2 } from './types';
Expand All @@ -38,8 +37,8 @@ export const runTaskFnFactory: RunTaskFnFactory<RunTaskFn<TaskPayloadPNGV2>> =
map((decryptedHeaders) => omitBlockedHeaders(decryptedHeaders)),
map((filteredHeaders) => getConditionalHeaders(config, filteredHeaders)),
mergeMap((conditionalHeaders) => {
const url = getFullRedirectAppUrl(config, job.spaceId);
const [locatorParams] = job.locatorParams.map(setForceNow(job.forceNow));
const url = getFullRedirectAppUrl(config, job.spaceId, job.forceNow);
const [locatorParams] = job.locatorParams;

apmGetAssets?.end();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
getConditionalHeaders,
omitBlockedHeaders,
getCustomLogo,
setForceNow,
} from '../common';
import { generatePdfObservableFactory } from './lib/generate_pdf';
import { TaskPayloadPDFV2 } from './types';
Expand Down Expand Up @@ -50,7 +49,7 @@ export const runTaskFnFactory: RunTaskFnFactory<RunTaskFn<TaskPayloadPDFV2>> =
jobLogger,
job,
title,
locatorParams.map(setForceNow(job.forceNow)),
locatorParams,
browserTimezone,
conditionalHeaders,
layout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export async function generatePdfObservableFactory(reporting: ReportingCore) {
/**
* For each locator we get the relative URL to the redirect app
*/
const urls = locatorParams.map(() => getFullRedirectAppUrl(reporting.getConfig(), job.spaceId));
const urls = locatorParams.map(() =>
getFullRedirectAppUrl(reporting.getConfig(), job.spaceId, job.forceNow)
);

const screenshots$ = getScreenshots$(captureConfig, browserDriverFactory, {
logger,
urlsOrUrlLocatorTuples: zip(urls, locatorParams) as UrlOrUrlLocatorTuple[],
Expand Down

0 comments on commit afe81bb

Please sign in to comment.