Skip to content

Commit

Permalink
[Reporting/Config] allow string representations of duration settings (#…
Browse files Browse the repository at this point in the history
…74202) (#77807)

* [Reporting/Config] use better schema methods

* add createMockConfig

* update documentation

* fix observable.test

* add docs links to common options page

* make the schema match the docs

* wording edits per feedback

* self edits

* todo comment

* fix tests

* feedback change 1

* schema utils

* fix goof

* use objects for the defaults when available

* fix pollInterval

* fix snapshots

* Update report_listing.tsx

* call new ByteSizeValue on server side only

* revert xpack.reporting.poll

* fix ts

* fix snapshot

* use correct input for duration

* revert reorganize imports

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
tsullivan and elasticmachine authored Sep 18, 2020
1 parent 7e01905 commit 5d3bc83
Show file tree
Hide file tree
Showing 37 changed files with 607 additions and 349 deletions.
54 changes: 26 additions & 28 deletions docs/settings/reporting-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ security is enabled, `xpack.security.encryptionKey`.
[cols="2*<"]
|===
| `xpack.reporting.queue.pollInterval`
| Specifies the number of milliseconds that the reporting poller waits between polling the
index for any pending Reporting jobs. Defaults to `3000` (3 seconds).
| Specify the {ref}/common-options.html#time-units[time] that the reporting poller waits between polling the index for any
pending Reporting jobs. Can be specified as number of milliseconds. Defaults to `3s`.

| [[xpack-reporting-q-timeout]] `xpack.reporting.queue.timeout` {ess-icon}
| How long each worker has to produce a report. If your machine is slow or under
heavy load, you might need to increase this timeout. Specified in milliseconds.
If a Reporting job execution time goes over this time limit, the job will be
marked as a failure and there will not be a download available.
Defaults to `120000` (two minutes).
| {ref}/common-options.html#time-units[How long] each worker has to produce a report. If your machine is slow or under heavy
load, you might need to increase this timeout. If a Reporting job execution goes over this time limit, the job is marked as a
failure and no download will be available. Can be specified as number of milliseconds.
Defaults to `2m`.

|===

Expand All @@ -127,24 +126,24 @@ control the capturing process.
|===
a| `xpack.reporting.capture.timeouts`
`.openUrl` {ess-icon}
| Specify how long to allow the Reporting browser to wait for the "Loading..." screen
to dismiss and find the initial data for the Kibana page. If the time is
exceeded, a page screenshot is captured showing the current state, and the download link shows a warning message.
Defaults to `60000` (1 minute).
| Specify the {ref}/common-options.html#time-units[time] to allow the Reporting browser to wait for the "Loading..." screen
to dismiss and find the initial data for the page. If the time is exceeded, a screenshot is captured showing the current
page, and the download link shows a warning message. Can be specified as number of milliseconds.
Defaults to `1m`.

a| `xpack.reporting.capture.timeouts`
`.waitForElements` {ess-icon}
| Specify how long to allow the Reporting browser to wait for all visualization
panels to load on the Kibana page. If the time is exceeded, a page screenshot
is captured showing the current state, and the download link shows a warning message. Defaults to `30000` (30
seconds).
| Specify the {ref}/common-options.html#time-units[time] to allow the Reporting browser to wait for all visualization panels
to load on the page. If the time is exceeded, a screenshot is captured showing the current page, and the download link shows
a warning message. Can be specified as number of milliseconds.
Defaults to `30s`.

a| `xpack.reporting.capture.timeouts`
`.renderComplete` {ess-icon}
| Specify how long to allow the Reporting browser to wait for all visualizations to
fetch and render the data. If the time is exceeded, a
page screenshot is captured showing the current state, and the download link shows a warning message. Defaults to
`30000` (30 seconds).
| Specify the {ref}/common-options.html#time-units[time] to allow the Reporting browser to wait for all visualizations to
fetch and render the data. If the time is exceeded, a screenshot is captured showing the current page, and the download link shows a
warning message. Can be specified as number of milliseconds.
Defaults to `30s`.

|===

Expand All @@ -163,11 +162,10 @@ available, but there will likely be errors in the visualizations in the report.
job, as many times as this setting. Defaults to `3`.

| `xpack.reporting.capture.loadDelay`
| When visualizations are not evented, this is the amount of time before
taking a screenshot. All visualizations that ship with {kib} are evented, so this
setting should not have much effect. If you are seeing empty images instead of
visualizations, try increasing this value.
Defaults to `3000` (3 seconds).
| Specify the {ref}/common-options.html#time-units[amount of time] before taking a screenshot when visualizations are not evented.
All visualizations that ship with {kib} are evented, so this setting should not have much effect. If you are seeing empty images
instead of visualizations, try increasing this value.
Defaults to `3s`.

| [[xpack-reporting-browser]] `xpack.reporting.capture.browser.type` {ess-icon}
| Specifies the browser to use to capture screenshots. This setting exists for
Expand Down Expand Up @@ -213,17 +211,17 @@ a| `xpack.reporting.capture.browser`
[cols="2*<"]
|===
| [[xpack-reporting-csv]] `xpack.reporting.csv.maxSizeBytes` {ess-icon}
| The maximum size of a CSV file before being truncated. This setting exists to prevent
large exports from causing performance and storage issues.
Defaults to `10485760` (10mB).
| The maximum {ref}/common-options.html#byte-units[byte size] of a CSV file before being truncated. This setting exists to
prevent large exports from causing performance and storage issues. Can be specified as number of bytes.
Defaults to `10mb`.

| `xpack.reporting.csv.scroll.size`
| Number of documents retrieved from {es} for each scroll iteration during a CSV
export.
Defaults to `500`.

| `xpack.reporting.csv.scroll.duration`
| Amount of time allowed before {kib} cleans the scroll context during a CSV export.
| Amount of {ref}/common-options.html#time-units[time] allowed before {kib} cleans the scroll context during a CSV export.
Defaults to `30s`.

| `xpack.reporting.csv.checkForFormulas`
Expand Down
28 changes: 28 additions & 0 deletions x-pack/plugins/reporting/common/schema_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { ByteSizeValue } from '@kbn/config-schema';
import moment from 'moment';

/*
* For cleaner code: use these functions when a config schema value could be
* one type or another. This allows you to treat the value as one type.
*/

export const durationToNumber = (value: number | moment.Duration): number => {
if (typeof value === 'number') {
return value;
}
return value.asMilliseconds();
};

export const byteSizeValueToNumber = (value: number | ByteSizeValue) => {
if (typeof value === 'number') {
return value;
}

return value.getValueInBytes();
};
11 changes: 7 additions & 4 deletions x-pack/plugins/reporting/public/components/report_listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import {
EuiBasicTable,
EuiFlexItem,
EuiFlexGroup,
EuiFlexItem,
EuiPageContent,
EuiSpacer,
EuiText,
Expand All @@ -23,6 +23,7 @@ import { Subscription } from 'rxjs';
import { ApplicationStart, ToastsSetup } from 'src/core/public';
import { ILicense, LicensingPluginSetup } from '../../../licensing/public';
import { Poller } from '../../common/poller';
import { durationToNumber } from '../../common/schema_utils';
import { JobStatuses } from '../../constants';
import { checkLicense } from '../lib/license_check';
import { JobQueueEntry, ReportingAPIClient } from '../lib/reporting_api_client';
Expand Down Expand Up @@ -183,17 +184,19 @@ class ReportListingUi extends Component<Props, State> {

public componentDidMount() {
this.mounted = true;
const { pollConfig, license$ } = this.props;
const pollFrequencyInMillis = durationToNumber(pollConfig.jobsRefresh.interval);
this.poller = new Poller({
functionToPoll: () => {
return this.fetchJobs();
},
pollFrequencyInMillis: this.props.pollConfig.jobsRefresh.interval,
pollFrequencyInMillis,
trailing: false,
continuePollingOnError: true,
pollFrequencyErrorMultiplier: this.props.pollConfig.jobsRefresh.intervalErrorMultiplier,
pollFrequencyErrorMultiplier: pollConfig.jobsRefresh.intervalErrorMultiplier,
});
this.poller.start();
this.licenseSubscription = this.props.license$.subscribe(this.licenseHandler);
this.licenseSubscription = license$.subscribe(this.licenseHandler);
}

private licenseHandler = (license: ILicense) => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/reporting/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { ManagementSetup } from '../../../../src/plugins/management/public';
import { SharePluginSetup } from '../../../../src/plugins/share/public';
import { LicensingPluginSetup } from '../../licensing/public';
import { durationToNumber } from '../common/schema_utils';
import { JobId, JobStatusBuckets, ReportingConfigType } from '../common/types';
import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY } from '../constants';
import { getGeneralErrorToast } from './components';
Expand Down Expand Up @@ -158,8 +159,7 @@ export class ReportingPublicPlugin implements Plugin<void, void> {
const { http, notifications } = core;
const apiClient = new ReportingAPIClient(http);
const streamHandler = new StreamHandler(notifications, apiClient);
const { interval } = this.config.poll.jobsRefresh;

const interval = durationToNumber(this.config.poll.jobsRefresh.interval);
Rx.timer(0, interval)
.pipe(
takeUntil(this.stop$), // stop the interval when stop method is called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { InnerSubscriber } from 'rxjs/internal/InnerSubscriber';
import { ignoreElements, map, mergeMap, tap } from 'rxjs/operators';
import { getChromiumDisconnectedError } from '../';
import { BROWSER_TYPE } from '../../../../common/constants';
import { durationToNumber } from '../../../../common/schema_utils';
import { CaptureConfig } from '../../../../server/types';
import { LevelLogger } from '../../../lib';
import { safeChildProcess } from '../../safe_child_process';
Expand Down Expand Up @@ -90,7 +91,7 @@ export class HeadlessChromiumDriverFactory {

// Set the default timeout for all navigation methods to the openUrl timeout (30 seconds)
// All waitFor methods have their own timeout config passed in to them
page.setDefaultTimeout(this.captureConfig.timeouts.openUrl);
page.setDefaultTimeout(durationToNumber(this.captureConfig.timeouts.openUrl));

logger.debug(`Browser page driver created`);
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/reporting/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const config: PluginConfigDescriptor<ReportingConfigType> = {
unused('capture.concurrency'),
unused('capture.settleTime'),
unused('capture.timeout'),
unused('poll.jobCompletionNotifier.intervalErrorMultiplier'),
unused('poll.jobsRefresh.intervalErrorMultiplier'),
unused('kibanaApp'),
],
};
Loading

0 comments on commit 5d3bc83

Please sign in to comment.