From 196884a205f0902f347bfb03dd73dfc6bb75ef25 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 10:15:51 -0700 Subject: [PATCH 01/25] fix ts --- .../reporting/server/routes/common/jobs/jobs_query.test.ts | 6 ++++-- x-pack/plugins/reporting/server/types.ts | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.test.ts b/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.test.ts index f0c656da2050a..57ad7586467cb 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.test.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.test.ts @@ -5,11 +5,13 @@ * 2.0. */ +import { set } from '@kbn/safer-lodash-set'; + import { ElasticsearchClient } from '@kbn/core/server'; import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; -import { set } from '@kbn/safer-lodash-set'; +import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; import { statuses } from '../../../lib'; -import { createMockConfigSchema, createMockReportingCore } from '../../../test_helpers'; +import { createMockReportingCore } from '../../../test_helpers'; import { jobsQueryFactory } from './jobs_query'; describe('jobsQuery', () => { diff --git a/x-pack/plugins/reporting/server/types.ts b/x-pack/plugins/reporting/server/types.ts index 2a9f61ef1f99c..a3c12d4c0afb7 100644 --- a/x-pack/plugins/reporting/server/types.ts +++ b/x-pack/plugins/reporting/server/types.ts @@ -6,6 +6,7 @@ */ import { CustomRequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; +import { IRouter } from '@kbn/core-http-server'; import type { DataPluginStart } from '@kbn/data-plugin/server/plugin'; import type { DiscoverServerPluginStart } from '@kbn/discover-plugin/server'; import type { PluginSetupContract as FeaturesPluginSetup } from '@kbn/features-plugin/server'; @@ -78,6 +79,8 @@ export type ReportingRequestHandlerContext = CustomRequestHandlerContext<{ reporting: ReportingStart | null; }>; +export type ReportingPluginRouter = IRouter; + /** * Interface of a response to an HTTP request for our plugin to generate a report. * @public From dd665b7b2cde81726b2cf695884238974b7087ee Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 10:22:17 -0700 Subject: [PATCH 02/25] update snapshots --- .../config/__snapshots__/schema.test.ts.snap | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap diff --git a/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap b/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap deleted file mode 100644 index 1c9a695f4a78e..0000000000000 --- a/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap +++ /dev/null @@ -1,122 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Reporting Config Schema context {"dev":false,"dist":false} produces correct config 1`] = ` -Object { - "capture": Object { - "maxAttempts": 1, - }, - "csv": Object { - "checkForFormulas": true, - "enablePanelActionDownload": true, - "escapeFormulaValues": false, - "maxSizeBytes": ByteSizeValue { - "valueInBytes": 262144000, - }, - "scroll": Object { - "duration": "30s", - "size": 500, - }, - "useByteOrderMarkEncoding": false, - }, - "enabled": true, - "encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "export_types": Object { - "csv": Object { - "enabled": true, - }, - "pdf": Object { - "enabled": true, - }, - "png": Object { - "enabled": true, - }, - }, - "kibanaServer": Object {}, - "poll": Object { - "jobCompletionNotifier": Object { - "interval": 10000, - "intervalErrorMultiplier": 5, - }, - "jobsRefresh": Object { - "interval": 5000, - "intervalErrorMultiplier": 5, - }, - }, - "queue": Object { - "indexInterval": "week", - "pollEnabled": true, - "pollInterval": "PT3S", - "pollIntervalErrorMultiplier": 10, - "timeout": "PT4M", - }, - "roles": Object { - "allow": Array [ - "reporting_user", - ], - "enabled": true, - }, - "statefulSettings": Object { - "enabled": true, - }, -} -`; - -exports[`Reporting Config Schema context {"dev":false,"dist":true} produces correct config 1`] = ` -Object { - "capture": Object { - "maxAttempts": 3, - }, - "csv": Object { - "checkForFormulas": true, - "enablePanelActionDownload": true, - "escapeFormulaValues": false, - "maxSizeBytes": ByteSizeValue { - "valueInBytes": 262144000, - }, - "scroll": Object { - "duration": "30s", - "size": 500, - }, - "useByteOrderMarkEncoding": false, - }, - "enabled": true, - "export_types": Object { - "csv": Object { - "enabled": true, - }, - "pdf": Object { - "enabled": true, - }, - "png": Object { - "enabled": true, - }, - }, - "kibanaServer": Object {}, - "poll": Object { - "jobCompletionNotifier": Object { - "interval": 10000, - "intervalErrorMultiplier": 5, - }, - "jobsRefresh": Object { - "interval": 5000, - "intervalErrorMultiplier": 5, - }, - }, - "queue": Object { - "indexInterval": "week", - "pollEnabled": true, - "pollInterval": "PT3S", - "pollIntervalErrorMultiplier": 10, - "timeout": "PT4M", - }, - "roles": Object { - "allow": Array [ - "reporting_user", - ], - "enabled": true, - }, - "statefulSettings": Object { - "enabled": true, - }, -} -`; From e749ed427588f5b5fbe62edf1b5dec09168944a8 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 10:22:17 -0700 Subject: [PATCH 03/25] update snapshots --- .../config/__snapshots__/schema.test.ts.snap | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap diff --git a/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap b/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap deleted file mode 100644 index 1c9a695f4a78e..0000000000000 --- a/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap +++ /dev/null @@ -1,122 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Reporting Config Schema context {"dev":false,"dist":false} produces correct config 1`] = ` -Object { - "capture": Object { - "maxAttempts": 1, - }, - "csv": Object { - "checkForFormulas": true, - "enablePanelActionDownload": true, - "escapeFormulaValues": false, - "maxSizeBytes": ByteSizeValue { - "valueInBytes": 262144000, - }, - "scroll": Object { - "duration": "30s", - "size": 500, - }, - "useByteOrderMarkEncoding": false, - }, - "enabled": true, - "encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "export_types": Object { - "csv": Object { - "enabled": true, - }, - "pdf": Object { - "enabled": true, - }, - "png": Object { - "enabled": true, - }, - }, - "kibanaServer": Object {}, - "poll": Object { - "jobCompletionNotifier": Object { - "interval": 10000, - "intervalErrorMultiplier": 5, - }, - "jobsRefresh": Object { - "interval": 5000, - "intervalErrorMultiplier": 5, - }, - }, - "queue": Object { - "indexInterval": "week", - "pollEnabled": true, - "pollInterval": "PT3S", - "pollIntervalErrorMultiplier": 10, - "timeout": "PT4M", - }, - "roles": Object { - "allow": Array [ - "reporting_user", - ], - "enabled": true, - }, - "statefulSettings": Object { - "enabled": true, - }, -} -`; - -exports[`Reporting Config Schema context {"dev":false,"dist":true} produces correct config 1`] = ` -Object { - "capture": Object { - "maxAttempts": 3, - }, - "csv": Object { - "checkForFormulas": true, - "enablePanelActionDownload": true, - "escapeFormulaValues": false, - "maxSizeBytes": ByteSizeValue { - "valueInBytes": 262144000, - }, - "scroll": Object { - "duration": "30s", - "size": 500, - }, - "useByteOrderMarkEncoding": false, - }, - "enabled": true, - "export_types": Object { - "csv": Object { - "enabled": true, - }, - "pdf": Object { - "enabled": true, - }, - "png": Object { - "enabled": true, - }, - }, - "kibanaServer": Object {}, - "poll": Object { - "jobCompletionNotifier": Object { - "interval": 10000, - "intervalErrorMultiplier": 5, - }, - "jobsRefresh": Object { - "interval": 5000, - "intervalErrorMultiplier": 5, - }, - }, - "queue": Object { - "indexInterval": "week", - "pollEnabled": true, - "pollInterval": "PT3S", - "pollIntervalErrorMultiplier": 10, - "timeout": "PT4M", - }, - "roles": Object { - "allow": Array [ - "reporting_user", - ], - "enabled": true, - }, - "statefulSettings": Object { - "enabled": true, - }, -} -`; From 187e58c87462bfcf1252b99716a6c2315b143238 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 10:28:20 -0700 Subject: [PATCH 04/25] fix jest test --- .../__snapshots__/schema.test.ts.snap | 122 ++++++++++++++++++ .../{csv_common => csv}/jest.config.js | 2 +- .../{pdf_common => pdf}/jest.config.js | 2 +- .../{png_common => png}/jest.config.js | 2 +- 4 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 packages/kbn-reporting/config_server/__snapshots__/schema.test.ts.snap rename packages/kbn-reporting/export_types/{csv_common => csv}/jest.config.js (85%) rename packages/kbn-reporting/export_types/{pdf_common => pdf}/jest.config.js (85%) rename packages/kbn-reporting/export_types/{png_common => png}/jest.config.js (85%) diff --git a/packages/kbn-reporting/config_server/__snapshots__/schema.test.ts.snap b/packages/kbn-reporting/config_server/__snapshots__/schema.test.ts.snap new file mode 100644 index 0000000000000..1c9a695f4a78e --- /dev/null +++ b/packages/kbn-reporting/config_server/__snapshots__/schema.test.ts.snap @@ -0,0 +1,122 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Reporting Config Schema context {"dev":false,"dist":false} produces correct config 1`] = ` +Object { + "capture": Object { + "maxAttempts": 1, + }, + "csv": Object { + "checkForFormulas": true, + "enablePanelActionDownload": true, + "escapeFormulaValues": false, + "maxSizeBytes": ByteSizeValue { + "valueInBytes": 262144000, + }, + "scroll": Object { + "duration": "30s", + "size": 500, + }, + "useByteOrderMarkEncoding": false, + }, + "enabled": true, + "encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "export_types": Object { + "csv": Object { + "enabled": true, + }, + "pdf": Object { + "enabled": true, + }, + "png": Object { + "enabled": true, + }, + }, + "kibanaServer": Object {}, + "poll": Object { + "jobCompletionNotifier": Object { + "interval": 10000, + "intervalErrorMultiplier": 5, + }, + "jobsRefresh": Object { + "interval": 5000, + "intervalErrorMultiplier": 5, + }, + }, + "queue": Object { + "indexInterval": "week", + "pollEnabled": true, + "pollInterval": "PT3S", + "pollIntervalErrorMultiplier": 10, + "timeout": "PT4M", + }, + "roles": Object { + "allow": Array [ + "reporting_user", + ], + "enabled": true, + }, + "statefulSettings": Object { + "enabled": true, + }, +} +`; + +exports[`Reporting Config Schema context {"dev":false,"dist":true} produces correct config 1`] = ` +Object { + "capture": Object { + "maxAttempts": 3, + }, + "csv": Object { + "checkForFormulas": true, + "enablePanelActionDownload": true, + "escapeFormulaValues": false, + "maxSizeBytes": ByteSizeValue { + "valueInBytes": 262144000, + }, + "scroll": Object { + "duration": "30s", + "size": 500, + }, + "useByteOrderMarkEncoding": false, + }, + "enabled": true, + "export_types": Object { + "csv": Object { + "enabled": true, + }, + "pdf": Object { + "enabled": true, + }, + "png": Object { + "enabled": true, + }, + }, + "kibanaServer": Object {}, + "poll": Object { + "jobCompletionNotifier": Object { + "interval": 10000, + "intervalErrorMultiplier": 5, + }, + "jobsRefresh": Object { + "interval": 5000, + "intervalErrorMultiplier": 5, + }, + }, + "queue": Object { + "indexInterval": "week", + "pollEnabled": true, + "pollInterval": "PT3S", + "pollIntervalErrorMultiplier": 10, + "timeout": "PT4M", + }, + "roles": Object { + "allow": Array [ + "reporting_user", + ], + "enabled": true, + }, + "statefulSettings": Object { + "enabled": true, + }, +} +`; diff --git a/packages/kbn-reporting/export_types/csv_common/jest.config.js b/packages/kbn-reporting/export_types/csv/jest.config.js similarity index 85% rename from packages/kbn-reporting/export_types/csv_common/jest.config.js rename to packages/kbn-reporting/export_types/csv/jest.config.js index 6e39e463a6f68..3f14bdeaba318 100644 --- a/packages/kbn-reporting/export_types/csv_common/jest.config.js +++ b/packages/kbn-reporting/export_types/csv/jest.config.js @@ -9,5 +9,5 @@ module.exports = { preset: '@kbn/test/jest_node', rootDir: '../../../..', - roots: ['/packages/kbn-reporting/export_types/csv_common'], + roots: ['/packages/kbn-reporting/export_types/csv'], }; diff --git a/packages/kbn-reporting/export_types/pdf_common/jest.config.js b/packages/kbn-reporting/export_types/pdf/jest.config.js similarity index 85% rename from packages/kbn-reporting/export_types/pdf_common/jest.config.js rename to packages/kbn-reporting/export_types/pdf/jest.config.js index a9935a9a75462..eb1d1bff052d0 100644 --- a/packages/kbn-reporting/export_types/pdf_common/jest.config.js +++ b/packages/kbn-reporting/export_types/pdf/jest.config.js @@ -9,5 +9,5 @@ module.exports = { preset: '@kbn/test/jest_node', rootDir: '../../../..', - roots: ['/packages/kbn-reporting/export_types/pdf_common'], + roots: ['/packages/kbn-reporting/export_types/pdf'], }; diff --git a/packages/kbn-reporting/export_types/png_common/jest.config.js b/packages/kbn-reporting/export_types/png/jest.config.js similarity index 85% rename from packages/kbn-reporting/export_types/png_common/jest.config.js rename to packages/kbn-reporting/export_types/png/jest.config.js index ea305c905ed87..467708b5bfe9f 100644 --- a/packages/kbn-reporting/export_types/png_common/jest.config.js +++ b/packages/kbn-reporting/export_types/png/jest.config.js @@ -9,5 +9,5 @@ module.exports = { preset: '@kbn/test/jest_node', rootDir: '../../../..', - roots: ['/packages/kbn-reporting/export_types/png_common'], + roots: ['/packages/kbn-reporting/export_types/png'], }; From 22f5f344c1c3d7ad6d78acdec752a9e618cec1fc Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 12:02:59 -0700 Subject: [PATCH 05/25] Move ClientConfigType out of reporting plugin --- package.json | 1 + packages/kbn-reporting/public/README.md | 3 +++ packages/kbn-reporting/public/index.ts | 9 +++++++ packages/kbn-reporting/public/jest.config.js | 13 ++++++++++ packages/kbn-reporting/public/kibana.jsonc | 5 ++++ packages/kbn-reporting/public/package.json | 6 +++++ packages/kbn-reporting/public/tsconfig.json | 17 ++++++++++++ packages/kbn-reporting/public/types.ts | 14 ++++++++++ tsconfig.base.json | 2 ++ .../components/report_diagnostic.tsx | 2 +- .../reporting/public/management/index.ts | 10 +++---- .../management/mount_management_section.tsx | 9 ++++--- x-pack/plugins/reporting/public/plugin.ts | 26 ++++++++----------- yarn.lock | 4 +++ 14 files changed, 96 insertions(+), 25 deletions(-) create mode 100644 packages/kbn-reporting/public/README.md create mode 100644 packages/kbn-reporting/public/index.ts create mode 100644 packages/kbn-reporting/public/jest.config.js create mode 100644 packages/kbn-reporting/public/kibana.jsonc create mode 100644 packages/kbn-reporting/public/package.json create mode 100644 packages/kbn-reporting/public/tsconfig.json create mode 100644 packages/kbn-reporting/public/types.ts diff --git a/package.json b/package.json index cfda249da8f10..d28aedeebef14 100644 --- a/package.json +++ b/package.json @@ -604,6 +604,7 @@ "@kbn/reporting-export-types-png-common": "link:packages/kbn-reporting/export_types/png_common", "@kbn/reporting-mocks-server": "link:packages/kbn-reporting/mocks_server", "@kbn/reporting-plugin": "link:x-pack/plugins/reporting", + "@kbn/reporting-public": "link:packages/kbn-reporting/public", "@kbn/reporting-server": "link:packages/kbn-reporting/server", "@kbn/resizable-layout": "link:packages/kbn-resizable-layout", "@kbn/resizable-layout-examples-plugin": "link:examples/resizable_layout_examples", diff --git a/packages/kbn-reporting/public/README.md b/packages/kbn-reporting/public/README.md new file mode 100644 index 0000000000000..76d4926820b7f --- /dev/null +++ b/packages/kbn-reporting/public/README.md @@ -0,0 +1,3 @@ +# @kbn/reporting-public + +Empty package generated by @kbn/generate diff --git a/packages/kbn-reporting/public/index.ts b/packages/kbn-reporting/public/index.ts new file mode 100644 index 0000000000000..7168d6768c5a2 --- /dev/null +++ b/packages/kbn-reporting/public/index.ts @@ -0,0 +1,9 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export type { ClientConfigType } from './types'; diff --git a/packages/kbn-reporting/public/jest.config.js b/packages/kbn-reporting/public/jest.config.js new file mode 100644 index 0000000000000..9b1a02aee8ea6 --- /dev/null +++ b/packages/kbn-reporting/public/jest.config.js @@ -0,0 +1,13 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../../..', + roots: ['/packages/kbn-reporting/public'], +}; diff --git a/packages/kbn-reporting/public/kibana.jsonc b/packages/kbn-reporting/public/kibana.jsonc new file mode 100644 index 0000000000000..9d506d6ed7199 --- /dev/null +++ b/packages/kbn-reporting/public/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-common", + "id": "@kbn/reporting-public", + "owner": "@elastic/appex-sharedux" +} diff --git a/packages/kbn-reporting/public/package.json b/packages/kbn-reporting/public/package.json new file mode 100644 index 0000000000000..b9a4abf894c64 --- /dev/null +++ b/packages/kbn-reporting/public/package.json @@ -0,0 +1,6 @@ +{ + "name": "@kbn/reporting-public", + "private": true, + "version": "1.0.0", + "license": "SSPL-1.0 OR Elastic License 2.0" +} \ No newline at end of file diff --git a/packages/kbn-reporting/public/tsconfig.json b/packages/kbn-reporting/public/tsconfig.json new file mode 100644 index 0000000000000..6d27b06d5f8ba --- /dev/null +++ b/packages/kbn-reporting/public/tsconfig.json @@ -0,0 +1,17 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node" + ] + }, + "include": [ + "**/*.ts", + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [] +} diff --git a/packages/kbn-reporting/public/types.ts b/packages/kbn-reporting/public/types.ts new file mode 100644 index 0000000000000..34aa52544ca76 --- /dev/null +++ b/packages/kbn-reporting/public/types.ts @@ -0,0 +1,14 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export interface ClientConfigType { + poll: { jobsRefresh: { interval: number; intervalErrorMultiplier: number } }; + roles: { enabled: boolean }; + export_types: { pdf: { enabled: boolean }; png: { enabled: boolean }; csv: { enabled: boolean } }; + statefulSettings: { enabled: boolean }; +} diff --git a/tsconfig.base.json b/tsconfig.base.json index f49cb59b967d8..ea69c25f57e34 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1192,6 +1192,8 @@ "@kbn/reporting-mocks-server/*": ["packages/kbn-reporting/mocks_server/*"], "@kbn/reporting-plugin": ["x-pack/plugins/reporting"], "@kbn/reporting-plugin/*": ["x-pack/plugins/reporting/*"], + "@kbn/reporting-public": ["packages/kbn-reporting/public"], + "@kbn/reporting-public/*": ["packages/kbn-reporting/public/*"], "@kbn/reporting-server": ["packages/kbn-reporting/server"], "@kbn/reporting-server/*": ["packages/kbn-reporting/server/*"], "@kbn/resizable-layout": ["packages/kbn-resizable-layout"], diff --git a/x-pack/plugins/reporting/public/management/components/report_diagnostic.tsx b/x-pack/plugins/reporting/public/management/components/report_diagnostic.tsx index dd59f34eb24a9..2e63ab4a6f253 100644 --- a/x-pack/plugins/reporting/public/management/components/report_diagnostic.tsx +++ b/x-pack/plugins/reporting/public/management/components/report_diagnostic.tsx @@ -19,8 +19,8 @@ import { EuiText, EuiTitle, } from '@elastic/eui'; +import { ClientConfigType } from '@kbn/reporting-public'; import { ReportingAPIClient, DiagnoseResponse } from '../../lib/reporting_api_client'; -import { ClientConfigType } from '../../plugin'; interface Props { apiClient: ReportingAPIClient; diff --git a/x-pack/plugins/reporting/public/management/index.ts b/x-pack/plugins/reporting/public/management/index.ts index c3e338af8ad3d..4b9074267dd49 100644 --- a/x-pack/plugins/reporting/public/management/index.ts +++ b/x-pack/plugins/reporting/public/management/index.ts @@ -5,11 +5,11 @@ * 2.0. */ -import { ApplicationStart, ToastsSetup } from '@kbn/core/public'; -import { LicensingPluginStart } from '@kbn/licensing-plugin/public'; -import { UseIlmPolicyStatusReturn } from '../lib/ilm_policy_status_context'; -import { ReportingAPIClient } from '../lib/reporting_api_client'; -import { ClientConfigType } from '../plugin'; +import type { ApplicationStart, ToastsSetup } from '@kbn/core/public'; +import type { LicensingPluginStart } from '@kbn/licensing-plugin/public'; +import type { ClientConfigType } from '@kbn/reporting-public'; +import type { UseIlmPolicyStatusReturn } from '../lib/ilm_policy_status_context'; +import type { ReportingAPIClient } from '../lib/reporting_api_client'; import type { SharePluginSetup } from '../shared_imports'; export interface ListingProps { diff --git a/x-pack/plugins/reporting/public/management/mount_management_section.tsx b/x-pack/plugins/reporting/public/management/mount_management_section.tsx index 4c994a5bb61b4..60cd66d952780 100644 --- a/x-pack/plugins/reporting/public/management/mount_management_section.tsx +++ b/x-pack/plugins/reporting/public/management/mount_management_section.tsx @@ -5,19 +5,20 @@ * 2.0. */ -import { I18nProvider } from '@kbn/i18n-react'; import * as React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { Observable } from 'rxjs'; + import { CoreSetup, CoreStart } from '@kbn/core/public'; +import { I18nProvider } from '@kbn/i18n-react'; import { ILicense } from '@kbn/licensing-plugin/public'; import { KibanaThemeProvider } from '@kbn/react-kibana-context-theme'; -import { ReportingAPIClient, InternalApiClientProvider } from '../lib/reporting_api_client'; +import type { ClientConfigType } from '@kbn/reporting-public'; +import { ReportListing } from '.'; import { IlmPolicyStatusContextProvider } from '../lib/ilm_policy_status_context'; -import { ClientConfigType } from '../plugin'; +import { InternalApiClientProvider, ReportingAPIClient } from '../lib/reporting_api_client'; import type { ManagementAppMountParams, SharePluginSetup } from '../shared_imports'; import { KibanaContextProvider } from '../shared_imports'; -import { ReportListing } from '.'; export async function mountManagementSection( coreSetup: CoreSetup, diff --git a/x-pack/plugins/reporting/public/plugin.ts b/x-pack/plugins/reporting/public/plugin.ts index 906fab4c4195b..560f4ef06635f 100644 --- a/x-pack/plugins/reporting/public/plugin.ts +++ b/x-pack/plugins/reporting/public/plugin.ts @@ -5,10 +5,9 @@ * 2.0. */ -import { i18n } from '@kbn/i18n'; import * as Rx from 'rxjs'; import { catchError, filter, map, mergeMap, takeUntil } from 'rxjs/operators'; -import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; + import { CoreSetup, CoreStart, @@ -19,18 +18,25 @@ import { PluginInitializerContext, ThemeServiceStart, } from '@kbn/core/public'; -import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/public'; +import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; import { CONTEXT_MENU_TRIGGER } from '@kbn/embeddable-plugin/public'; import type { HomePublicPluginSetup, HomePublicPluginStart } from '@kbn/home-plugin/public'; -import { ManagementSetup, ManagementStart } from '@kbn/management-plugin/public'; +import { i18n } from '@kbn/i18n'; import { LicensingPluginStart } from '@kbn/licensing-plugin/public'; +import { ManagementSetup, ManagementStart } from '@kbn/management-plugin/public'; +import { ClientConfigType } from '@kbn/reporting-public'; +import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/public'; + +import { ReportingSetup, ReportingStart } from '.'; +import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY, JobId } from '../common/constants'; import { durationToNumber } from '../common/schema_utils'; import { JobSummarySet } from '../common/types'; -import { ReportingSetup, ReportingStart } from '.'; import { ReportingAPIClient } from './lib/reporting_api_client'; import { ReportingNotifierStreamHandler as StreamHandler } from './lib/stream_handler'; import { getGeneralErrorToast } from './notifier'; import { ReportingCsvPanelAction } from './panel_actions/get_csv_panel_action'; +import { reportingCsvShareProvider } from './share_context_menu/register_csv_reporting'; +import { reportingScreenshotShareProvider } from './share_context_menu/register_pdf_png_reporting'; import { getSharedComponents } from './shared'; import type { SharePluginSetup, @@ -39,16 +45,6 @@ import type { UiActionsStart, } from './shared_imports'; import { AppNavLinkStatus } from './shared_imports'; -import { reportingCsvShareProvider } from './share_context_menu/register_csv_reporting'; -import { reportingScreenshotShareProvider } from './share_context_menu/register_pdf_png_reporting'; -import { JobId, JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY } from '../common/constants'; - -export interface ClientConfigType { - poll: { jobsRefresh: { interval: number; intervalErrorMultiplier: number } }; - roles: { enabled: boolean }; - export_types: { pdf: { enabled: boolean }; png: { enabled: boolean }; csv: { enabled: boolean } }; - statefulSettings: { enabled: boolean }; -} function getStored(): JobId[] { const sessionValue = sessionStorage.getItem(JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY); diff --git a/yarn.lock b/yarn.lock index 33d5a847a930e..7908feafae972 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5288,6 +5288,10 @@ version "0.0.0" uid "" +"@kbn/reporting-public@link:packages/kbn-reporting/public": + version "0.0.0" + uid "" + "@kbn/reporting-server@link:packages/kbn-reporting/server": version "0.0.0" uid "" From 3c80d67a67ca6e0015a0cfe53fb495a5c99c0c15 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 12:08:04 -0700 Subject: [PATCH 06/25] Clean up duplicated --- .../plugins/reporting/common/schema_utils.ts | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 x-pack/plugins/reporting/common/schema_utils.ts diff --git a/x-pack/plugins/reporting/common/schema_utils.ts b/x-pack/plugins/reporting/common/schema_utils.ts deleted file mode 100644 index 798440bfbb69c..0000000000000 --- a/x-pack/plugins/reporting/common/schema_utils.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 { 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 numberToDuration = (value: number | moment.Duration): moment.Duration => { - if (typeof value === 'number') { - return moment.duration(value, 'milliseconds'); - } - return value; -}; - -export const byteSizeValueToNumber = (value: number | ByteSizeValue) => { - if (typeof value === 'number') { - return value; - } - - return value.getValueInBytes(); -}; From 9727225dc5aad910510c919e8ad23bf287e75430 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 12:37:38 -0700 Subject: [PATCH 07/25] Add more to packages --- packages/kbn-reporting/common/constants.ts | 29 ++++ packages/kbn-reporting/common/types.ts | 97 +++++++++++++ packages/kbn-reporting/server/types.ts | 5 + .../reporting/common/constants/index.ts | 53 -------- .../plugins/reporting/common/test/fixtures.ts | 2 +- x-pack/plugins/reporting/common/test/types.ts | 2 +- x-pack/plugins/reporting/common/types.ts | 127 ------------------ x-pack/plugins/reporting/public/lib/job.tsx | 15 ++- .../public/lib/stream_handler.test.ts | 7 +- x-pack/plugins/reporting/public/types.ts | 24 ++++ .../server/export_types/common/index.ts | 11 -- .../reporting/server/lib/store/report.ts | 10 +- .../common/jobs/get_document_payload.test.ts | 2 +- .../common/jobs/get_document_payload.ts | 7 +- .../common/jobs/job_management_pre_routing.ts | 3 +- .../server/routes/common/jobs/jobs_query.ts | 6 +- x-pack/plugins/reporting/server/types.ts | 2 +- 17 files changed, 188 insertions(+), 214 deletions(-) delete mode 100644 x-pack/plugins/reporting/common/types.ts delete mode 100644 x-pack/plugins/reporting/server/export_types/common/index.ts diff --git a/packages/kbn-reporting/common/constants.ts b/packages/kbn-reporting/common/constants.ts index 52f8808f3e925..a9f7c5ffa3757 100644 --- a/packages/kbn-reporting/common/constants.ts +++ b/packages/kbn-reporting/common/constants.ts @@ -9,6 +9,7 @@ export const PLUGIN_ID = 'reporting'; export const REPORTING_TRANSACTION_TYPE = PLUGIN_ID; + export const REPORTING_REDIRECT_LOCATOR_STORE_KEY = '__REPORTING_REDIRECT_LOCATOR_STORE_KEY__'; export const UI_SETTINGS_SEARCH_INCLUDE_FROZEN = 'search:includeFrozen'; @@ -23,6 +24,11 @@ export const LICENSE_TYPE_GOLD = 'gold' as const; export const LICENSE_TYPE_PLATINUM = 'platinum' as const; export const LICENSE_TYPE_ENTERPRISE = 'enterprise' as const; +export const REPORTING_SYSTEM_INDEX = '.reporting'; + +export const JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY = + 'xpack.reporting.jobCompletionNotifications'; + /** * A way to get the client side route for the reporting redirect app. * @@ -32,3 +38,26 @@ export const LICENSE_TYPE_ENTERPRISE = 'enterprise' as const; export const getRedirectAppPath = () => { return '/app/reportingRedirect'; }; + +export const ILM_POLICY_NAME = 'kibana-reporting'; + +// Usage counter types +export const API_USAGE_COUNTER_TYPE = 'reportingApi'; +export const API_USAGE_ERROR_TYPE = 'reportingApiError'; + +// Management UI route +export const REPORTING_MANAGEMENT_HOME = '/app/management/insightsAndAlerting/reporting'; + +// Statuses +export enum JOB_STATUSES { + PENDING = 'pending', + PROCESSING = 'processing', + COMPLETED = 'completed', + FAILED = 'failed', + WARNINGS = 'completed_with_warnings', +} + +// Job params require a `version` field as of 7.15.0. For older jobs set with +// automation that have no version value in the job params, we assume the +// intended version is 7.14.0 +export const UNVERSIONED_VERSION = '7.14.0'; diff --git a/packages/kbn-reporting/common/types.ts b/packages/kbn-reporting/common/types.ts index 679ac59432571..6002f82b11b89 100644 --- a/packages/kbn-reporting/common/types.ts +++ b/packages/kbn-reporting/common/types.ts @@ -99,3 +99,100 @@ export type IlmPolicyMigrationStatus = 'policy-not-found' | 'indices-not-managed export interface IlmPolicyStatusResponse { status: IlmPolicyMigrationStatus; } + +export interface ReportDocumentHead { + _id: string; + _index: string; + _seq_no: number; + _primary_term: number; +} + +export interface ReportFields { + queue_time_ms?: number[]; // runtime field: started_at - created_at + execution_time_ms?: number[]; // runtime field: completed_at - started_at +} + +export interface ReportSource { + /* + * Required fields: populated in RequestHandler.enqueueJob when the request comes in to + * generate the report + */ + jobtype: string; // refers to `ExportTypeDefinition.jobType` + created_by: string | false; // username or `false` if security is disabled. Used for ensuring users can only access the reports they've created. + payload: BasePayload; + meta: { + // for telemetry + objectType: string; + layout?: string; + isDeprecated?: boolean; + }; + migration_version: string; // for reminding the user to update their POST URL + attempts: number; // initially populated as 0 + created_at: string; // timestamp in UTC + status: JobStatus; + + /* + * `output` is only populated if the report job is completed or failed. + */ + output: ReportOutput | null; + + /* + * Optional fields: populated when the job is claimed to execute, and after + * execution has finished + */ + kibana_name?: string; // for troubleshooting + kibana_id?: string; // for troubleshooting + timeout?: number; // for troubleshooting: the actual comparison uses the config setting xpack.reporting.queue.timeout + max_attempts?: number; // for troubleshooting: the actual comparison uses the config setting xpack.reporting.capture.maxAttempts + started_at?: string; // timestamp in UTC + completed_at?: string; // timestamp in UTC + process_expiration?: string | null; // timestamp in UTC - is overwritten with `null` when the job needs a retry + metrics?: TaskRunMetrics; +} + +/* + * The document created by Reporting to store in the .reporting index + */ +export interface ReportDocument extends ReportDocumentHead { + _source: ReportSource; +} + +/* + * JobStatus: + * - Begins as 'pending' + * - Changes to 'processing` when the job is claimed + * - Then 'completed' | 'failed' when execution is done + * If the job needs a retry, it reverts back to 'pending'. + */ +export type JobStatus = + | 'completed' // Report was successful + | 'completed_with_warnings' // The download available for troubleshooting - it **should** show a meaningful error + | 'pending' // Report job is waiting to be claimed + | 'processing' // Report job has been claimed and is executing + | 'failed'; // Report was not successful, and all retries are done. Nothing to download. + +/* + * Info API response: to avoid unnecessary large payloads on a network, the + * report query results do not include `payload.headers` or `output.content`, + * which can be long strings of meaningless text + */ +interface ReportSimple extends Omit { + payload: Omit; + output?: Omit; // is undefined for report jobs that are not completed + queue_time_ms?: number; + execution_time_ms?: number; +} + +/* + * The response format for all of the report job APIs + */ +export interface ReportApiJSON extends ReportSimple { + id: string; + index: string; +} + +export interface LicenseCheckResults { + enableLinks: boolean; + showLinks: boolean; + message: string; +} diff --git a/packages/kbn-reporting/server/types.ts b/packages/kbn-reporting/server/types.ts index 8fac04cbc5f6c..007333de214e7 100644 --- a/packages/kbn-reporting/server/types.ts +++ b/packages/kbn-reporting/server/types.ts @@ -38,3 +38,8 @@ export type RunTaskFn = ( cancellationToken: CancellationToken, stream: Writable ) => Promise; + +export interface TimeRangeParams { + min?: Date | string | number | null; + max?: Date | string | number | null; +} diff --git a/x-pack/plugins/reporting/common/constants/index.ts b/x-pack/plugins/reporting/common/constants/index.ts index d3de630932a75..d03c5d37d67b5 100644 --- a/x-pack/plugins/reporting/common/constants/index.ts +++ b/x-pack/plugins/reporting/common/constants/index.ts @@ -26,25 +26,6 @@ import { PNG_REPORT_TYPE_V2, } from '@kbn/reporting-export-types-png-common'; -export const PLUGIN_ID = 'reporting'; - -export const REPORTING_TRANSACTION_TYPE = PLUGIN_ID; - -export const REPORTING_SYSTEM_INDEX = '.reporting'; - -export const JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY = - 'xpack.reporting.jobCompletionNotifications'; - -/** - * A way to get the client side route for the reporting redirect app. - * - * TODO: Add a job ID and a locator to use so that we can redirect without expecting state to - * be injected to the page - */ -export const getRedirectAppPath = () => { - return '/app/reportingRedirect'; -}; - export const ALLOWED_JOB_CONTENT_TYPES = [ 'application/json', 'application/pdf', @@ -53,8 +34,6 @@ export const ALLOWED_JOB_CONTENT_TYPES = [ 'text/plain', ]; -export type JobId = string; - export const reportTypes = [ CSV_REPORT_TYPE, CSV_REPORT_TYPE_V2, @@ -88,40 +67,8 @@ export const USES_HEADLESS_JOB_TYPES = [ export const DEPRECATED_JOB_TYPES = [CSV_JOB_TYPE_DEPRECATED]; -// Licenses -export const LICENSE_TYPE_TRIAL = 'trial' as const; -export const LICENSE_TYPE_BASIC = 'basic' as const; -export const LICENSE_TYPE_CLOUD_STANDARD = 'standard' as const; -export const LICENSE_TYPE_GOLD = 'gold' as const; -export const LICENSE_TYPE_PLATINUM = 'platinum' as const; -export const LICENSE_TYPE_ENTERPRISE = 'enterprise' as const; - -export const ILM_POLICY_NAME = 'kibana-reporting'; - -// Usage counter types -export const API_USAGE_COUNTER_TYPE = 'reportingApi'; -export const API_USAGE_ERROR_TYPE = 'reportingApiError'; - -// Management UI route -export const REPORTING_MANAGEMENT_HOME = '/app/management/insightsAndAlerting/reporting'; - -export const REPORTING_REDIRECT_LOCATOR_STORE_KEY = '__REPORTING_REDIRECT_LOCATOR_STORE_KEY__'; - -// Statuses -export enum JOB_STATUSES { - PENDING = 'pending', - PROCESSING = 'processing', - COMPLETED = 'completed', - FAILED = 'failed', - WARNINGS = 'completed_with_warnings', -} - // Test Subjects export const REPORT_TABLE_ID = 'reportJobListing'; export const REPORT_TABLE_ROW_ID = 'reportJobRow'; -// Job params require a `version` field as of 7.15.0. For older jobs set with -// automation that have no version value in the job params, we assume the -// intended version is 7.14.0 -export const UNVERSIONED_VERSION = '7.14.0'; export * from './routes'; diff --git a/x-pack/plugins/reporting/common/test/fixtures.ts b/x-pack/plugins/reporting/common/test/fixtures.ts index 16f748c0a15f7..1628fb9e6af80 100644 --- a/x-pack/plugins/reporting/common/test/fixtures.ts +++ b/x-pack/plugins/reporting/common/test/fixtures.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { ReportApiJSON } from '../types'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; import type { ReportMock } from './types'; const buildMockReport = (baseObj: ReportMock): ReportApiJSON => ({ diff --git a/x-pack/plugins/reporting/common/test/types.ts b/x-pack/plugins/reporting/common/test/types.ts index 83ebc1e3358cb..5a4b7ed8530a6 100644 --- a/x-pack/plugins/reporting/common/test/types.ts +++ b/x-pack/plugins/reporting/common/test/types.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { ReportApiJSON } from '../types'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; /** @internal */ export interface PayloadMock { diff --git a/x-pack/plugins/reporting/common/types.ts b/x-pack/plugins/reporting/common/types.ts deleted file mode 100644 index d541e2ed203d2..0000000000000 --- a/x-pack/plugins/reporting/common/types.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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 type { - BasePayload, - ReportOutput, - TaskRunMetrics, - TaskRunResult, -} from '@kbn/reporting-common/types'; -import type { JobId } from './constants'; - -export interface ReportDocumentHead { - _id: string; - _index: string; - _seq_no: number; - _primary_term: number; -} - -export interface ReportFields { - queue_time_ms?: number[]; // runtime field: started_at - created_at - execution_time_ms?: number[]; // runtime field: completed_at - started_at -} - -export interface ReportSource { - /* - * Required fields: populated in RequestHandler.enqueueJob when the request comes in to - * generate the report - */ - jobtype: string; // refers to `ExportTypeDefinition.jobType` - created_by: string | false; // username or `false` if security is disabled. Used for ensuring users can only access the reports they've created. - payload: BasePayload; - meta: { - // for telemetry - objectType: string; - layout?: string; - isDeprecated?: boolean; - }; - migration_version: string; // for reminding the user to update their POST URL - attempts: number; // initially populated as 0 - created_at: string; // timestamp in UTC - status: JobStatus; - - /* - * `output` is only populated if the report job is completed or failed. - */ - output: ReportOutput | null; - - /* - * Optional fields: populated when the job is claimed to execute, and after - * execution has finished - */ - kibana_name?: string; // for troubleshooting - kibana_id?: string; // for troubleshooting - timeout?: number; // for troubleshooting: the actual comparison uses the config setting xpack.reporting.queue.timeout - max_attempts?: number; // for troubleshooting: the actual comparison uses the config setting xpack.reporting.capture.maxAttempts - started_at?: string; // timestamp in UTC - completed_at?: string; // timestamp in UTC - process_expiration?: string | null; // timestamp in UTC - is overwritten with `null` when the job needs a retry - metrics?: TaskRunMetrics; -} - -/* - * The document created by Reporting to store in the .reporting index - */ -export interface ReportDocument extends ReportDocumentHead { - _source: ReportSource; -} - -/* - * JobStatus: - * - Begins as 'pending' - * - Changes to 'processing` when the job is claimed - * - Then 'completed' | 'failed' when execution is done - * If the job needs a retry, it reverts back to 'pending'. - */ -export type JobStatus = - | 'completed' // Report was successful - | 'completed_with_warnings' // The download available for troubleshooting - it **should** show a meaningful error - | 'pending' // Report job is waiting to be claimed - | 'processing' // Report job has been claimed and is executing - | 'failed'; // Report was not successful, and all retries are done. Nothing to download. - -/* - * Info API response: to avoid unnecessary large payloads on a network, the - * report query results do not include `payload.headers` or `output.content`, - * which can be long strings of meaningless text - */ -interface ReportSimple extends Omit { - payload: Omit; - output?: Omit; // is undefined for report jobs that are not completed - queue_time_ms?: number; - execution_time_ms?: number; -} - -/* - * The response format for all of the report job APIs - */ -export interface ReportApiJSON extends ReportSimple { - id: string; - index: string; -} - -export interface LicenseCheckResults { - enableLinks: boolean; - showLinks: boolean; - message: string; -} - -/* Notifier Toasts */ -export interface JobSummary { - id: JobId; - status: JobStatus; - jobtype: ReportSource['jobtype']; - title: ReportSource['payload']['title']; - errorCode?: ReportOutput['error_code']; - maxSizeReached: TaskRunResult['max_size_reached']; - csvContainsFormulas: TaskRunResult['csv_contains_formulas']; -} - -export interface JobSummarySet { - completed: JobSummary[]; - failed: JobSummary[]; -} diff --git a/x-pack/plugins/reporting/public/lib/job.tsx b/x-pack/plugins/reporting/public/lib/job.tsx index 7b5b0b4347a2b..149149e9bf516 100644 --- a/x-pack/plugins/reporting/public/lib/job.tsx +++ b/x-pack/plugins/reporting/public/lib/job.tsx @@ -10,10 +10,17 @@ import React from 'react'; import { EuiText, EuiTextColor } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { BaseParamsV2, ReportOutput, TaskRunResult } from '@kbn/reporting-common/types'; - -import { JobId, JobTypes, JOB_STATUSES } from '../../common/constants'; -import type { ReportApiJSON, ReportFields, ReportSource } from '../../common/types'; +import { JOB_STATUSES } from '@kbn/reporting-common'; +import type { + BaseParamsV2, + JobId, + ReportApiJSON, + ReportFields, + ReportOutput, + ReportSource, + TaskRunResult, +} from '@kbn/reporting-common/types'; +import { JobTypes } from '../../common/constants'; const { COMPLETED, FAILED, PENDING, PROCESSING, WARNINGS } = JOB_STATUSES; diff --git a/x-pack/plugins/reporting/public/lib/stream_handler.test.ts b/x-pack/plugins/reporting/public/lib/stream_handler.test.ts index ed3b973a95e64..3c2aef023022b 100644 --- a/x-pack/plugins/reporting/public/lib/stream_handler.test.ts +++ b/x-pack/plugins/reporting/public/lib/stream_handler.test.ts @@ -6,9 +6,12 @@ */ import sinon, { stub } from 'sinon'; + import { NotificationsStart } from '@kbn/core/public'; -import { coreMock, themeServiceMock, docLinksServiceMock } from '@kbn/core/public/mocks'; -import { JobSummary, ReportApiJSON } from '../../common/types'; +import { coreMock, docLinksServiceMock, themeServiceMock } from '@kbn/core/public/mocks'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; + +import { JobSummary } from '../types'; import { Job } from './job'; import { ReportingAPIClient } from './reporting_api_client'; import { ReportingNotifierStreamHandler } from './stream_handler'; diff --git a/x-pack/plugins/reporting/public/types.ts b/x-pack/plugins/reporting/public/types.ts index 3be354bada72e..705232e6f32e3 100644 --- a/x-pack/plugins/reporting/public/types.ts +++ b/x-pack/plugins/reporting/public/types.ts @@ -7,6 +7,30 @@ import type { CoreSetup, CoreStart } from '@kbn/core/public'; +import type { + JobId, + JobStatus, + ReportOutput, + ReportSource, + TaskRunResult, +} from '@kbn/reporting-common/types'; + +/* Notifier Toasts */ +export interface JobSummary { + id: JobId; + status: JobStatus; + jobtype: ReportSource['jobtype']; + title: ReportSource['payload']['title']; + errorCode?: ReportOutput['error_code']; + maxSizeReached: TaskRunResult['max_size_reached']; + csvContainsFormulas: TaskRunResult['csv_contains_formulas']; +} + +export interface JobSummarySet { + completed: JobSummary[]; + failed: JobSummary[]; +} + export interface KibanaContext { http: CoreSetup['http']; application: CoreStart['application']; diff --git a/x-pack/plugins/reporting/server/export_types/common/index.ts b/x-pack/plugins/reporting/server/export_types/common/index.ts deleted file mode 100644 index f2fec35ac9d02..0000000000000 --- a/x-pack/plugins/reporting/server/export_types/common/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* - * 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. - */ - -export interface TimeRangeParams { - min?: Date | string | number | null; - max?: Date | string | number | null; -} diff --git a/x-pack/plugins/reporting/server/lib/store/report.ts b/x-pack/plugins/reporting/server/lib/store/report.ts index 6f23c23e9066a..680b6936a4cc2 100644 --- a/x-pack/plugins/reporting/server/lib/store/report.ts +++ b/x-pack/plugins/reporting/server/lib/store/report.ts @@ -8,18 +8,16 @@ import { omit } from 'lodash'; import moment from 'moment'; import Puid from 'puid'; -import { JOB_STATUSES } from '../../../common/constants'; + +import { JOB_STATUSES } from '@kbn/reporting-common'; import { ReportApiJSON, - ReportDocument, ReportDocumentHead, ReportFields, ReportSource, -} from '../../../common/types'; -import type { ReportTaskParams } from '../tasks'; +} from '@kbn/reporting-common/types'; -export type { ReportDocument }; -export type { ReportApiJSON, ReportSource }; +import type { ReportTaskParams } from '../tasks'; const puid = new Puid(); export const MIGRATION_VERSION = '7.14.0'; diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.test.ts b/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.test.ts index 00a47c703ff90..73aa630b671d8 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.test.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.test.ts @@ -7,11 +7,11 @@ import { Readable } from 'stream'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; import { CSV_JOB_TYPE } from '@kbn/reporting-export-types-csv-common'; import { PDF_JOB_TYPE, PDF_JOB_TYPE_V2 } from '@kbn/reporting-export-types-pdf-common'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; -import { ReportApiJSON } from '../../../../common/types'; import { ContentStream, getContentStream, statuses } from '../../../lib'; import { createMockReportingCore } from '../../../test_helpers'; import { getDocumentPayloadFactory } from './get_document_payload'; diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.ts b/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.ts index 588f5c9f661b3..b519238d9a0a3 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.ts @@ -5,13 +5,14 @@ * 2.0. */ -import { CSV_JOB_TYPE, CSV_JOB_TYPE_DEPRECATED } from '@kbn/reporting-export-types-csv-common'; +import { Stream } from 'stream'; import { ResponseHeaders } from '@kbn/core-http-server'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; +import { CSV_JOB_TYPE, CSV_JOB_TYPE_DEPRECATED } from '@kbn/reporting-export-types-csv-common'; import { ExportType } from '@kbn/reporting-server'; -import { Stream } from 'stream'; + import { ReportingCore } from '../../..'; -import { ReportApiJSON } from '../../../../common/types'; import { getContentStream, statuses } from '../../../lib'; import { jobsQueryFactory } from './jobs_query'; diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/job_management_pre_routing.ts b/x-pack/plugins/reporting/server/routes/common/jobs/job_management_pre_routing.ts index 79221c0c49d34..cfe9df9cebc40 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/job_management_pre_routing.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/job_management_pre_routing.ts @@ -6,11 +6,12 @@ */ import Boom from '@hapi/boom'; + import { IKibanaResponse, kibanaResponseFactory } from '@kbn/core/server'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; import { i18n } from '@kbn/i18n'; import { Counters } from '..'; import { ReportingCore } from '../../..'; -import { ReportApiJSON } from '../../../lib/store/report'; import { ReportingUser } from '../../../types'; import { jobsQueryFactory } from './jobs_query'; diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.ts b/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.ts index 87bf38648bd2f..102b41bb11322 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.ts @@ -5,12 +5,12 @@ * 2.0. */ -import { estypes, errors, TransportResult } from '@elastic/elasticsearch'; +import { TransportResult, errors, estypes } from '@elastic/elasticsearch'; import type { ElasticsearchClient } from '@kbn/core/server'; import { i18n } from '@kbn/i18n'; +import { REPORTING_SYSTEM_INDEX } from '@kbn/reporting-common'; +import { ReportApiJSON, ReportSource } from '@kbn/reporting-common/types'; import type { ReportingCore } from '../../..'; -import { REPORTING_SYSTEM_INDEX } from '../../../../common/constants'; -import type { ReportApiJSON, ReportSource } from '../../../../common/types'; import { statuses } from '../../../lib/statuses'; import { Report } from '../../../lib/store'; import { runtimeFieldKeys, runtimeFields } from '../../../lib/store/runtime_fields'; diff --git a/x-pack/plugins/reporting/server/types.ts b/x-pack/plugins/reporting/server/types.ts index a3c12d4c0afb7..f0573af0651f1 100644 --- a/x-pack/plugins/reporting/server/types.ts +++ b/x-pack/plugins/reporting/server/types.ts @@ -13,6 +13,7 @@ import type { PluginSetupContract as FeaturesPluginSetup } from '@kbn/features-p import type { FieldFormatsStart } from '@kbn/field-formats-plugin/server'; import type { LicensingPluginStart } from '@kbn/licensing-plugin/server'; import type { UrlOrUrlLocatorTuple } from '@kbn/reporting-common/types'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; import type { PdfScreenshotOptions as BasePdfScreenshotOptions, @@ -31,7 +32,6 @@ import type { } from '@kbn/task-manager-plugin/server'; import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server'; -import { ReportApiJSON } from '../common/types'; import type { ReportingConfigType } from './config'; import { ReportingCore } from './core'; import { ExportTypesRegistry } from './lib'; From f7b58ad2895bec1c4a11e8cae3f4a0b7c1e5a3dc Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 12:41:21 -0700 Subject: [PATCH 08/25] Clean up odd imports --- .../kbn-reporting/export_types/csv/csv_searchsource.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/kbn-reporting/export_types/csv/csv_searchsource.test.ts b/packages/kbn-reporting/export_types/csv/csv_searchsource.test.ts index aef32cbb2f775..796cc8de4eaad 100644 --- a/packages/kbn-reporting/export_types/csv/csv_searchsource.test.ts +++ b/packages/kbn-reporting/export_types/csv/csv_searchsource.test.ts @@ -24,7 +24,6 @@ import { CancellationToken } from '@kbn/reporting-common'; import { discoverPluginMock } from '@kbn/discover-plugin/server/mocks'; import { dataPluginMock } from '@kbn/data-plugin/server/mocks'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; -import { createMockScreenshottingStart } from '@kbn/screenshotting-plugin/server/mock'; import { CsvSearchSourceExportType } from '.'; @@ -69,7 +68,6 @@ beforeAll(async () => { uiSettings: mockCoreStart.uiSettings, discover: discoverPluginMock.createStartContract(), data: dataPluginMock.createStartContract(), - screenshotting: createMockScreenshottingStart(), }); }); From aad708df7457a25a9d1194cdbf90a0e89b085be9 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 13:05:12 -0700 Subject: [PATCH 09/25] Cleaning up with packages --- packages/kbn-generate-csv/kibana.jsonc | 2 +- .../kbn-generate-csv/src/generate_csv.test.ts | 2 +- packages/kbn-generate-csv/src/generate_csv.ts | 2 +- .../src/get_export_settings.test.ts | 4 +- .../src/get_export_settings.ts | 2 +- packages/kbn-generate-csv/tsconfig.json | 1 - packages/kbn-reporting/common/constants.ts | 73 ++++++++- packages/kbn-reporting/common/types.ts | 17 +- packages/kbn-reporting/mocks_server/index.ts | 4 +- .../kbn-reporting/mocks_server/tsconfig.json | 2 +- packages/kbn-reporting/server/config.ts | 152 ++++++++++++++++++ packages/kbn-reporting/server/export_type.ts | 6 +- .../kbn-reporting/server/generate_pdf_v2.ts | 5 +- .../server/get_full_redirect_app_url.test.ts | 2 +- .../server/get_full_redirect_app_url.ts | 4 +- .../server/get_full_urls.test.ts | 6 +- .../kbn-reporting/server/get_full_urls.ts | 6 +- packages/kbn-reporting/server/index.ts | 7 +- packages/kbn-reporting/server/tsconfig.json | 1 - .../reporting/common/constants/index.ts | 64 +------- .../reporting/common/schema_utils.test.ts | 16 -- .../plugins/reporting/public/lib/job.test.ts | 3 +- x-pack/plugins/reporting/public/lib/job.tsx | 13 +- .../reporting/public/lib/license_check.ts | 2 +- .../reporting_api_client.ts | 17 +- .../reporting/public/lib/stream_handler.ts | 24 +-- .../management/components/ilm_policy_link.tsx | 3 +- .../ilm_policy_migration_needed_callout.tsx | 8 +- .../components/report_info_flyout_content.tsx | 15 +- .../components/report_status_indicator.tsx | 12 +- .../public/management/report_listing.tsx | 19 ++- .../reporting/public/management/utils.ts | 4 +- .../notifier/job_completion_notifications.ts | 3 +- .../public/notifier/job_download_button.tsx | 4 +- .../reporting/public/notifier/job_failure.tsx | 2 +- .../reporting/public/notifier/job_success.tsx | 8 +- .../reporting/public/notifier/job_warning.tsx | 8 +- .../public/notifier/job_warning_formulas.tsx | 8 +- .../public/notifier/job_warning_max_size.tsx | 8 +- x-pack/plugins/reporting/public/plugin.ts | 10 +- .../public/redirect/redirect_app.tsx | 2 +- .../plugins/reporting/server/config/index.ts | 2 +- .../reporting/server/config/ui_settings.ts | 5 +- .../migrate_existing_indices_ilm_policy.ts | 5 +- .../server/lib/check_params_version.ts | 2 +- .../reporting/server/lib/content_stream.ts | 10 +- .../check_ilm_migration_status.ts | 2 +- .../server/lib/event_logger/logger.ts | 2 +- x-pack/plugins/reporting/server/lib/index.ts | 1 - .../plugins/reporting/server/lib/statuses.ts | 16 -- .../ilm_policy_manager/ilm_policy_manager.ts | 3 +- .../reporting/server/lib/store/report.ts | 4 +- .../reporting/server/lib/store/store.ts | 24 ++- .../server/lib/tasks/execute_report.ts | 16 +- .../server/lib/tasks/monitor_reports.ts | 9 +- x-pack/plugins/reporting/server/plugin.ts | 2 +- .../server/routes/common/get_counter.ts | 2 +- .../common/jobs/get_document_payload.test.ts | 11 +- .../common/jobs/get_document_payload.ts | 7 +- .../routes/common/jobs/get_job_routes.ts | 2 +- .../routes/common/jobs/jobs_query.test.ts | 6 +- .../server/routes/common/jobs/jobs_query.ts | 5 +- .../internal/deprecations/deprecations.ts | 3 +- .../server/usage/get_export_stats.ts | 2 +- .../server/usage/get_reporting_usage.ts | 2 +- .../reporting_and_security/csv_v2.ts | 2 +- .../reporting_and_security/error_codes.ts | 2 +- .../generate_csv_discover.ts | 2 +- .../job_apis_csv.ts | 2 +- 69 files changed, 411 insertions(+), 291 deletions(-) create mode 100644 packages/kbn-reporting/server/config.ts delete mode 100644 x-pack/plugins/reporting/common/schema_utils.test.ts delete mode 100644 x-pack/plugins/reporting/server/lib/statuses.ts diff --git a/packages/kbn-generate-csv/kibana.jsonc b/packages/kbn-generate-csv/kibana.jsonc index 9769151714f2a..d29b33047007c 100644 --- a/packages/kbn-generate-csv/kibana.jsonc +++ b/packages/kbn-generate-csv/kibana.jsonc @@ -1,5 +1,5 @@ { - "type": "shared-common", + "type": "shared-server", "id": "@kbn/generate-csv", "owner": "@elastic/appex-sharedux" } diff --git a/packages/kbn-generate-csv/src/generate_csv.test.ts b/packages/kbn-generate-csv/src/generate_csv.test.ts index 48d61ca500b31..22857f37afdaf 100644 --- a/packages/kbn-generate-csv/src/generate_csv.test.ts +++ b/packages/kbn-generate-csv/src/generate_csv.test.ts @@ -25,7 +25,7 @@ import { IScopedSearchClient } from '@kbn/data-plugin/server'; import { dataPluginMock } from '@kbn/data-plugin/server/mocks'; import { FieldFormatsRegistry } from '@kbn/field-formats-plugin/common'; import { CancellationToken } from '@kbn/reporting-common'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import { JobParamsCSV } from '@kbn/reporting-export-types-csv-common'; import { UI_SETTINGS_CSV_QUOTE_VALUES, diff --git a/packages/kbn-generate-csv/src/generate_csv.ts b/packages/kbn-generate-csv/src/generate_csv.ts index 5d7cb09799002..d36a9b9da1231 100644 --- a/packages/kbn-generate-csv/src/generate_csv.ts +++ b/packages/kbn-generate-csv/src/generate_csv.ts @@ -27,7 +27,7 @@ import { byteSizeValueToNumber, } from '@kbn/reporting-common'; import type { TaskRunResult } from '@kbn/reporting-common/types'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import { JobParamsCSV } from '@kbn/reporting-export-types-csv-common'; import { CONTENT_TYPE_CSV } from './constants'; diff --git a/packages/kbn-generate-csv/src/get_export_settings.test.ts b/packages/kbn-generate-csv/src/get_export_settings.test.ts index 70d576dc9a9e6..18b2525cf7942 100644 --- a/packages/kbn-generate-csv/src/get_export_settings.test.ts +++ b/packages/kbn-generate-csv/src/get_export_settings.test.ts @@ -6,13 +6,13 @@ * Side Public License, v 1. */ -import { IUiSettingsClient } from '@kbn/core/server'; +import type { IUiSettingsClient } from '@kbn/core/server'; import { loggingSystemMock, savedObjectsClientMock, uiSettingsServiceMock, } from '@kbn/core/server/mocks'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import { UI_SETTINGS_CSV_QUOTE_VALUES, diff --git a/packages/kbn-generate-csv/src/get_export_settings.ts b/packages/kbn-generate-csv/src/get_export_settings.ts index 66c73895ec2d8..f6804b5d17572 100644 --- a/packages/kbn-generate-csv/src/get_export_settings.ts +++ b/packages/kbn-generate-csv/src/get_export_settings.ts @@ -9,7 +9,7 @@ import { ByteSizeValue } from '@kbn/config-schema'; import type { IUiSettingsClient, Logger } from '@kbn/core/server'; import { createEscapeValue } from '@kbn/data-plugin/common'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import { CSV_BOM_CHARS, UI_SETTINGS_CSV_QUOTE_VALUES, diff --git a/packages/kbn-generate-csv/tsconfig.json b/packages/kbn-generate-csv/tsconfig.json index f4096aa2c28b5..54bb4b7615309 100644 --- a/packages/kbn-generate-csv/tsconfig.json +++ b/packages/kbn-generate-csv/tsconfig.json @@ -25,6 +25,5 @@ "@kbn/i18n", "@kbn/reporting-common", "@kbn/reporting-export-types-csv-common", - "@kbn/reporting-config-server", ] } diff --git a/packages/kbn-reporting/common/constants.ts b/packages/kbn-reporting/common/constants.ts index a9f7c5ffa3757..26aafa77ed4a8 100644 --- a/packages/kbn-reporting/common/constants.ts +++ b/packages/kbn-reporting/common/constants.ts @@ -8,6 +8,69 @@ export const PLUGIN_ID = 'reporting'; +// Export Type Sets +import { + CSV_JOB_TYPE, + CSV_JOB_TYPE_DEPRECATED, + CSV_JOB_TYPE_V2, + CSV_REPORT_TYPE, + CSV_REPORT_TYPE_V2, +} from '@kbn/reporting-export-types-csv-common'; +import { + PDF_JOB_TYPE, + PDF_JOB_TYPE_V2, + PDF_REPORT_TYPE, + PDF_REPORT_TYPE_V2, +} from '@kbn/reporting-export-types-pdf-common'; +import { + PNG_JOB_TYPE, + PNG_JOB_TYPE_V2, + PNG_REPORT_TYPE, + PNG_REPORT_TYPE_V2, +} from '@kbn/reporting-export-types-png-common'; + +export const ALLOWED_JOB_CONTENT_TYPES = [ + 'application/json', + 'application/pdf', + 'text/csv', + 'image/png', + 'text/plain', +]; + +export const reportTypes = [ + CSV_REPORT_TYPE, + CSV_REPORT_TYPE_V2, + PDF_REPORT_TYPE, + PDF_REPORT_TYPE_V2, + PNG_REPORT_TYPE, + PNG_REPORT_TYPE_V2, +]; + +export const jobTypes = [ + CSV_JOB_TYPE, + CSV_JOB_TYPE_V2, + PDF_JOB_TYPE, + PDF_JOB_TYPE_V2, + PNG_JOB_TYPE, + PNG_JOB_TYPE_V2, +]; + +type ReportTypeDeclaration = typeof reportTypes; +export type ReportTypes = ReportTypeDeclaration[keyof ReportTypeDeclaration]; + +type JobTypeDeclaration = typeof jobTypes; +export type JobTypes = JobTypeDeclaration[keyof JobTypeDeclaration]; + +export const USES_HEADLESS_JOB_TYPES = [ + PDF_JOB_TYPE, + PNG_JOB_TYPE, + PDF_JOB_TYPE_V2, + PNG_JOB_TYPE_V2, +]; + +export const DEPRECATED_JOB_TYPES = [CSV_JOB_TYPE_DEPRECATED]; + +// APM export const REPORTING_TRANSACTION_TYPE = PLUGIN_ID; export const REPORTING_REDIRECT_LOCATOR_STORE_KEY = '__REPORTING_REDIRECT_LOCATOR_STORE_KEY__'; @@ -48,8 +111,14 @@ export const API_USAGE_ERROR_TYPE = 'reportingApiError'; // Management UI route export const REPORTING_MANAGEMENT_HOME = '/app/management/insightsAndAlerting/reporting'; -// Statuses -export enum JOB_STATUSES { +/* + * JobStatus: + * - Begins as 'pending' + * - Changes to 'processing` when the job is claimed + * - Then 'completed' | 'failed' when execution is done + * If the job needs a retry, it reverts back to 'pending'. + */ +export enum JOB_STATUS { PENDING = 'pending', PROCESSING = 'processing', COMPLETED = 'completed', diff --git a/packages/kbn-reporting/common/types.ts b/packages/kbn-reporting/common/types.ts index 6002f82b11b89..a208bd24226f1 100644 --- a/packages/kbn-reporting/common/types.ts +++ b/packages/kbn-reporting/common/types.ts @@ -10,6 +10,7 @@ import type { LayoutParams, PerformanceMetrics as ScreenshotMetrics, } from '@kbn/screenshotting-plugin/common'; +import { JOB_STATUS } from './constants'; import type { LocatorParams } from './url'; export * from './url'; @@ -129,7 +130,7 @@ export interface ReportSource { migration_version: string; // for reminding the user to update their POST URL attempts: number; // initially populated as 0 created_at: string; // timestamp in UTC - status: JobStatus; + status: JOB_STATUS; /* * `output` is only populated if the report job is completed or failed. @@ -157,20 +158,6 @@ export interface ReportDocument extends ReportDocumentHead { _source: ReportSource; } -/* - * JobStatus: - * - Begins as 'pending' - * - Changes to 'processing` when the job is claimed - * - Then 'completed' | 'failed' when execution is done - * If the job needs a retry, it reverts back to 'pending'. - */ -export type JobStatus = - | 'completed' // Report was successful - | 'completed_with_warnings' // The download available for troubleshooting - it **should** show a meaningful error - | 'pending' // Report job is waiting to be claimed - | 'processing' // Report job has been claimed and is executing - | 'failed'; // Report was not successful, and all retries are done. Nothing to download. - /* * Info API response: to avoid unnecessary large payloads on a network, the * report query results do not include `payload.headers` or `output.content`, diff --git a/packages/kbn-reporting/mocks_server/index.ts b/packages/kbn-reporting/mocks_server/index.ts index e6395c9bbe9eb..8367754a97f34 100644 --- a/packages/kbn-reporting/mocks_server/index.ts +++ b/packages/kbn-reporting/mocks_server/index.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ -import { DeepPartial } from 'utility-types'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; +import type { DeepPartial } from 'utility-types'; +import type { ReportingConfigType } from '@kbn/reporting-server'; export const createMockConfigSchema = ( overrides: DeepPartial = {} diff --git a/packages/kbn-reporting/mocks_server/tsconfig.json b/packages/kbn-reporting/mocks_server/tsconfig.json index 1027c66fc5837..ef36887c668e2 100644 --- a/packages/kbn-reporting/mocks_server/tsconfig.json +++ b/packages/kbn-reporting/mocks_server/tsconfig.json @@ -14,6 +14,6 @@ "target/**/*" ], "kbn_references": [ - "@kbn/reporting-config-server", + "@kbn/reporting-server", ] } diff --git a/packages/kbn-reporting/server/config.ts b/packages/kbn-reporting/server/config.ts new file mode 100644 index 0000000000000..f7c910d9c425b --- /dev/null +++ b/packages/kbn-reporting/server/config.ts @@ -0,0 +1,152 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ByteSizeValue, offeringBasedSchema, schema, TypeOf } from '@kbn/config-schema'; +import ipaddr from 'ipaddr.js'; +import { sum } from 'lodash'; +import moment from 'moment'; + +const KibanaServerSchema = schema.object({ + hostname: schema.maybe( + schema.string({ + hostname: true, + validate(value) { + if (ipaddr.isValid(value) && !sum(ipaddr.parse(value).toByteArray())) { + // prevent setting a hostname that fails in Chromium on Windows + return `cannot use '0.0.0.0' as Kibana host name, consider using the default (localhost) instead`; + } + }, + }) + ), + port: schema.maybe(schema.number()), + protocol: schema.maybe( + schema.string({ + validate(value) { + if (!/^https?$/.test(value)) { + return 'must be "http" or "https"'; + } + }, + }) + ), +}); // default values are all dynamic in createConfig$ + +const QueueSchema = schema.object({ + indexInterval: schema.string({ defaultValue: 'week' }), + pollEnabled: schema.boolean({ defaultValue: true }), + pollInterval: schema.oneOf([schema.number(), schema.duration()], { + defaultValue: moment.duration({ seconds: 3 }), + }), + pollIntervalErrorMultiplier: schema.number({ defaultValue: 10 }), + timeout: schema.oneOf([schema.number(), schema.duration()], { + defaultValue: moment.duration({ minutes: 4 }), + }), +}); + +const CaptureSchema = schema.object({ + maxAttempts: schema.conditional( + schema.contextRef('dist'), + true, + schema.number({ defaultValue: 3 }), + schema.number({ defaultValue: 1 }) + ), +}); + +const CsvSchema = schema.object({ + checkForFormulas: schema.boolean({ defaultValue: true }), + escapeFormulaValues: schema.boolean({ defaultValue: false }), + enablePanelActionDownload: schema.boolean({ defaultValue: true }), + maxSizeBytes: schema.oneOf([schema.number(), schema.byteSize()], { + defaultValue: ByteSizeValue.parse('250mb'), + }), + useByteOrderMarkEncoding: schema.boolean({ defaultValue: false }), + scroll: schema.object({ + duration: schema.string({ + defaultValue: '30s', // this value is passed directly to ES, so string only format is preferred + validate(value) { + if (!/^[0-9]+(d|h|m|s|ms|micros|nanos)$/.test(value)) { + return 'must be a duration string'; + } + }, + }), + size: schema.number({ defaultValue: 500 }), + }), +}); + +const EncryptionKeySchema = schema.conditional( + schema.contextRef('dist'), + true, + schema.maybe(schema.string()), // default value is dynamic in createConfig$ + schema.string({ defaultValue: 'a'.repeat(32) }) +); + +const RolesSchema = schema.object({ + enabled: offeringBasedSchema({ + serverless: schema.boolean({ defaultValue: false }), + traditional: schema.boolean({ defaultValue: true }), + }), // true: use ES API for access control (deprecated in 7.x). false: use Kibana API for application features (8.0) + allow: offeringBasedSchema({ + serverless: schema.arrayOf(schema.string(), { defaultValue: [] }), + traditional: schema.arrayOf(schema.string(), { defaultValue: ['reporting_user'] }), + }), +}); + +// Browser side polling: job completion notifier, management table auto-refresh +// NOTE: can not use schema.duration, a bug prevents it being passed to the browser correctly +const PollSchema = schema.object({ + jobCompletionNotifier: schema.object({ + interval: schema.number({ defaultValue: 10000 }), + intervalErrorMultiplier: schema.number({ defaultValue: 5 }), // deprecated as unused since 7.10 + }), + jobsRefresh: schema.object({ + interval: schema.number({ defaultValue: 5000 }), + intervalErrorMultiplier: schema.number({ defaultValue: 5 }), // deprecated as unused since 7.10 + }), +}); + +const ExportTypeSchema = schema.object({ + // Csv reports are enabled in all offerings + csv: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + }), + // Png reports are disabled in serverless + png: schema.object({ + enabled: offeringBasedSchema({ + serverless: schema.boolean({ defaultValue: false }), + traditional: schema.boolean({ defaultValue: true }), + }), + }), + // Pdf reports are disabled in serverless + pdf: schema.object({ + enabled: offeringBasedSchema({ + serverless: schema.boolean({ defaultValue: false }), + traditional: schema.boolean({ defaultValue: true }), + }), + }), +}); + +const SettingsSchema = schema.object({ + enabled: offeringBasedSchema({ + serverless: schema.boolean({ defaultValue: false }), + traditional: schema.boolean({ defaultValue: true }), + }), +}); + +export const ConfigSchema = schema.object({ + enabled: schema.boolean({ defaultValue: true }), + kibanaServer: KibanaServerSchema, + queue: QueueSchema, + capture: CaptureSchema, + csv: CsvSchema, + encryptionKey: EncryptionKeySchema, + roles: RolesSchema, + poll: PollSchema, + export_types: ExportTypeSchema, + statefulSettings: SettingsSchema, +}); + +export type ReportingConfigType = TypeOf; diff --git a/packages/kbn-reporting/server/export_type.ts b/packages/kbn-reporting/server/export_type.ts index 6adfa041c18fa..7765fe6dd7e26 100644 --- a/packages/kbn-reporting/server/export_type.ts +++ b/packages/kbn-reporting/server/export_type.ts @@ -22,13 +22,13 @@ import type { SavedObjectsServiceStart } from '@kbn/core-saved-objects-server'; import type { UiSettingsServiceStart } from '@kbn/core-ui-settings-server'; import type { LicenseType } from '@kbn/licensing-plugin/common/types'; import type { Logger } from '@kbn/logging'; -import { ReportingServerInfo } from '@kbn/reporting-common/types'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; +import type { ReportingServerInfo } from '@kbn/reporting-common/types'; import type { ScreenshottingStart } from '@kbn/screenshotting-plugin/server'; import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common'; import type { SpacesPluginSetup } from '@kbn/spaces-plugin/server'; -import { CreateJobFn, RunTaskFn } from './types'; +import type { CreateJobFn, RunTaskFn } from './types'; +import type { ReportingConfigType } from '.'; export interface BaseExportTypeSetupDeps { basePath: Pick; diff --git a/packages/kbn-reporting/server/generate_pdf_v2.ts b/packages/kbn-reporting/server/generate_pdf_v2.ts index af6b7b208723e..3504614959548 100644 --- a/packages/kbn-reporting/server/generate_pdf_v2.ts +++ b/packages/kbn-reporting/server/generate_pdf_v2.ts @@ -10,10 +10,11 @@ import { Observable } from 'rxjs'; import { mergeMap, tap } from 'rxjs/operators'; import type { LocatorParams, ReportingServerInfo } from '@kbn/reporting-common/types'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; -import { TaskPayloadPDFV2 } from '@kbn/reporting-export-types-pdf-common'; +import type { TaskPayloadPDFV2 } from '@kbn/reporting-export-types-pdf-common'; import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; import type { UrlOrUrlWithContext } from '@kbn/screenshotting-plugin/server/screenshots'; + +import type { ReportingConfigType } from '.'; import { getFullRedirectAppUrl } from '.'; import { getTracker } from './pdf_tracker'; diff --git a/packages/kbn-reporting/server/get_full_redirect_app_url.test.ts b/packages/kbn-reporting/server/get_full_redirect_app_url.test.ts index c10ed022a0b5e..00c19f09c276c 100644 --- a/packages/kbn-reporting/server/get_full_redirect_app_url.test.ts +++ b/packages/kbn-reporting/server/get_full_redirect_app_url.test.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ -import { ReportingConfigType } from '@kbn/reporting-config-server'; import { getFullRedirectAppUrl } from './get_full_redirect_app_url'; +import type { ReportingConfigType } from '.'; describe('getFullRedirectAppUrl', () => { const mockConfig = { kibanaServer: {} } as unknown as ReportingConfigType; diff --git a/packages/kbn-reporting/server/get_full_redirect_app_url.ts b/packages/kbn-reporting/server/get_full_redirect_app_url.ts index b80241b82258d..e09f7b8ceed9d 100644 --- a/packages/kbn-reporting/server/get_full_redirect_app_url.ts +++ b/packages/kbn-reporting/server/get_full_redirect_app_url.ts @@ -9,8 +9,8 @@ import { format } from 'url'; import { buildKibanaPath, getRedirectAppPath } from '@kbn/reporting-common'; -import { ReportingServerInfo } from '@kbn/reporting-common/types'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; +import type { ReportingServerInfo } from '@kbn/reporting-common/types'; +import type { ReportingConfigType } from '.'; export function getFullRedirectAppUrl( config: ReportingConfigType, diff --git a/packages/kbn-reporting/server/get_full_urls.test.ts b/packages/kbn-reporting/server/get_full_urls.test.ts index fd644233a52dd..27a3ea434750b 100644 --- a/packages/kbn-reporting/server/get_full_urls.test.ts +++ b/packages/kbn-reporting/server/get_full_urls.test.ts @@ -6,10 +6,10 @@ * Side Public License, v 1. */ -import { ReportingServerInfo } from '@kbn/reporting-common/types'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; -import { TaskPayloadPDF } from '@kbn/reporting-export-types-pdf-common'; +import type { ReportingServerInfo } from '@kbn/reporting-common/types'; +import type { TaskPayloadPDF } from '@kbn/reporting-export-types-pdf-common'; +import type { ReportingConfigType } from '.'; import { getFullUrls } from './get_full_urls'; const getMockJob = (base: object) => base as TaskPayloadPDF; diff --git a/packages/kbn-reporting/server/get_full_urls.ts b/packages/kbn-reporting/server/get_full_urls.ts index 215b61feaa072..b79b3d2f78c76 100644 --- a/packages/kbn-reporting/server/get_full_urls.ts +++ b/packages/kbn-reporting/server/get_full_urls.ts @@ -13,10 +13,10 @@ import { UrlWithStringQuery, } from 'url'; -import { ReportingServerInfo } from '@kbn/reporting-common/types'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; -import { TaskPayloadPDF } from '@kbn/reporting-export-types-pdf-common'; +import type { ReportingServerInfo } from '@kbn/reporting-common/types'; +import type { TaskPayloadPDF } from '@kbn/reporting-export-types-pdf-common'; +import type { ReportingConfigType } from '.'; import { getAbsoluteUrlFactory } from './get_absolute_url'; import { validateUrls } from './validate_urls'; diff --git a/packages/kbn-reporting/server/index.ts b/packages/kbn-reporting/server/index.ts index e34730b96e8b2..b177c953085b4 100644 --- a/packages/kbn-reporting/server/index.ts +++ b/packages/kbn-reporting/server/index.ts @@ -9,7 +9,6 @@ export { cryptoFactory } from './crypto'; export { decryptJobHeaders } from './decrypt_job_headers'; export { ExportType } from './export_type'; -export type { BaseExportTypeSetupDeps, BaseExportTypeStartDeps } from './export_type'; export { generatePdfObservable } from './generate_pdf'; export { generatePdfObservableV2 } from './generate_pdf_v2'; export { generatePngObservable } from './generate_png'; @@ -19,5 +18,9 @@ export { getFullRedirectAppUrl } from './get_full_redirect_app_url'; export { getFullUrls } from './get_full_urls'; export { getTracker } from './pdf_tracker'; export { getFieldFormats, setFieldFormats } from './services'; -export * from './types'; export { validateUrls } from './validate_urls'; + +export type { BaseExportTypeSetupDeps, BaseExportTypeStartDeps } from './export_type'; +export * from './types'; + +export { ConfigSchema, ReportingConfigType } from './config'; diff --git a/packages/kbn-reporting/server/tsconfig.json b/packages/kbn-reporting/server/tsconfig.json index 7bc92e31bddb5..5dbd30b3e0cc5 100644 --- a/packages/kbn-reporting/server/tsconfig.json +++ b/packages/kbn-reporting/server/tsconfig.json @@ -34,6 +34,5 @@ "@kbn/core-http-router-server-internal", "@kbn/core-http-request-handler-context-server", "@kbn/reporting-export-types-pdf-common", - "@kbn/reporting-config-server", ] } diff --git a/x-pack/plugins/reporting/common/constants/index.ts b/x-pack/plugins/reporting/common/constants/index.ts index d03c5d37d67b5..1424ee18b7be8 100644 --- a/x-pack/plugins/reporting/common/constants/index.ts +++ b/x-pack/plugins/reporting/common/constants/index.ts @@ -5,70 +5,8 @@ * 2.0. */ -import { CONTENT_TYPE_CSV } from '@kbn/generate-csv/src/constants'; -import { - CSV_JOB_TYPE, - CSV_JOB_TYPE_DEPRECATED, - CSV_JOB_TYPE_V2, - CSV_REPORT_TYPE, - CSV_REPORT_TYPE_V2, -} from '@kbn/reporting-export-types-csv-common'; -import { - PDF_JOB_TYPE, - PDF_JOB_TYPE_V2, - PDF_REPORT_TYPE, - PDF_REPORT_TYPE_V2, -} from '@kbn/reporting-export-types-pdf-common'; -import { - PNG_JOB_TYPE, - PNG_JOB_TYPE_V2, - PNG_REPORT_TYPE, - PNG_REPORT_TYPE_V2, -} from '@kbn/reporting-export-types-png-common'; - -export const ALLOWED_JOB_CONTENT_TYPES = [ - 'application/json', - 'application/pdf', - CONTENT_TYPE_CSV, - 'image/png', - 'text/plain', -]; - -export const reportTypes = [ - CSV_REPORT_TYPE, - CSV_REPORT_TYPE_V2, - PDF_REPORT_TYPE, - PDF_REPORT_TYPE_V2, - PNG_REPORT_TYPE, - PNG_REPORT_TYPE_V2, -]; - -export const jobTypes = [ - CSV_JOB_TYPE, - CSV_JOB_TYPE_V2, - PDF_JOB_TYPE, - PDF_JOB_TYPE_V2, - PNG_JOB_TYPE, - PNG_JOB_TYPE_V2, -]; - -type ReportTypeDeclaration = typeof reportTypes; -export type ReportTypes = ReportTypeDeclaration[keyof ReportTypeDeclaration]; - -type JobTypeDeclaration = typeof jobTypes; -export type JobTypes = JobTypeDeclaration[keyof JobTypeDeclaration]; - -export const USES_HEADLESS_JOB_TYPES = [ - PDF_JOB_TYPE, - PNG_JOB_TYPE, - PDF_JOB_TYPE_V2, - PNG_JOB_TYPE_V2, -]; - -export const DEPRECATED_JOB_TYPES = [CSV_JOB_TYPE_DEPRECATED]; +export * from './routes'; // Test Subjects export const REPORT_TABLE_ID = 'reportJobListing'; export const REPORT_TABLE_ROW_ID = 'reportJobRow'; - -export * from './routes'; diff --git a/x-pack/plugins/reporting/common/schema_utils.test.ts b/x-pack/plugins/reporting/common/schema_utils.test.ts deleted file mode 100644 index 6e9bb2db75437..0000000000000 --- a/x-pack/plugins/reporting/common/schema_utils.test.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 moment from 'moment'; -import { numberToDuration } from './schema_utils'; - -describe('Schema Utils', () => { - it('numberToDuration converts a number/Duration into a Duration object', () => { - expect(numberToDuration(500)).toMatchInlineSnapshot(`"PT0.5S"`); - expect(numberToDuration(moment.duration(1, 'hour'))).toMatchInlineSnapshot(`"PT1H"`); - }); -}); diff --git a/x-pack/plugins/reporting/public/lib/job.test.ts b/x-pack/plugins/reporting/public/lib/job.test.ts index 3f1e64d57daf8..d8be3b3e7060b 100644 --- a/x-pack/plugins/reporting/public/lib/job.test.ts +++ b/x-pack/plugins/reporting/public/lib/job.test.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { jobTypes } from '../../common/constants'; +import { jobTypes } from '@kbn/reporting-common'; + import { mockJobs } from '../../common/test'; import { Job } from './job'; diff --git a/x-pack/plugins/reporting/public/lib/job.tsx b/x-pack/plugins/reporting/public/lib/job.tsx index 149149e9bf516..38fd9b70b0a74 100644 --- a/x-pack/plugins/reporting/public/lib/job.tsx +++ b/x-pack/plugins/reporting/public/lib/job.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { EuiText, EuiTextColor } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { JOB_STATUSES } from '@kbn/reporting-common'; +import { JOB_STATUS, JobTypes } from '@kbn/reporting-common'; import type { BaseParamsV2, JobId, @@ -20,9 +20,8 @@ import type { ReportSource, TaskRunResult, } from '@kbn/reporting-common/types'; -import { JobTypes } from '../../common/constants'; -const { COMPLETED, FAILED, PENDING, PROCESSING, WARNINGS } = JOB_STATUSES; +const { COMPLETED, FAILED, PENDING, PROCESSING, WARNINGS } = JOB_STATUS; type ReportPayload = ReportSource['payload']; @@ -47,7 +46,7 @@ export class Job { public readonly created_at: ReportSource['created_at']; public readonly started_at: ReportSource['started_at']; public readonly completed_at: ReportSource['completed_at']; - public readonly status: JOB_STATUSES; // FIXME: can not use ReportSource['status'] due to type mismatch + public readonly status: JOB_STATUS; // FIXME: can not use ReportSource['status'] due to type mismatch public readonly attempts: ReportSource['attempts']; public readonly max_attempts: ReportSource['max_attempts']; @@ -81,7 +80,7 @@ export class Job { this.created_at = report.created_at; this.started_at = report.started_at; this.completed_at = report.completed_at; - this.status = report.status as JOB_STATUSES; + this.status = report.status as JOB_STATUS; this.attempts = report.attempts; this.max_attempts = report.max_attempts; @@ -166,7 +165,7 @@ export class Job { } public get isDownloadReady(): boolean { - return this.status === JOB_STATUSES.COMPLETED || this.status === JOB_STATUSES.WARNINGS; + return this.status === JOB_STATUS.COMPLETED || this.status === JOB_STATUS.WARNINGS; } public get prettyJobTypeName(): undefined | string { @@ -322,7 +321,7 @@ export class Job { } } -const jobStatusLabelsMap = new Map([ +const jobStatusLabelsMap = new Map([ [ PENDING, i18n.translate('xpack.reporting.jobStatuses.pendingText', { diff --git a/x-pack/plugins/reporting/public/lib/license_check.ts b/x-pack/plugins/reporting/public/lib/license_check.ts index 80ecaefe8a853..6145d9b02f7e8 100644 --- a/x-pack/plugins/reporting/public/lib/license_check.ts +++ b/x-pack/plugins/reporting/public/lib/license_check.ts @@ -6,7 +6,7 @@ */ import { LicenseCheck } from '@kbn/licensing-plugin/public'; -import { LicenseCheckResults } from '../../common/types'; +import { LicenseCheckResults } from '@kbn/reporting-common/types'; export const checkLicense = (checkResults: LicenseCheck): LicenseCheckResults => { switch (checkResults.state) { diff --git a/x-pack/plugins/reporting/public/lib/reporting_api_client/reporting_api_client.ts b/x-pack/plugins/reporting/public/lib/reporting_api_client/reporting_api_client.ts index e7727908e9152..37b8c60f4fe16 100644 --- a/x-pack/plugins/reporting/public/lib/reporting_api_client/reporting_api_client.ts +++ b/x-pack/plugins/reporting/public/lib/reporting_api_client/reporting_api_client.ts @@ -8,19 +8,16 @@ import { ELASTIC_INTERNAL_ORIGIN_QUERY_PARAM } from '@kbn/core-http-common'; import type { HttpFetchQuery } from '@kbn/core/public'; import { HttpSetup, IUiSettingsClient } from '@kbn/core/public'; import { i18n } from '@kbn/i18n'; +import { + REPORTING_MANAGEMENT_HOME, + buildKibanaPath, + getRedirectAppPath, +} from '@kbn/reporting-common'; +import { BaseParams, JobId, ManagementLinkFn, ReportApiJSON } from '@kbn/reporting-common/types'; import rison from '@kbn/rison'; import moment from 'moment'; import { stringify } from 'query-string'; -import { buildKibanaPath } from '@kbn/reporting-common'; -import { BaseParams, ManagementLinkFn } from '@kbn/reporting-common/types'; -import { - getRedirectAppPath, - INTERNAL_ROUTES, - JobId, - PUBLIC_ROUTES, - REPORTING_MANAGEMENT_HOME, -} from '../../../common/constants'; -import { ReportApiJSON } from '../../../common/types'; +import { INTERNAL_ROUTES, PUBLIC_ROUTES } from '../../../common/constants'; import { add } from '../../notifier/job_completion_notifications'; import { Job } from '../job'; diff --git a/x-pack/plugins/reporting/public/lib/stream_handler.ts b/x-pack/plugins/reporting/public/lib/stream_handler.ts index 92721fd20e60a..6bdba0b9bf84d 100644 --- a/x-pack/plugins/reporting/public/lib/stream_handler.ts +++ b/x-pack/plugins/reporting/public/lib/stream_handler.ts @@ -5,21 +5,23 @@ * 2.0. */ -import { i18n } from '@kbn/i18n'; import * as Rx from 'rxjs'; import { catchError, map } from 'rxjs/operators'; -import { NotificationsSetup, ThemeServiceStart, DocLinksStart } from '@kbn/core/public'; -import type { JobId } from '../../common/constants'; -import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY, JOB_STATUSES } from '../../common/constants'; -import { JobSummary, JobSummarySet } from '../../common/types'; + +import { DocLinksStart, NotificationsSetup, ThemeServiceStart } from '@kbn/core/public'; +import { i18n } from '@kbn/i18n'; +import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY, JOB_STATUS } from '@kbn/reporting-common'; +import { JobId } from '@kbn/reporting-common/types'; + import { getFailureToast, - getWarningToast, - getSuccessToast, getGeneralErrorToast, - getWarningMaxSizeToast, + getSuccessToast, getWarningFormulasToast, + getWarningMaxSizeToast, + getWarningToast, } from '../notifier'; +import { JobSummary, JobSummarySet } from '../types'; import { Job } from './job'; import { ReportingAPIClient } from './reporting_api_client'; @@ -85,7 +87,7 @@ export class ReportingNotifierStreamHandler { ), completedOptions ); - } else if (job.status === JOB_STATUSES.WARNINGS) { + } else if (job.status === JOB_STATUS.WARNINGS) { this.notifications.toasts.addWarning( getWarningToast( job, @@ -142,9 +144,9 @@ export class ReportingNotifierStreamHandler { for (const job of jobs) { const { id: jobId, status: jobStatus } = job; if (storedJobs.includes(jobId)) { - if (jobStatus === JOB_STATUSES.COMPLETED || jobStatus === JOB_STATUSES.WARNINGS) { + if (jobStatus === JOB_STATUS.COMPLETED || jobStatus === JOB_STATUS.WARNINGS) { completedJobs.push(getReportStatus(job)); - } else if (jobStatus === JOB_STATUSES.FAILED) { + } else if (jobStatus === JOB_STATUS.FAILED) { failedJobs.push(getReportStatus(job)); } else { pending.push(jobId); diff --git a/x-pack/plugins/reporting/public/management/components/ilm_policy_link.tsx b/x-pack/plugins/reporting/public/management/components/ilm_policy_link.tsx index 092f33d06215c..8bb72cddd6c76 100644 --- a/x-pack/plugins/reporting/public/management/components/ilm_policy_link.tsx +++ b/x-pack/plugins/reporting/public/management/components/ilm_policy_link.tsx @@ -7,11 +7,12 @@ import type { FunctionComponent } from 'react'; import React from 'react'; + import { i18n } from '@kbn/i18n'; import { EuiButtonEmpty } from '@elastic/eui'; import type { ApplicationStart } from '@kbn/core/public'; +import { ILM_POLICY_NAME } from '@kbn/reporting-common'; -import { ILM_POLICY_NAME } from '../../../common/constants'; import { LocatorPublic, SerializableRecord } from '../../shared_imports'; interface Props { diff --git a/x-pack/plugins/reporting/public/management/components/migrate_ilm_policy_callout/ilm_policy_migration_needed_callout.tsx b/x-pack/plugins/reporting/public/management/components/migrate_ilm_policy_callout/ilm_policy_migration_needed_callout.tsx index a1b0dbcd24c30..4e8d039251e81 100644 --- a/x-pack/plugins/reporting/public/management/components/migrate_ilm_policy_callout/ilm_policy_migration_needed_callout.tsx +++ b/x-pack/plugins/reporting/public/management/components/migrate_ilm_policy_callout/ilm_policy_migration_needed_callout.tsx @@ -5,16 +5,14 @@ * 2.0. */ +import { EuiButton, EuiCallOut, EuiCode } from '@elastic/eui'; +import type { NotificationsSetup } from '@kbn/core/public'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; +import { ILM_POLICY_NAME } from '@kbn/reporting-common'; import type { FunctionComponent } from 'react'; import React, { useState } from 'react'; import useMountedState from 'react-use/lib/useMountedState'; -import { EuiCallOut, EuiButton, EuiCode } from '@elastic/eui'; - -import type { NotificationsSetup } from '@kbn/core/public'; - -import { ILM_POLICY_NAME } from '../../../../common/constants'; import { useInternalApiClient } from '../../../lib/reporting_api_client'; diff --git a/x-pack/plugins/reporting/public/management/components/report_info_flyout_content.tsx b/x-pack/plugins/reporting/public/management/components/report_info_flyout_content.tsx index e111285d02d52..04a18a9572946 100644 --- a/x-pack/plugins/reporting/public/management/components/report_info_flyout_content.tsx +++ b/x-pack/plugins/reporting/public/management/components/report_info_flyout_content.tsx @@ -5,24 +5,23 @@ * 2.0. */ +import moment from 'moment'; import React, { FunctionComponent } from 'react'; -import { i18n } from '@kbn/i18n'; + import { + EuiCallOut, EuiDescriptionList, EuiDescriptionListProps, - EuiTitle, - EuiCallOut, EuiSpacer, + EuiTitle, } from '@elastic/eui'; -import moment from 'moment'; +import { i18n } from '@kbn/i18n'; +import { USES_HEADLESS_JOB_TYPES } from '@kbn/reporting-common'; import { VisualReportingSoftDisabledError } from '@kbn/reporting-common/errors'; -import { USES_HEADLESS_JOB_TYPES } from '../../../common/constants'; - import type { Job } from '../../lib/job'; -import { useKibana } from '../../shared_imports'; - import { sharedI18nTexts } from '../../shared_i18n_texts'; +import { useKibana } from '../../shared_imports'; // TODO: Move all of these i18n texts to ./i18n_texts.tsx const NA = i18n.translate('xpack.reporting.listing.infoPanel.notApplicableLabel', { diff --git a/x-pack/plugins/reporting/public/management/components/report_status_indicator.tsx b/x-pack/plugins/reporting/public/management/components/report_status_indicator.tsx index 3f15813cd4c2f..08e58d538da3b 100644 --- a/x-pack/plugins/reporting/public/management/components/report_status_indicator.tsx +++ b/x-pack/plugins/reporting/public/management/components/report_status_indicator.tsx @@ -8,9 +8,9 @@ import React, { FC, useMemo } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiLoadingSpinner, EuiToolTip } from '@elastic/eui'; +import { JOB_STATUS } from '@kbn/reporting-common/constants'; import type { Job } from '../../lib/job'; -import { JOB_STATUSES } from '../../../common/constants'; import { jobHasIssues } from '../utils'; interface Props { @@ -60,7 +60,7 @@ export const ReportStatusIndicator: FC = ({ job }) => { let statusText: string; switch (job.status) { - case JOB_STATUSES.COMPLETED: + case JOB_STATUS.COMPLETED: if (hasIssues) { icon = ; statusText = i18nTexts.completedWithWarnings; @@ -69,19 +69,19 @@ export const ReportStatusIndicator: FC = ({ job }) => { icon = ; statusText = i18nTexts.completed; break; - case JOB_STATUSES.WARNINGS: + case JOB_STATUS.WARNINGS: icon = ; statusText = i18nTexts.completedWithWarnings; break; - case JOB_STATUSES.PENDING: + case JOB_STATUS.PENDING: icon = ; statusText = i18nTexts.pending; break; - case JOB_STATUSES.PROCESSING: + case JOB_STATUS.PROCESSING: icon = ; statusText = i18nTexts.processing({ attempt: job.attempts, of: job.max_attempts }); break; - case JOB_STATUSES.FAILED: + case JOB_STATUS.FAILED: icon = ; statusText = i18nTexts.failed; break; diff --git a/x-pack/plugins/reporting/public/management/report_listing.tsx b/x-pack/plugins/reporting/public/management/report_listing.tsx index d6289bc2032f9..31976dd196a9a 100644 --- a/x-pack/plugins/reporting/public/management/report_listing.tsx +++ b/x-pack/plugins/reporting/public/management/report_listing.tsx @@ -5,41 +5,44 @@ * 2.0. */ +import { Component, Fragment, default as React } from 'react'; +import { Subscription } from 'rxjs'; + import { EuiBasicTable, + EuiBasicTableColumn, EuiFlexGroup, EuiFlexItem, + EuiIconTip, + EuiLink, EuiLoadingSpinner, EuiPageHeader, EuiSpacer, - EuiBasicTableColumn, - EuiIconTip, - EuiLink, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; -import { Component, default as React, Fragment } from 'react'; -import { Subscription } from 'rxjs'; import { ILicense } from '@kbn/licensing-plugin/public'; +import { durationToNumber } from '@kbn/reporting-common'; + +import { ListingProps as Props } from '.'; import { REPORT_TABLE_ID, REPORT_TABLE_ROW_ID } from '../../common/constants'; import { prettyPrintJobType } from '../../common/job_utils'; import { Poller } from '../../common/poller'; -import { durationToNumber } from '../../common/schema_utils'; import { useIlmPolicyStatus } from '../lib/ilm_policy_status_context'; import { Job } from '../lib/job'; import { checkLicense } from '../lib/license_check'; import { useInternalApiClient } from '../lib/reporting_api_client'; import { useKibana } from '../shared_imports'; -import { ListingProps as Props } from '.'; import { IlmPolicyLink, MigrateIlmPolicyCallOut, ReportDeleteButton, ReportDiagnostic, - ReportStatusIndicator, ReportInfoFlyout, + ReportStatusIndicator, } from './components'; import { guessAppIconTypeFromObjectType } from './utils'; + import './report_listing.scss'; type TableColumn = EuiBasicTableColumn; diff --git a/x-pack/plugins/reporting/public/management/utils.ts b/x-pack/plugins/reporting/public/management/utils.ts index 87e49c2054f92..b26c5fdf58046 100644 --- a/x-pack/plugins/reporting/public/management/utils.ts +++ b/x-pack/plugins/reporting/public/management/utils.ts @@ -6,7 +6,7 @@ */ import type { IconType } from '@elastic/eui'; -import { JOB_STATUSES } from '../../common/constants'; +import { JOB_STATUS } from '@kbn/reporting-common'; import { Job } from '../lib/job'; /** @@ -35,6 +35,6 @@ export const guessAppIconTypeFromObjectType = (type: string): IconType => { export const jobHasIssues = (job: Job): boolean => { return ( Boolean(job.getWarnings()) || - [JOB_STATUSES.WARNINGS, JOB_STATUSES.FAILED].some((status) => job.status === status) + [JOB_STATUS.WARNINGS, JOB_STATUS.FAILED].some((status) => job.status === status) ); }; diff --git a/x-pack/plugins/reporting/public/notifier/job_completion_notifications.ts b/x-pack/plugins/reporting/public/notifier/job_completion_notifications.ts index 69a6ca52d013f..61db874e75208 100644 --- a/x-pack/plugins/reporting/public/notifier/job_completion_notifications.ts +++ b/x-pack/plugins/reporting/public/notifier/job_completion_notifications.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { JobId, JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY } from '../../common/constants'; +import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY } from '@kbn/reporting-common'; +import { JobId } from '@kbn/reporting-common/types'; const set = (jobs: string[]) => { sessionStorage.setItem(JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY, JSON.stringify(jobs)); diff --git a/x-pack/plugins/reporting/public/notifier/job_download_button.tsx b/x-pack/plugins/reporting/public/notifier/job_download_button.tsx index 32b3e33f9923a..5b7cd42f78a16 100644 --- a/x-pack/plugins/reporting/public/notifier/job_download_button.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_download_button.tsx @@ -7,9 +7,9 @@ import { EuiButton } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; +import { JobId } from '@kbn/reporting-common/types'; import React from 'react'; -import { JobId } from '../../common/constants'; -import { JobSummary } from '../../common/types'; +import { JobSummary } from '../types'; interface Props { getUrl: (jobId: JobId) => string; diff --git a/x-pack/plugins/reporting/public/notifier/job_failure.tsx b/x-pack/plugins/reporting/public/notifier/job_failure.tsx index e18782437e799..e5c6f06413bdf 100644 --- a/x-pack/plugins/reporting/public/notifier/job_failure.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_failure.tsx @@ -12,8 +12,8 @@ import { DocLinksStart, ThemeServiceStart, ToastInput } from '@kbn/core/public'; import { toMountPoint } from '@kbn/kibana-react-plugin/public'; import * as errors from '@kbn/reporting-common/errors'; import { ManagementLinkFn } from '@kbn/reporting-common/types'; -import type { JobSummary } from '../../common/types'; import { sharedI18nTexts } from '../shared_i18n_texts'; +import type { JobSummary } from '../types'; export const getFailureToast = ( errorText: string, diff --git a/x-pack/plugins/reporting/public/notifier/job_success.tsx b/x-pack/plugins/reporting/public/notifier/job_success.tsx index bc141172f9037..00b08ed2413d9 100644 --- a/x-pack/plugins/reporting/public/notifier/job_success.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_success.tsx @@ -5,14 +5,14 @@ * 2.0. */ -import { FormattedMessage } from '@kbn/i18n-react'; -import React from 'react'; import { ThemeServiceStart, ToastInput } from '@kbn/core/public'; +import { FormattedMessage } from '@kbn/i18n-react'; import { toMountPoint } from '@kbn/kibana-react-plugin/public'; -import { JobSummary } from '../../common/types'; +import { JobId } from '@kbn/reporting-common/types'; +import React from 'react'; +import { JobSummary } from '../types'; import { DownloadButton } from './job_download_button'; import { ReportLink } from './report_link'; -import { JobId } from '../../common/constants'; export const getSuccessToast = ( job: JobSummary, diff --git a/x-pack/plugins/reporting/public/notifier/job_warning.tsx b/x-pack/plugins/reporting/public/notifier/job_warning.tsx index 2c0ae098f0801..6751eb76ab073 100644 --- a/x-pack/plugins/reporting/public/notifier/job_warning.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_warning.tsx @@ -5,12 +5,12 @@ * 2.0. */ -import { FormattedMessage } from '@kbn/i18n-react'; -import React from 'react'; import { ThemeServiceStart, ToastInput } from '@kbn/core/public'; +import { FormattedMessage } from '@kbn/i18n-react'; import { toMountPoint } from '@kbn/kibana-react-plugin/public'; -import type { JobId } from '../../common/constants'; -import { JobSummary } from '../../common/types'; +import { JobId } from '@kbn/reporting-common/types'; +import React from 'react'; +import { JobSummary } from '../types'; import { DownloadButton } from './job_download_button'; import { ReportLink } from './report_link'; diff --git a/x-pack/plugins/reporting/public/notifier/job_warning_formulas.tsx b/x-pack/plugins/reporting/public/notifier/job_warning_formulas.tsx index 51da9823ad857..4cf9f3f655cc1 100644 --- a/x-pack/plugins/reporting/public/notifier/job_warning_formulas.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_warning_formulas.tsx @@ -5,13 +5,15 @@ * 2.0. */ -import { FormattedMessage } from '@kbn/i18n-react'; import React from 'react'; + import { ThemeServiceStart, ToastInput } from '@kbn/core/public'; +import { FormattedMessage } from '@kbn/i18n-react'; import { toMountPoint } from '@kbn/kibana-react-plugin/public'; -import type { JobId } from '../../common/constants'; -import { JobSummary } from '../../common/types'; +import { JobId } from '@kbn/reporting-common/types'; import { DownloadButton } from './job_download_button'; + +import { JobSummary } from '../types'; import { ReportLink } from './report_link'; export const getWarningFormulasToast = ( diff --git a/x-pack/plugins/reporting/public/notifier/job_warning_max_size.tsx b/x-pack/plugins/reporting/public/notifier/job_warning_max_size.tsx index 6af86bb6ff40a..54c7628242067 100644 --- a/x-pack/plugins/reporting/public/notifier/job_warning_max_size.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_warning_max_size.tsx @@ -5,12 +5,12 @@ * 2.0. */ -import { FormattedMessage } from '@kbn/i18n-react'; -import React from 'react'; import { ThemeServiceStart, ToastInput } from '@kbn/core/public'; +import { FormattedMessage } from '@kbn/i18n-react'; import { toMountPoint } from '@kbn/kibana-react-plugin/public'; -import type { JobId } from '../../common/constants'; -import { JobSummary } from '../../common/types'; +import type { JobId } from '@kbn/reporting-common/types'; +import React from 'react'; +import { JobSummary } from '../types'; import { DownloadButton } from './job_download_button'; import { ReportLink } from './report_link'; diff --git a/x-pack/plugins/reporting/public/plugin.ts b/x-pack/plugins/reporting/public/plugin.ts index 560f4ef06635f..a0ff30f775260 100644 --- a/x-pack/plugins/reporting/public/plugin.ts +++ b/x-pack/plugins/reporting/public/plugin.ts @@ -27,10 +27,10 @@ import { ManagementSetup, ManagementStart } from '@kbn/management-plugin/public' import { ClientConfigType } from '@kbn/reporting-public'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/public'; -import { ReportingSetup, ReportingStart } from '.'; -import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY, JobId } from '../common/constants'; -import { durationToNumber } from '../common/schema_utils'; -import { JobSummarySet } from '../common/types'; +import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY, durationToNumber } from '@kbn/reporting-common'; +import type { JobId } from '@kbn/reporting-common/types'; + +import type { ReportingSetup, ReportingStart } from '.'; import { ReportingAPIClient } from './lib/reporting_api_client'; import { ReportingNotifierStreamHandler as StreamHandler } from './lib/stream_handler'; import { getGeneralErrorToast } from './notifier'; @@ -45,7 +45,7 @@ import type { UiActionsStart, } from './shared_imports'; import { AppNavLinkStatus } from './shared_imports'; - +import type { JobSummarySet } from './types'; function getStored(): JobId[] { const sessionValue = sessionStorage.getItem(JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY); return sessionValue ? JSON.parse(sessionValue) : []; diff --git a/x-pack/plugins/reporting/public/redirect/redirect_app.tsx b/x-pack/plugins/reporting/public/redirect/redirect_app.tsx index 440bb67762746..f26fae4e85763 100644 --- a/x-pack/plugins/reporting/public/redirect/redirect_app.tsx +++ b/x-pack/plugins/reporting/public/redirect/redirect_app.tsx @@ -13,10 +13,10 @@ import { EuiCallOut, EuiCodeBlock } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import type { ScopedHistory } from '@kbn/core/public'; +import { REPORTING_REDIRECT_LOCATOR_STORE_KEY } from '@kbn/reporting-common'; import { LocatorParams } from '@kbn/reporting-common/types'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/public'; -import { REPORTING_REDIRECT_LOCATOR_STORE_KEY } from '../../common/constants'; import { ReportingAPIClient } from '../lib/reporting_api_client'; import type { SharePluginSetup } from '../shared_imports'; diff --git a/x-pack/plugins/reporting/server/config/index.ts b/x-pack/plugins/reporting/server/config/index.ts index 01b9574d07b47..bb47bb9658412 100644 --- a/x-pack/plugins/reporting/server/config/index.ts +++ b/x-pack/plugins/reporting/server/config/index.ts @@ -9,7 +9,7 @@ import { get } from 'lodash'; import { PluginConfigDescriptor } from '@kbn/core/server'; import { i18n } from '@kbn/i18n'; -import { ConfigSchema, ReportingConfigType } from '@kbn/reporting-config-server'; +import { ConfigSchema, ReportingConfigType } from '@kbn/reporting-server'; export const config: PluginConfigDescriptor = { exposeToBrowser: { poll: true, roles: true, export_types: true, statefulSettings: true }, diff --git a/x-pack/plugins/reporting/server/config/ui_settings.ts b/x-pack/plugins/reporting/server/config/ui_settings.ts index f6122a814d6f7..cb4a5ca4ec09b 100644 --- a/x-pack/plugins/reporting/server/config/ui_settings.ts +++ b/x-pack/plugins/reporting/server/config/ui_settings.ts @@ -6,10 +6,9 @@ */ import { schema } from '@kbn/config-schema'; -import { i18n } from '@kbn/i18n'; import { CoreSetup, UiSettingsParams } from '@kbn/core/server'; -import { UI_SETTINGS_CUSTOM_PDF_LOGO } from '@kbn/reporting-common'; -import { PLUGIN_ID } from '../../common/constants'; +import { i18n } from '@kbn/i18n'; +import { PLUGIN_ID, UI_SETTINGS_CUSTOM_PDF_LOGO } from '@kbn/reporting-common'; const kbToBase64Length = (kb: number) => Math.floor((kb * 1024 * 8) / 6); const maxLogoSizeInBase64 = kbToBase64Length(200); diff --git a/x-pack/plugins/reporting/server/deprecations/migrate_existing_indices_ilm_policy.ts b/x-pack/plugins/reporting/server/deprecations/migrate_existing_indices_ilm_policy.ts index 6f0ddba9ce296..d7c6e1fd9fc2a 100644 --- a/x-pack/plugins/reporting/server/deprecations/migrate_existing_indices_ilm_policy.ts +++ b/x-pack/plugins/reporting/server/deprecations/migrate_existing_indices_ilm_policy.ts @@ -5,9 +5,10 @@ * 2.0. */ -import { i18n } from '@kbn/i18n'; import { DeprecationsDetails, GetDeprecationsContext } from '@kbn/core/server'; -import { INTERNAL_ROUTES, ILM_POLICY_NAME } from '../../common/constants'; +import { i18n } from '@kbn/i18n'; +import { ILM_POLICY_NAME } from '@kbn/reporting-common'; +import { INTERNAL_ROUTES } from '../../common/constants'; import { ReportingCore } from '../core'; import { deprecations } from '../lib/deprecations'; diff --git a/x-pack/plugins/reporting/server/lib/check_params_version.ts b/x-pack/plugins/reporting/server/lib/check_params_version.ts index b84cf0c01dc42..9ab249ced9d6a 100644 --- a/x-pack/plugins/reporting/server/lib/check_params_version.ts +++ b/x-pack/plugins/reporting/server/lib/check_params_version.ts @@ -6,8 +6,8 @@ */ import type { Logger } from '@kbn/core/server'; +import { UNVERSIONED_VERSION } from '@kbn/reporting-common'; import type { BaseParams } from '@kbn/reporting-common/types'; -import { UNVERSIONED_VERSION } from '../../common/constants'; export function checkParamsVersion(jobParams: BaseParams, logger: Logger) { if (jobParams.version) { diff --git a/x-pack/plugins/reporting/server/lib/content_stream.ts b/x-pack/plugins/reporting/server/lib/content_stream.ts index 7bf7f1108776e..0be61705d84b5 100644 --- a/x-pack/plugins/reporting/server/lib/content_stream.ts +++ b/x-pack/plugins/reporting/server/lib/content_stream.ts @@ -4,14 +4,16 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ + +import { defaults, get } from 'lodash'; +import { Duplex } from 'stream'; +import { v4 as uuidv4 } from 'uuid'; + import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { ByteSizeValue } from '@kbn/config-schema'; import type { ElasticsearchClient, Logger } from '@kbn/core/server'; -import { defaults, get } from 'lodash'; -import { v4 as uuidv4 } from 'uuid'; -import { Duplex } from 'stream'; +import type { ReportSource } from '@kbn/reporting-common/types'; import type { ReportingCore } from '..'; -import type { ReportSource } from '../../common/types'; /** * @note The Elasticsearch `http.max_content_length` is including the whole POST body. diff --git a/x-pack/plugins/reporting/server/lib/deprecations/check_ilm_migration_status.ts b/x-pack/plugins/reporting/server/lib/deprecations/check_ilm_migration_status.ts index d6985600d19c2..aab4c1f0cecf4 100644 --- a/x-pack/plugins/reporting/server/lib/deprecations/check_ilm_migration_status.ts +++ b/x-pack/plugins/reporting/server/lib/deprecations/check_ilm_migration_status.ts @@ -6,7 +6,7 @@ */ import { IlmPolicyMigrationStatus } from '@kbn/reporting-common/url'; -import { ILM_POLICY_NAME } from '../../../common/constants'; +import { ILM_POLICY_NAME } from '@kbn/reporting-common'; import { IlmPolicyManager } from '../store/ilm_policy_manager'; import type { DeprecationsDependencies } from './types'; diff --git a/x-pack/plugins/reporting/server/lib/event_logger/logger.ts b/x-pack/plugins/reporting/server/lib/event_logger/logger.ts index 8096aa36be7b0..a1a7d8e2ea1ca 100644 --- a/x-pack/plugins/reporting/server/lib/event_logger/logger.ts +++ b/x-pack/plugins/reporting/server/lib/event_logger/logger.ts @@ -8,7 +8,7 @@ import deepMerge from 'deepmerge'; import type { Logger, LogMeta } from '@kbn/core/server'; import type { TaskRunMetrics } from '@kbn/reporting-common/types'; -import { PLUGIN_ID } from '../../../common/constants'; +import { PLUGIN_ID } from '@kbn/reporting-common'; import { IReport } from '../store'; import { ActionType } from '.'; import { EcsLogAdapter } from './adapter'; diff --git a/x-pack/plugins/reporting/server/lib/index.ts b/x-pack/plugins/reporting/server/lib/index.ts index 356341ddff592..4c3f29bfa1383 100644 --- a/x-pack/plugins/reporting/server/lib/index.ts +++ b/x-pack/plugins/reporting/server/lib/index.ts @@ -10,6 +10,5 @@ export { checkParamsVersion } from './check_params_version'; export { ContentStream, getContentStream } from './content_stream'; export { ExportTypesRegistry } from './export_types_registry'; export { PassThroughStream } from './passthrough_stream'; -export { statuses } from './statuses'; export { ReportingStore, IlmPolicyManager } from './store'; export { startTrace } from './trace'; diff --git a/x-pack/plugins/reporting/server/lib/statuses.ts b/x-pack/plugins/reporting/server/lib/statuses.ts deleted file mode 100644 index 2c25708078aaf..0000000000000 --- a/x-pack/plugins/reporting/server/lib/statuses.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 { JobStatus } from '../../common/types'; - -export const statuses: Record = { - JOB_STATUS_PENDING: 'pending', - JOB_STATUS_PROCESSING: 'processing', - JOB_STATUS_COMPLETED: 'completed', - JOB_STATUS_WARNINGS: 'completed_with_warnings', - JOB_STATUS_FAILED: 'failed', -}; diff --git a/x-pack/plugins/reporting/server/lib/store/ilm_policy_manager/ilm_policy_manager.ts b/x-pack/plugins/reporting/server/lib/store/ilm_policy_manager/ilm_policy_manager.ts index 48a45be80f716..90bda652898f3 100644 --- a/x-pack/plugins/reporting/server/lib/store/ilm_policy_manager/ilm_policy_manager.ts +++ b/x-pack/plugins/reporting/server/lib/store/ilm_policy_manager/ilm_policy_manager.ts @@ -6,8 +6,7 @@ */ import type { ElasticsearchClient } from '@kbn/core/server'; -import { ILM_POLICY_NAME } from '../../../../common/constants'; - +import { ILM_POLICY_NAME } from '@kbn/reporting-common'; import { reportingIlmPolicy } from './constants'; /** diff --git a/x-pack/plugins/reporting/server/lib/store/report.ts b/x-pack/plugins/reporting/server/lib/store/report.ts index 680b6936a4cc2..e4ed610eeecd6 100644 --- a/x-pack/plugins/reporting/server/lib/store/report.ts +++ b/x-pack/plugins/reporting/server/lib/store/report.ts @@ -9,7 +9,7 @@ import { omit } from 'lodash'; import moment from 'moment'; import Puid from 'puid'; -import { JOB_STATUSES } from '@kbn/reporting-common'; +import { JOB_STATUS } from '@kbn/reporting-common'; import { ReportApiJSON, ReportDocumentHead, @@ -93,7 +93,7 @@ export class Report implements Partial { this.meta = opts.meta || { objectType: 'unknown' }; this.metrics = opts.metrics; - this.status = opts.status || JOB_STATUSES.PENDING; + this.status = opts.status || JOB_STATUS.PENDING; this.output = opts.output || null; this.queue_time_ms = fields?.queue_time_ms; diff --git a/x-pack/plugins/reporting/server/lib/store/store.ts b/x-pack/plugins/reporting/server/lib/store/store.ts index 47db231a87f70..f13f1169ade3b 100644 --- a/x-pack/plugins/reporting/server/lib/store/store.ts +++ b/x-pack/plugins/reporting/server/lib/store/store.ts @@ -7,14 +7,12 @@ import { estypes } from '@elastic/elasticsearch'; import type { ElasticsearchClient, Logger } from '@kbn/core/server'; +import { ILM_POLICY_NAME, JOB_STATUS, REPORTING_SYSTEM_INDEX } from '@kbn/reporting-common'; +import { ReportOutput, ReportSource } from '@kbn/reporting-common/types'; import moment from 'moment'; -import { ReportOutput } from '@kbn/reporting-common/types'; import type { IReport, Report, ReportDocument } from '.'; import { SavedReport } from '.'; -import { statuses } from '..'; import type { ReportingCore } from '../..'; -import { ILM_POLICY_NAME, REPORTING_SYSTEM_INDEX } from '../../../common/constants'; -import type { JobStatus, ReportSource } from '../../../common/types'; import type { ReportTaskParams } from '../tasks'; import { IlmPolicyManager } from './ilm_policy_manager'; import { indexTimestamp } from './index_timestamp'; @@ -54,7 +52,7 @@ export interface ReportRecordTimeout { _id: string; _index: string; _source: { - status: JobStatus; + status: JOB_STATUS; process_expiration?: string; }; } @@ -166,7 +164,7 @@ export class ReportingStore { ...sourceDoc({ process_expiration: new Date(0).toISOString(), attempts: 0, - status: statuses.JOB_STATUS_PENDING, + status: JOB_STATUS.PENDING, }), }, }; @@ -284,7 +282,7 @@ export class ReportingStore { ): Promise> { const doc = sourceDoc({ ...processingInfo, - status: statuses.JOB_STATUS_PROCESSING, + status: JOB_STATUS.PROCESSING, }); let body: UpdateResponse; @@ -323,7 +321,7 @@ export class ReportingStore { ): Promise> { const doc = sourceDoc({ ...failedInfo, - status: statuses.JOB_STATUS_FAILED, + status: JOB_STATUS.FAILED, }); let body: UpdateResponse; @@ -354,8 +352,8 @@ export class ReportingStore { const { output } = completedInfo; const status = output && output.warnings && output.warnings.length > 0 - ? statuses.JOB_STATUS_WARNINGS - : statuses.JOB_STATUS_COMPLETED; + ? JOB_STATUS.WARNINGS + : JOB_STATUS.COMPLETED; const doc = sourceDoc({ ...completedInfo, status, @@ -384,7 +382,7 @@ export class ReportingStore { public async prepareReportForRetry(report: SavedReport): Promise> { const doc = sourceDoc({ - status: statuses.JOB_STATUS_PENDING, + status: JOB_STATUS.PENDING, process_expiration: null, }); @@ -421,13 +419,13 @@ export class ReportingStore { bool: { must: [ { range: { process_expiration: { lt: `now` } } }, - { terms: { status: [statuses.JOB_STATUS_PROCESSING] } }, + { terms: { status: [JOB_STATUS.PROCESSING] } }, ], }, }; const oldVersionFilter = { bool: { - must: [{ terms: { status: [statuses.JOB_STATUS_PENDING] } }], + must: [{ terms: { status: [JOB_STATUS.PENDING] } }], must_not: [{ exists: { field: 'migration_version' } }], }, }; diff --git a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts index e0b43153456da..32aee34caa0de 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts @@ -5,6 +5,13 @@ * 2.0. */ +import moment from 'moment'; +import * as Rx from 'rxjs'; +import { timeout } from 'rxjs/operators'; +import { Writable } from 'stream'; +import { finished } from 'stream/promises'; +import { setTimeout } from 'timers/promises'; + import { UpdateResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { Logger } from '@kbn/core/server'; import { @@ -12,6 +19,8 @@ import { KibanaShuttingDownError, QueueTimeoutError, ReportingError, + durationToNumber, + numberToDuration, } from '@kbn/reporting-common'; import type { ReportOutput, TaskRunResult } from '@kbn/reporting-common/types'; import type { @@ -19,18 +28,11 @@ import type { TaskManagerStartContract, TaskRunCreatorFunction, } from '@kbn/task-manager-plugin/server'; -import moment from 'moment'; -import * as Rx from 'rxjs'; -import { timeout } from 'rxjs/operators'; -import { Writable } from 'stream'; -import { finished } from 'stream/promises'; -import { setTimeout } from 'timers/promises'; import { REPORTING_EXECUTE_TYPE, ReportTaskParams, ReportingTask, ReportingTaskStatus } from '.'; import { ExportTypesRegistry, getContentStream } from '..'; import type { ReportingCore } from '../..'; import { mapToReportingError } from '../../../common/errors/map_to_reporting_error'; -import { durationToNumber, numberToDuration } from '../../../common/schema_utils'; import type { ReportingConfigType } from '../../config'; import type { ReportDocument, ReportingStore } from '../store'; import { Report, SavedReport } from '../store'; diff --git a/x-pack/plugins/reporting/server/lib/tasks/monitor_reports.ts b/x-pack/plugins/reporting/server/lib/tasks/monitor_reports.ts index fa599d225b77d..867adf3617248 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/monitor_reports.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/monitor_reports.ts @@ -8,11 +8,10 @@ import type { Logger } from '@kbn/core/server'; import moment from 'moment'; import { TaskManagerStartContract, TaskRunCreatorFunction } from '@kbn/task-manager-plugin/server'; +import { JOB_STATUS, numberToDuration } from '@kbn/reporting-common'; import { ReportingStore } from '..'; import { ReportingCore } from '../..'; -import { numberToDuration } from '../../../common/schema_utils'; import { ReportingConfigType } from '../../config'; -import { statuses } from '../statuses'; import { SavedReport } from '../store'; import { ReportingTask, ReportingTaskStatus, REPORTING_MONITOR_TYPE, ReportTaskParams } from '.'; @@ -96,7 +95,7 @@ export class MonitorReportsTask implements ReportingTask { const { _id: jobId, process_expiration: processExpiration, status } = report; const eventLog = this.reporting.getEventLogger(report); - if (![statuses.JOB_STATUS_PENDING, statuses.JOB_STATUS_PROCESSING].includes(status)) { + if (![JOB_STATUS.PENDING, JOB_STATUS.PROCESSING].includes(status)) { const invalidStatusError = new Error( `Invalid job status in the monitoring search result: ${status}` ); // only pending or processing jobs possibility need rescheduling @@ -107,7 +106,7 @@ export class MonitorReportsTask implements ReportingTask { throw invalidStatusError; } - if (status === statuses.JOB_STATUS_PENDING) { + if (status === JOB_STATUS.PENDING) { const migratingJobError = new Error( `${jobId} was scheduled in a previous version and left in [${status}] status. Rescheduling...` ); @@ -115,7 +114,7 @@ export class MonitorReportsTask implements ReportingTask { eventLog.logError(migratingJobError); } - if (status === statuses.JOB_STATUS_PROCESSING) { + if (status === JOB_STATUS.PROCESSING) { const expirationTime = moment(processExpiration); const overdueValue = moment().valueOf() - expirationTime.valueOf(); const overdueExpirationError = new Error( diff --git a/x-pack/plugins/reporting/server/plugin.ts b/x-pack/plugins/reporting/server/plugin.ts index ca19617e199c5..db653917cb401 100644 --- a/x-pack/plugins/reporting/server/plugin.ts +++ b/x-pack/plugins/reporting/server/plugin.ts @@ -12,9 +12,9 @@ import type { Plugin, PluginInitializerContext, } from '@kbn/core/server'; +import { PLUGIN_ID } from '@kbn/reporting-common'; import { setFieldFormats } from '@kbn/reporting-server'; import { ReportingCore } from '.'; -import { PLUGIN_ID } from '../common/constants'; import { ReportingConfigType, registerUiSettings } from './config'; import { registerDeprecations } from './deprecations'; import { ReportingStore } from './lib'; diff --git a/x-pack/plugins/reporting/server/routes/common/get_counter.ts b/x-pack/plugins/reporting/server/routes/common/get_counter.ts index 2888bebcc5e6b..83603d07e5ce8 100644 --- a/x-pack/plugins/reporting/server/routes/common/get_counter.ts +++ b/x-pack/plugins/reporting/server/routes/common/get_counter.ts @@ -5,8 +5,8 @@ * 2.0. */ +import { API_USAGE_COUNTER_TYPE, API_USAGE_ERROR_TYPE } from '@kbn/reporting-common'; import { UsageCounter } from '@kbn/usage-collection-plugin/server'; -import { API_USAGE_COUNTER_TYPE, API_USAGE_ERROR_TYPE } from '../../../common/constants'; export type Counters = ReturnType; diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.test.ts b/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.test.ts index 73aa630b671d8..cbd5f93425847 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.test.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.test.ts @@ -7,12 +7,13 @@ import { Readable } from 'stream'; +import { JOB_STATUS } from '@kbn/reporting-common'; import { ReportApiJSON } from '@kbn/reporting-common/types'; import { CSV_JOB_TYPE } from '@kbn/reporting-export-types-csv-common'; import { PDF_JOB_TYPE, PDF_JOB_TYPE_V2 } from '@kbn/reporting-export-types-pdf-common'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; -import { ContentStream, getContentStream, statuses } from '../../../lib'; +import { ContentStream, getContentStream } from '../../../lib'; import { createMockReportingCore } from '../../../test_helpers'; import { getDocumentPayloadFactory } from './get_document_payload'; import { jobsQueryFactory } from './jobs_query'; @@ -49,7 +50,7 @@ describe('getDocumentPayload', () => { getDocumentPayload({ id: 'id1', index: '.reporting-12345', - status: statuses.JOB_STATUS_COMPLETED, + status: JOB_STATUS.COMPLETED, jobtype: PDF_JOB_TYPE, output: { content_type: 'application/pdf', @@ -75,7 +76,7 @@ describe('getDocumentPayload', () => { getDocumentPayload({ id: 'id1', index: '.reporting-12345', - status: statuses.JOB_STATUS_WARNINGS, + status: JOB_STATUS.WARNINGS, jobtype: CSV_JOB_TYPE, output: { content_type: 'text/csv', @@ -107,7 +108,7 @@ describe('getDocumentPayload', () => { getDocumentPayload({ id: 'id1', index: '.reporting-12345', - status: statuses.JOB_STATUS_FAILED, + status: JOB_STATUS.FAILED, jobtype: PDF_JOB_TYPE_V2, output: {}, payload: {}, @@ -131,7 +132,7 @@ describe('getDocumentPayload', () => { getDocumentPayload({ id: 'id1', index: '.reporting-12345', - status: statuses.JOB_STATUS_PENDING, + status: JOB_STATUS.PENDING, jobtype: PDF_JOB_TYPE_V2, output: {}, payload: {}, diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.ts b/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.ts index b519238d9a0a3..d8a0027c42d64 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/get_document_payload.ts @@ -10,10 +10,11 @@ import { Stream } from 'stream'; import { ResponseHeaders } from '@kbn/core-http-server'; import { ReportApiJSON } from '@kbn/reporting-common/types'; import { CSV_JOB_TYPE, CSV_JOB_TYPE_DEPRECATED } from '@kbn/reporting-export-types-csv-common'; +import { JOB_STATUS } from '@kbn/reporting-common'; import { ExportType } from '@kbn/reporting-server'; import { ReportingCore } from '../../..'; -import { getContentStream, statuses } from '../../../lib'; +import { getContentStream } from '../../../lib'; import { jobsQueryFactory } from './jobs_query'; export interface ErrorFromPayload { @@ -108,11 +109,11 @@ export function getDocumentPayloadFactory(reporting: ReportingCore) { return async function getDocumentPayload(report: ReportApiJSON): Promise { if (report.output) { - if ([statuses.JOB_STATUS_COMPLETED, statuses.JOB_STATUS_WARNINGS].includes(report.status)) { + if ([JOB_STATUS.COMPLETED, JOB_STATUS.WARNINGS].includes(report.status)) { return getCompleted(report as Required); } - if (statuses.JOB_STATUS_FAILED === report.status) { + if (JOB_STATUS.FAILED === report.status) { return getFailure(report); } } diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/get_job_routes.ts b/x-pack/plugins/reporting/server/routes/common/jobs/get_job_routes.ts index 343410ddf3ca4..ddd226187adf0 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/get_job_routes.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/get_job_routes.ts @@ -9,10 +9,10 @@ import { promisify } from 'util'; import { schema, TypeOf } from '@kbn/config-schema'; import { KibanaRequest, KibanaResponseFactory } from '@kbn/core-http-server'; +import { ALLOWED_JOB_CONTENT_TYPES } from '@kbn/reporting-common'; import { getCounters } from '..'; import { ReportingCore } from '../../..'; -import { ALLOWED_JOB_CONTENT_TYPES } from '../../../../common/constants'; import { getContentStream } from '../../../lib'; import { ReportingRequestHandlerContext, ReportingUser } from '../../../types'; import { handleUnavailable } from '../generate'; diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.test.ts b/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.test.ts index 57ad7586467cb..616079c0aa27e 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.test.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.test.ts @@ -9,8 +9,8 @@ import { set } from '@kbn/safer-lodash-set'; import { ElasticsearchClient } from '@kbn/core/server'; import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; +import { JOB_STATUS } from '@kbn/reporting-common'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; -import { statuses } from '../../../lib'; import { createMockReportingCore } from '../../../test_helpers'; import { jobsQueryFactory } from './jobs_query'; @@ -186,7 +186,7 @@ describe('jobsQuery', () => { _id: 'id1', jobtype: 'pdf', output: { content: 'Some error' }, - status: statuses.JOB_STATUS_FAILED, + status: JOB_STATUS.FAILED, }, }, ]) @@ -220,7 +220,7 @@ describe('jobsQuery', () => { _source: { _id: 'id1', jobtype: 'pdf', - status: statuses.JOB_STATUS_PENDING, + status: JOB_STATUS.PENDING, }, }, ]) diff --git a/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.ts b/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.ts index 102b41bb11322..9efe74a0c3aac 100644 --- a/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.ts +++ b/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.ts @@ -8,10 +8,9 @@ import { TransportResult, errors, estypes } from '@elastic/elasticsearch'; import type { ElasticsearchClient } from '@kbn/core/server'; import { i18n } from '@kbn/i18n'; -import { REPORTING_SYSTEM_INDEX } from '@kbn/reporting-common'; +import { JOB_STATUS, REPORTING_SYSTEM_INDEX } from '@kbn/reporting-common'; import { ReportApiJSON, ReportSource } from '@kbn/reporting-common/types'; import type { ReportingCore } from '../../..'; -import { statuses } from '../../../lib/statuses'; import { Report } from '../../../lib/store'; import { runtimeFieldKeys, runtimeFields } from '../../../lib/store/runtime_fields'; import type { ReportingUser } from '../../../types'; @@ -192,7 +191,7 @@ export function jobsQueryFactory(reportingCore: ReportingCore): JobsQueryFactory const hits = response?.hits?.hits?.[0]; const status = hits?._source?.status; - if (status !== statuses.JOB_STATUS_FAILED) { + if (status !== JOB_STATUS.FAILED) { throw new Error(`Can not get error for ${id}`); } diff --git a/x-pack/plugins/reporting/server/routes/internal/deprecations/deprecations.ts b/x-pack/plugins/reporting/server/routes/internal/deprecations/deprecations.ts index 249046c9da910..d6322f2d60346 100644 --- a/x-pack/plugins/reporting/server/routes/internal/deprecations/deprecations.ts +++ b/x-pack/plugins/reporting/server/routes/internal/deprecations/deprecations.ts @@ -6,8 +6,9 @@ */ import { errors } from '@elastic/elasticsearch'; import type { Logger, RequestHandler } from '@kbn/core/server'; +import { ILM_POLICY_NAME } from '@kbn/reporting-common'; import type { IlmPolicyStatusResponse } from '@kbn/reporting-common/url'; -import { ILM_POLICY_NAME, INTERNAL_ROUTES } from '../../../../common/constants'; +import { INTERNAL_ROUTES } from '../../../../common/constants'; import type { ReportingCore } from '../../../core'; import { IlmPolicyManager } from '../../../lib'; import { deprecations } from '../../../lib/deprecations'; diff --git a/x-pack/plugins/reporting/server/usage/get_export_stats.ts b/x-pack/plugins/reporting/server/usage/get_export_stats.ts index 4e2b1b6ceafc3..29d73232df884 100644 --- a/x-pack/plugins/reporting/server/usage/get_export_stats.ts +++ b/x-pack/plugins/reporting/server/usage/get_export_stats.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { DEPRECATED_JOB_TYPES } from '../../common/constants'; +import { DEPRECATED_JOB_TYPES } from '@kbn/reporting-common'; import { ExportTypesHandler } from './get_export_type_handler'; import { AvailableTotal, diff --git a/x-pack/plugins/reporting/server/usage/get_reporting_usage.ts b/x-pack/plugins/reporting/server/usage/get_reporting_usage.ts index c8ef2790932f6..5946e15b2dda3 100644 --- a/x-pack/plugins/reporting/server/usage/get_reporting_usage.ts +++ b/x-pack/plugins/reporting/server/usage/get_reporting_usage.ts @@ -6,9 +6,9 @@ */ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { ElasticsearchClient } from '@kbn/core/server'; +import { REPORTING_SYSTEM_INDEX } from '@kbn/reporting-common'; import { get, pick } from 'lodash'; import type { GetLicense } from '.'; -import { REPORTING_SYSTEM_INDEX } from '../../common/constants'; import type { ExportTypesRegistry } from '../lib/export_types_registry'; import { FIELD_EXECUTION_TIME_MS, diff --git a/x-pack/test/reporting_api_integration/reporting_and_security/csv_v2.ts b/x-pack/test/reporting_api_integration/reporting_and_security/csv_v2.ts index 0d75cb1449192..5b70c5db2fd8a 100644 --- a/x-pack/test/reporting_api_integration/reporting_and_security/csv_v2.ts +++ b/x-pack/test/reporting_api_integration/reporting_and_security/csv_v2.ts @@ -10,7 +10,7 @@ import request from 'supertest'; import { DISCOVER_APP_LOCATOR } from '@kbn/discover-plugin/common'; import type { JobParamsCsvFromSavedObject } from '@kbn/reporting-export-types-csv-common'; -import type { ReportApiJSON } from '@kbn/reporting-plugin/common/types'; +import type { ReportApiJSON } from '@kbn/reporting-common/types'; import rison from '@kbn/rison'; import { FtrProviderContext } from '../ftr_provider_context'; diff --git a/x-pack/test/reporting_api_integration/reporting_and_security/error_codes.ts b/x-pack/test/reporting_api_integration/reporting_and_security/error_codes.ts index 0d83da710ba23..1f417a3d526c2 100644 --- a/x-pack/test/reporting_api_integration/reporting_and_security/error_codes.ts +++ b/x-pack/test/reporting_api_integration/reporting_and_security/error_codes.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { INTERNAL_ROUTES } from '@kbn/reporting-plugin/common/constants/routes'; -import { ReportApiJSON } from '@kbn/reporting-plugin/common/types'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; import { FtrProviderContext } from '../ftr_provider_context'; // eslint-disable-next-line import/no-default-export diff --git a/x-pack/test/reporting_api_integration/reporting_and_security/generate_csv_discover.ts b/x-pack/test/reporting_api_integration/reporting_and_security/generate_csv_discover.ts index d7f9d772f826d..951fdf8ec5772 100644 --- a/x-pack/test/reporting_api_integration/reporting_and_security/generate_csv_discover.ts +++ b/x-pack/test/reporting_api_integration/reporting_and_security/generate_csv_discover.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { SerializedSearchSourceFields } from '@kbn/data-plugin/common'; -import { ReportApiJSON } from '@kbn/reporting-plugin/common/types'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; import { FtrProviderContext } from '../ftr_provider_context'; // eslint-disable-next-line import/no-default-export diff --git a/x-pack/test/reporting_api_integration/reporting_without_security/job_apis_csv.ts b/x-pack/test/reporting_api_integration/reporting_without_security/job_apis_csv.ts index 30f58524b46f8..921ad4ef6a915 100644 --- a/x-pack/test/reporting_api_integration/reporting_without_security/job_apis_csv.ts +++ b/x-pack/test/reporting_api_integration/reporting_without_security/job_apis_csv.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { INTERNAL_ROUTES } from '@kbn/reporting-plugin/common/constants/routes'; -import { ReportApiJSON } from '@kbn/reporting-plugin/common/types'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; import { pick } from 'lodash'; import { FtrProviderContext } from '../ftr_provider_context'; From 1c8cad6237882d0832cfb7c319a6b6705ee71464 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 13:40:07 -0700 Subject: [PATCH 10/25] Remove reporting-config-server package --- package.json | 1 - .../kbn-reporting/config_server/README.md | 3 - .../__snapshots__/schema.test.ts.snap | 122 -------------- packages/kbn-reporting/config_server/index.ts | 10 -- .../config_server/jest.config.js | 13 -- .../kbn-reporting/config_server/kibana.jsonc | 5 - .../kbn-reporting/config_server/package.json | 6 - .../config_server/schema.test.ts | 134 --------------- .../kbn-reporting/config_server/schema.ts | 152 ------------------ .../kbn-reporting/config_server/tsconfig.json | 19 --- tsconfig.base.json | 2 - x-pack/plugins/reporting/tsconfig.json | 1 - yarn.lock | 4 - 13 files changed, 472 deletions(-) delete mode 100644 packages/kbn-reporting/config_server/README.md delete mode 100644 packages/kbn-reporting/config_server/__snapshots__/schema.test.ts.snap delete mode 100644 packages/kbn-reporting/config_server/index.ts delete mode 100644 packages/kbn-reporting/config_server/jest.config.js delete mode 100644 packages/kbn-reporting/config_server/kibana.jsonc delete mode 100644 packages/kbn-reporting/config_server/package.json delete mode 100644 packages/kbn-reporting/config_server/schema.test.ts delete mode 100644 packages/kbn-reporting/config_server/schema.ts delete mode 100644 packages/kbn-reporting/config_server/tsconfig.json diff --git a/package.json b/package.json index d28aedeebef14..56780d2913560 100644 --- a/package.json +++ b/package.json @@ -594,7 +594,6 @@ "@kbn/repo-info": "link:packages/kbn-repo-info", "@kbn/repo-packages": "link:packages/kbn-repo-packages", "@kbn/reporting-common": "link:packages/kbn-reporting/common", - "@kbn/reporting-config-server": "link:packages/kbn-reporting/config_server", "@kbn/reporting-example-plugin": "link:x-pack/examples/reporting_example", "@kbn/reporting-export-types-csv": "link:packages/kbn-reporting/export_types/csv", "@kbn/reporting-export-types-csv-common": "link:packages/kbn-reporting/export_types/csv_common", diff --git a/packages/kbn-reporting/config_server/README.md b/packages/kbn-reporting/config_server/README.md deleted file mode 100644 index 08a8499bdb2d5..0000000000000 --- a/packages/kbn-reporting/config_server/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @kbn/reporting-config-server - -Empty package generated by @kbn/generate diff --git a/packages/kbn-reporting/config_server/__snapshots__/schema.test.ts.snap b/packages/kbn-reporting/config_server/__snapshots__/schema.test.ts.snap deleted file mode 100644 index 1c9a695f4a78e..0000000000000 --- a/packages/kbn-reporting/config_server/__snapshots__/schema.test.ts.snap +++ /dev/null @@ -1,122 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Reporting Config Schema context {"dev":false,"dist":false} produces correct config 1`] = ` -Object { - "capture": Object { - "maxAttempts": 1, - }, - "csv": Object { - "checkForFormulas": true, - "enablePanelActionDownload": true, - "escapeFormulaValues": false, - "maxSizeBytes": ByteSizeValue { - "valueInBytes": 262144000, - }, - "scroll": Object { - "duration": "30s", - "size": 500, - }, - "useByteOrderMarkEncoding": false, - }, - "enabled": true, - "encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "export_types": Object { - "csv": Object { - "enabled": true, - }, - "pdf": Object { - "enabled": true, - }, - "png": Object { - "enabled": true, - }, - }, - "kibanaServer": Object {}, - "poll": Object { - "jobCompletionNotifier": Object { - "interval": 10000, - "intervalErrorMultiplier": 5, - }, - "jobsRefresh": Object { - "interval": 5000, - "intervalErrorMultiplier": 5, - }, - }, - "queue": Object { - "indexInterval": "week", - "pollEnabled": true, - "pollInterval": "PT3S", - "pollIntervalErrorMultiplier": 10, - "timeout": "PT4M", - }, - "roles": Object { - "allow": Array [ - "reporting_user", - ], - "enabled": true, - }, - "statefulSettings": Object { - "enabled": true, - }, -} -`; - -exports[`Reporting Config Schema context {"dev":false,"dist":true} produces correct config 1`] = ` -Object { - "capture": Object { - "maxAttempts": 3, - }, - "csv": Object { - "checkForFormulas": true, - "enablePanelActionDownload": true, - "escapeFormulaValues": false, - "maxSizeBytes": ByteSizeValue { - "valueInBytes": 262144000, - }, - "scroll": Object { - "duration": "30s", - "size": 500, - }, - "useByteOrderMarkEncoding": false, - }, - "enabled": true, - "export_types": Object { - "csv": Object { - "enabled": true, - }, - "pdf": Object { - "enabled": true, - }, - "png": Object { - "enabled": true, - }, - }, - "kibanaServer": Object {}, - "poll": Object { - "jobCompletionNotifier": Object { - "interval": 10000, - "intervalErrorMultiplier": 5, - }, - "jobsRefresh": Object { - "interval": 5000, - "intervalErrorMultiplier": 5, - }, - }, - "queue": Object { - "indexInterval": "week", - "pollEnabled": true, - "pollInterval": "PT3S", - "pollIntervalErrorMultiplier": 10, - "timeout": "PT4M", - }, - "roles": Object { - "allow": Array [ - "reporting_user", - ], - "enabled": true, - }, - "statefulSettings": Object { - "enabled": true, - }, -} -`; diff --git a/packages/kbn-reporting/config_server/index.ts b/packages/kbn-reporting/config_server/index.ts deleted file mode 100644 index 57ddce550f9b1..0000000000000 --- a/packages/kbn-reporting/config_server/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * 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 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export { ConfigSchema } from './schema'; -export type { ReportingConfigType } from './schema'; diff --git a/packages/kbn-reporting/config_server/jest.config.js b/packages/kbn-reporting/config_server/jest.config.js deleted file mode 100644 index 050f036d10e37..0000000000000 --- a/packages/kbn-reporting/config_server/jest.config.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 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 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -module.exports = { - preset: '@kbn/test/jest_node', - rootDir: '../../..', - roots: ['/packages/kbn-reporting/config_server'], -}; diff --git a/packages/kbn-reporting/config_server/kibana.jsonc b/packages/kbn-reporting/config_server/kibana.jsonc deleted file mode 100644 index 0f3884ea6d5ff..0000000000000 --- a/packages/kbn-reporting/config_server/kibana.jsonc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "type": "shared-common", - "id": "@kbn/reporting-config-server", - "owner": "@elastic/appex-sharedux" -} diff --git a/packages/kbn-reporting/config_server/package.json b/packages/kbn-reporting/config_server/package.json deleted file mode 100644 index 9df47eaa9f737..0000000000000 --- a/packages/kbn-reporting/config_server/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "@kbn/reporting-config-server", - "private": true, - "version": "1.0.0", - "license": "SSPL-1.0 OR Elastic License 2.0" -} \ No newline at end of file diff --git a/packages/kbn-reporting/config_server/schema.test.ts b/packages/kbn-reporting/config_server/schema.test.ts deleted file mode 100644 index 58f2cc1a5e893..0000000000000 --- a/packages/kbn-reporting/config_server/schema.test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { ConfigSchema } from './schema'; - -describe('Reporting Config Schema', () => { - it(`context {"dev":false,"dist":false} produces correct config`, () => { - expect(ConfigSchema.validate({}, { dev: false, dist: false })).toMatchSnapshot(); - }); - - it(`context {"dev":false,"dist":true} produces correct config`, () => { - expect(ConfigSchema.validate({}, { dev: false, dist: true })).toMatchSnapshot(); - }); - - it('allows ByteSizeValue values for certain keys', () => { - expect(ConfigSchema.validate({ csv: { maxSizeBytes: '12mb' } }).csv.maxSizeBytes) - .toMatchInlineSnapshot(` - ByteSizeValue { - "valueInBytes": 12582912, - } - `); - }); - - it(`allows optional settings`, () => { - // encryption key - expect( - ConfigSchema.validate({ encryptionKey: 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq' }) - .encryptionKey - ).toBe('qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'); - - expect(ConfigSchema.validate({ encryptionKey: 'weaksauce' }).encryptionKey).toBe('weaksauce'); - // kibanaServer - expect( - ConfigSchema.validate({ kibanaServer: { hostname: 'Frodo' } }).kibanaServer - ).toMatchObject({ hostname: 'Frodo' }); - }); - - it.each(['0', '0.0', '0.0.0'])( - `fails to validate "kibanaServer.hostname" with an invalid hostname: "%s"`, - (address) => { - expect(() => - ConfigSchema.validate({ - kibanaServer: { hostname: address }, - }) - ).toThrowError(`[kibanaServer.hostname]: value must be a valid hostname (see RFC 1123).`); - } - ); - - it.each(['0.0.0.0', '0000:0000:0000:0000:0000:0000:0000:0000', '::'])( - `fails to validate "kibanaServer.hostname" hostname as zero: "%s"`, - (address) => { - expect(() => - ConfigSchema.validate({ - kibanaServer: { hostname: address }, - }) - ).toThrowError( - `[kibanaServer.hostname]: cannot use '0.0.0.0' as Kibana host name, consider using the default (localhost) instead` - ); - } - ); - - it('permits csv with serverless', () => { - expect(() => - ConfigSchema.validate({ export_types: { pdf: { enabled: true } } }, { dev: true }) - ).not.toThrow(); - }); - - it('enables all export types by default', () => { - expect(ConfigSchema.validate({}, { serverless: false }).export_types).toMatchInlineSnapshot(` - Object { - "csv": Object { - "enabled": true, - }, - "pdf": Object { - "enabled": true, - }, - "png": Object { - "enabled": true, - }, - } - `); - }); - - it('disables ilm settings in serverless', () => { - expect(ConfigSchema.validate({}, { serverless: true }).statefulSettings).toMatchInlineSnapshot(` - Object { - "enabled": false, - } - `); - }); - - it('disables screenshot type exports in serverless', () => { - expect(ConfigSchema.validate({}, { serverless: true }).export_types).toMatchInlineSnapshot(` - Object { - "csv": Object { - "enabled": true, - }, - "pdf": Object { - "enabled": false, - }, - "png": Object { - "enabled": false, - }, - } - `); - }); - - it('it should allow image reporting for any non-serverless config', () => { - expect(() => - ConfigSchema.validate({ export_types: { pdf: { enabled: true } } }, { dev: true }) - ).not.toThrow(); - expect(() => - ConfigSchema.validate({ export_types: { png: { enabled: true } } }, { dev: true }) - ).not.toThrow(); - expect(() => - ConfigSchema.validate({ export_types: { csv: { enabled: true } } }, { dev: true }) - ).not.toThrow(); - }); - - describe('roles', () => { - it('should have roles enabled set to false for serverless by default', () => { - expect(ConfigSchema.validate({}, { serverless: true }).roles.enabled).toBe(false); - }); - - it('should have roles enabled set to true for non-serverless by default', () => { - expect(ConfigSchema.validate({}).roles.enabled).toBe(true); - }); - }); -}); diff --git a/packages/kbn-reporting/config_server/schema.ts b/packages/kbn-reporting/config_server/schema.ts deleted file mode 100644 index f7c910d9c425b..0000000000000 --- a/packages/kbn-reporting/config_server/schema.ts +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { ByteSizeValue, offeringBasedSchema, schema, TypeOf } from '@kbn/config-schema'; -import ipaddr from 'ipaddr.js'; -import { sum } from 'lodash'; -import moment from 'moment'; - -const KibanaServerSchema = schema.object({ - hostname: schema.maybe( - schema.string({ - hostname: true, - validate(value) { - if (ipaddr.isValid(value) && !sum(ipaddr.parse(value).toByteArray())) { - // prevent setting a hostname that fails in Chromium on Windows - return `cannot use '0.0.0.0' as Kibana host name, consider using the default (localhost) instead`; - } - }, - }) - ), - port: schema.maybe(schema.number()), - protocol: schema.maybe( - schema.string({ - validate(value) { - if (!/^https?$/.test(value)) { - return 'must be "http" or "https"'; - } - }, - }) - ), -}); // default values are all dynamic in createConfig$ - -const QueueSchema = schema.object({ - indexInterval: schema.string({ defaultValue: 'week' }), - pollEnabled: schema.boolean({ defaultValue: true }), - pollInterval: schema.oneOf([schema.number(), schema.duration()], { - defaultValue: moment.duration({ seconds: 3 }), - }), - pollIntervalErrorMultiplier: schema.number({ defaultValue: 10 }), - timeout: schema.oneOf([schema.number(), schema.duration()], { - defaultValue: moment.duration({ minutes: 4 }), - }), -}); - -const CaptureSchema = schema.object({ - maxAttempts: schema.conditional( - schema.contextRef('dist'), - true, - schema.number({ defaultValue: 3 }), - schema.number({ defaultValue: 1 }) - ), -}); - -const CsvSchema = schema.object({ - checkForFormulas: schema.boolean({ defaultValue: true }), - escapeFormulaValues: schema.boolean({ defaultValue: false }), - enablePanelActionDownload: schema.boolean({ defaultValue: true }), - maxSizeBytes: schema.oneOf([schema.number(), schema.byteSize()], { - defaultValue: ByteSizeValue.parse('250mb'), - }), - useByteOrderMarkEncoding: schema.boolean({ defaultValue: false }), - scroll: schema.object({ - duration: schema.string({ - defaultValue: '30s', // this value is passed directly to ES, so string only format is preferred - validate(value) { - if (!/^[0-9]+(d|h|m|s|ms|micros|nanos)$/.test(value)) { - return 'must be a duration string'; - } - }, - }), - size: schema.number({ defaultValue: 500 }), - }), -}); - -const EncryptionKeySchema = schema.conditional( - schema.contextRef('dist'), - true, - schema.maybe(schema.string()), // default value is dynamic in createConfig$ - schema.string({ defaultValue: 'a'.repeat(32) }) -); - -const RolesSchema = schema.object({ - enabled: offeringBasedSchema({ - serverless: schema.boolean({ defaultValue: false }), - traditional: schema.boolean({ defaultValue: true }), - }), // true: use ES API for access control (deprecated in 7.x). false: use Kibana API for application features (8.0) - allow: offeringBasedSchema({ - serverless: schema.arrayOf(schema.string(), { defaultValue: [] }), - traditional: schema.arrayOf(schema.string(), { defaultValue: ['reporting_user'] }), - }), -}); - -// Browser side polling: job completion notifier, management table auto-refresh -// NOTE: can not use schema.duration, a bug prevents it being passed to the browser correctly -const PollSchema = schema.object({ - jobCompletionNotifier: schema.object({ - interval: schema.number({ defaultValue: 10000 }), - intervalErrorMultiplier: schema.number({ defaultValue: 5 }), // deprecated as unused since 7.10 - }), - jobsRefresh: schema.object({ - interval: schema.number({ defaultValue: 5000 }), - intervalErrorMultiplier: schema.number({ defaultValue: 5 }), // deprecated as unused since 7.10 - }), -}); - -const ExportTypeSchema = schema.object({ - // Csv reports are enabled in all offerings - csv: schema.object({ - enabled: schema.boolean({ defaultValue: true }), - }), - // Png reports are disabled in serverless - png: schema.object({ - enabled: offeringBasedSchema({ - serverless: schema.boolean({ defaultValue: false }), - traditional: schema.boolean({ defaultValue: true }), - }), - }), - // Pdf reports are disabled in serverless - pdf: schema.object({ - enabled: offeringBasedSchema({ - serverless: schema.boolean({ defaultValue: false }), - traditional: schema.boolean({ defaultValue: true }), - }), - }), -}); - -const SettingsSchema = schema.object({ - enabled: offeringBasedSchema({ - serverless: schema.boolean({ defaultValue: false }), - traditional: schema.boolean({ defaultValue: true }), - }), -}); - -export const ConfigSchema = schema.object({ - enabled: schema.boolean({ defaultValue: true }), - kibanaServer: KibanaServerSchema, - queue: QueueSchema, - capture: CaptureSchema, - csv: CsvSchema, - encryptionKey: EncryptionKeySchema, - roles: RolesSchema, - poll: PollSchema, - export_types: ExportTypeSchema, - statefulSettings: SettingsSchema, -}); - -export type ReportingConfigType = TypeOf; diff --git a/packages/kbn-reporting/config_server/tsconfig.json b/packages/kbn-reporting/config_server/tsconfig.json deleted file mode 100644 index 3df73f778fdc1..0000000000000 --- a/packages/kbn-reporting/config_server/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "extends": "../../../tsconfig.base.json", - "compilerOptions": { - "outDir": "target/types", - "types": [ - "jest", - "node" - ] - }, - "include": [ - "**/*.ts", - ], - "exclude": [ - "target/**/*" - ], - "kbn_references": [ - "@kbn/config-schema", - ] -} diff --git a/tsconfig.base.json b/tsconfig.base.json index ea69c25f57e34..a9aa9d1d7b36c 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1172,8 +1172,6 @@ "@kbn/repo-source-classifier-cli/*": ["packages/kbn-repo-source-classifier-cli/*"], "@kbn/reporting-common": ["packages/kbn-reporting/common"], "@kbn/reporting-common/*": ["packages/kbn-reporting/common/*"], - "@kbn/reporting-config-server": ["packages/kbn-reporting/config_server"], - "@kbn/reporting-config-server/*": ["packages/kbn-reporting/config_server/*"], "@kbn/reporting-example-plugin": ["x-pack/examples/reporting_example"], "@kbn/reporting-example-plugin/*": ["x-pack/examples/reporting_example/*"], "@kbn/reporting-export-types-csv": ["packages/kbn-reporting/export_types/csv"], diff --git a/x-pack/plugins/reporting/tsconfig.json b/x-pack/plugins/reporting/tsconfig.json index e29ad2120925f..4fb7674f4ade0 100644 --- a/x-pack/plugins/reporting/tsconfig.json +++ b/x-pack/plugins/reporting/tsconfig.json @@ -49,7 +49,6 @@ "@kbn/react-kibana-context-theme", "@kbn/reporting-export-types-png-common", "@kbn/reporting-mocks-server", - "@kbn/reporting-config-server", "@kbn/core-http-request-handler-context-server", ], "exclude": [ diff --git a/yarn.lock b/yarn.lock index 7908feafae972..bf6cc06a027ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5248,10 +5248,6 @@ version "0.0.0" uid "" -"@kbn/reporting-config-server@link:packages/kbn-reporting/config_server": - version "0.0.0" - uid "" - "@kbn/reporting-example-plugin@link:x-pack/examples/reporting_example": version "0.0.0" uid "" From f06eaf3c09412a10aae93f30ffadbd6669e38b84 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:55:24 +0000 Subject: [PATCH 11/25] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- packages/kbn-generate-csv/tsconfig.json | 1 + packages/kbn-reporting/common/tsconfig.json | 3 +++ packages/kbn-reporting/export_types/csv/tsconfig.json | 1 - packages/kbn-reporting/server/tsconfig.json | 1 + x-pack/plugins/reporting/tsconfig.json | 2 +- x-pack/test/tsconfig.json | 1 + 6 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/kbn-generate-csv/tsconfig.json b/packages/kbn-generate-csv/tsconfig.json index 54bb4b7615309..f84c03931dd31 100644 --- a/packages/kbn-generate-csv/tsconfig.json +++ b/packages/kbn-generate-csv/tsconfig.json @@ -25,5 +25,6 @@ "@kbn/i18n", "@kbn/reporting-common", "@kbn/reporting-export-types-csv-common", + "@kbn/reporting-server", ] } diff --git a/packages/kbn-reporting/common/tsconfig.json b/packages/kbn-reporting/common/tsconfig.json index 80ed6308f02ff..556abebb8a93c 100644 --- a/packages/kbn-reporting/common/tsconfig.json +++ b/packages/kbn-reporting/common/tsconfig.json @@ -19,5 +19,8 @@ "@kbn/utility-types", "@kbn/screenshotting-plugin", "@kbn/i18n", + "@kbn/reporting-export-types-csv-common", + "@kbn/reporting-export-types-pdf-common", + "@kbn/reporting-export-types-png-common", ] } diff --git a/packages/kbn-reporting/export_types/csv/tsconfig.json b/packages/kbn-reporting/export_types/csv/tsconfig.json index d1351d6c6be8c..553a976a2a64d 100644 --- a/packages/kbn-reporting/export_types/csv/tsconfig.json +++ b/packages/kbn-reporting/export_types/csv/tsconfig.json @@ -25,7 +25,6 @@ "@kbn/reporting-server", "@kbn/reporting-export-types-csv-common", "@kbn/reporting-mocks-server", - "@kbn/screenshotting-plugin", "@kbn/core-http-request-handler-context-server", ] } diff --git a/packages/kbn-reporting/server/tsconfig.json b/packages/kbn-reporting/server/tsconfig.json index 5dbd30b3e0cc5..26e1dfd461d21 100644 --- a/packages/kbn-reporting/server/tsconfig.json +++ b/packages/kbn-reporting/server/tsconfig.json @@ -34,5 +34,6 @@ "@kbn/core-http-router-server-internal", "@kbn/core-http-request-handler-context-server", "@kbn/reporting-export-types-pdf-common", + "@kbn/config-schema", ] } diff --git a/x-pack/plugins/reporting/tsconfig.json b/x-pack/plugins/reporting/tsconfig.json index 4fb7674f4ade0..53a4ab34eb197 100644 --- a/x-pack/plugins/reporting/tsconfig.json +++ b/x-pack/plugins/reporting/tsconfig.json @@ -35,7 +35,6 @@ "@kbn/core-http-server", "@kbn/core-test-helpers-test-utils", "@kbn/safer-lodash-set", - "@kbn/generate-csv", "@kbn/reporting-common", "@kbn/saved-search-plugin", "@kbn/core-http-router-server-internal", @@ -50,6 +49,7 @@ "@kbn/reporting-export-types-png-common", "@kbn/reporting-mocks-server", "@kbn/core-http-request-handler-context-server", + "@kbn/reporting-public", ], "exclude": [ "target/**/*", diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index 3b263d5cc5a3c..3d9c0dfd47d99 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -149,5 +149,6 @@ "@kbn/reporting-export-types-csv-common", "@kbn/reporting-export-types-pdf-common", "@kbn/reporting-export-types-png-common", + "@kbn/reporting-common", ] } From 56310cee53fa4788c302923948c0b2e3485a244d Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 13 Nov 2023 21:02:29 +0000 Subject: [PATCH 12/25] [CI] Auto-commit changed files from 'node scripts/generate codeowners' --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7ddd54cb9d87f..02f5f133bd307 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -589,7 +589,6 @@ packages/kbn-repo-path @elastic/kibana-operations packages/kbn-repo-source-classifier @elastic/kibana-operations packages/kbn-repo-source-classifier-cli @elastic/kibana-operations packages/kbn-reporting/common @elastic/appex-sharedux -packages/kbn-reporting/config_server @elastic/appex-sharedux x-pack/examples/reporting_example @elastic/appex-sharedux packages/kbn-reporting/export_types/csv @elastic/appex-sharedux packages/kbn-reporting/export_types/csv_common @elastic/appex-sharedux @@ -599,6 +598,7 @@ packages/kbn-reporting/export_types/png @elastic/appex-sharedux packages/kbn-reporting/export_types/png_common @elastic/appex-sharedux packages/kbn-reporting/mocks_server @elastic/appex-sharedux x-pack/plugins/reporting @elastic/appex-sharedux +packages/kbn-reporting/public @elastic/appex-sharedux packages/kbn-reporting/server @elastic/appex-sharedux packages/kbn-resizable-layout @elastic/kibana-data-discovery examples/resizable_layout_examples @elastic/kibana-data-discovery From c29baae7240d935547cb914020f8ec7dcdc5d9d8 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 14:32:33 -0700 Subject: [PATCH 13/25] fix 18n string IDs --- packages/kbn-reporting/common/errors.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/kbn-reporting/common/errors.ts b/packages/kbn-reporting/common/errors.ts index cea9ae544950c..46610c789a5cd 100644 --- a/packages/kbn-reporting/common/errors.ts +++ b/packages/kbn-reporting/common/errors.ts @@ -95,7 +95,7 @@ export class PdfWorkerOutOfMemoryError extends ReportingError { } public humanFriendlyMessage() { - return i18n.translate('generateCsv.pdfWorkerOutOfMemoryErrorMessage', { + return i18n.translate('reporting.common.pdfWorkerOutOfMemoryErrorMessage', { defaultMessage: `Can't generate a PDF due to insufficient memory. Try making a smaller PDF and retrying this report.`, }); } @@ -108,7 +108,7 @@ export class BrowserCouldNotLaunchError extends ReportingError { } public humanFriendlyMessage() { - return i18n.translate('generateCsv.browserCouldNotLaunchErrorMessage', { + return i18n.translate('reporting.common.browserCouldNotLaunchErrorMessage', { defaultMessage: `Can't generate screenshots because the browser did not launch. See the server logs for more information.`, }); } @@ -146,7 +146,7 @@ export class VisualReportingSoftDisabledError extends ReportingError { } humanFriendlyMessage() { - return i18n.translate('generateCsv.cloud.insufficientSystemMemoryError', { + return i18n.translate('reporting.common.cloud.insufficientSystemMemoryError', { defaultMessage: `Can't generate this report due to insufficient memory.`, }); } From 207cdeebd934011e2c79972e486ab153ee210ceb Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 15:13:39 -0700 Subject: [PATCH 14/25] fix circular graph --- packages/kbn-generate-csv/src/generate_csv.ts | 2 +- packages/kbn-generate-csv/tsconfig.json | 1 - packages/kbn-generate-csv/types.ts | 18 +++++++ packages/kbn-reporting/common/constants.ts | 54 ------------------- packages/kbn-reporting/common/tsconfig.json | 3 -- .../common/constants/export_types.ts | 54 +++++++++++++++++++ .../reporting/common/constants/index.ts | 1 + .../plugins/reporting/common/test/fixtures.ts | 19 +++---- .../plugins/reporting/public/lib/job.test.ts | 3 +- x-pack/plugins/reporting/public/lib/job.tsx | 4 +- .../components/report_info_flyout_content.tsx | 2 +- x-pack/plugins/reporting/public/types.ts | 12 ++--- .../reporting/server/lib/tasks/index.ts | 3 +- .../server/usage/get_export_stats.ts | 2 +- 14 files changed, 94 insertions(+), 84 deletions(-) create mode 100644 packages/kbn-generate-csv/types.ts create mode 100644 x-pack/plugins/reporting/common/constants/export_types.ts diff --git a/packages/kbn-generate-csv/src/generate_csv.ts b/packages/kbn-generate-csv/src/generate_csv.ts index d36a9b9da1231..59e69e9989c8e 100644 --- a/packages/kbn-generate-csv/src/generate_csv.ts +++ b/packages/kbn-generate-csv/src/generate_csv.ts @@ -28,12 +28,12 @@ import { } from '@kbn/reporting-common'; import type { TaskRunResult } from '@kbn/reporting-common/types'; import type { ReportingConfigType } from '@kbn/reporting-server'; -import { JobParamsCSV } from '@kbn/reporting-export-types-csv-common'; import { CONTENT_TYPE_CSV } from './constants'; import { CsvExportSettings, getExportSettings } from './get_export_settings'; import { i18nTexts } from './i18n_texts'; import { MaxSizeStringBuilder } from './max_size_string_builder'; +import { JobParamsCSV } from '../types'; interface Clients { es: IScopedClusterClient; diff --git a/packages/kbn-generate-csv/tsconfig.json b/packages/kbn-generate-csv/tsconfig.json index f84c03931dd31..a747ee469ad63 100644 --- a/packages/kbn-generate-csv/tsconfig.json +++ b/packages/kbn-generate-csv/tsconfig.json @@ -24,7 +24,6 @@ "@kbn/config-schema", "@kbn/i18n", "@kbn/reporting-common", - "@kbn/reporting-export-types-csv-common", "@kbn/reporting-server", ] } diff --git a/packages/kbn-generate-csv/types.ts b/packages/kbn-generate-csv/types.ts new file mode 100644 index 0000000000000..6d7461609afe2 --- /dev/null +++ b/packages/kbn-generate-csv/types.ts @@ -0,0 +1,18 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import type { SerializedSearchSourceFields } from '@kbn/data-plugin/public'; + +/** + * Duplicated from @kbn/reporting-export-types-csv-common to reduce dependencies + */ +export interface JobParamsCSV { + browserTimezone?: string; + searchSource: SerializedSearchSourceFields; + columns?: string[]; +} diff --git a/packages/kbn-reporting/common/constants.ts b/packages/kbn-reporting/common/constants.ts index 26aafa77ed4a8..02926a53a14eb 100644 --- a/packages/kbn-reporting/common/constants.ts +++ b/packages/kbn-reporting/common/constants.ts @@ -8,27 +8,6 @@ export const PLUGIN_ID = 'reporting'; -// Export Type Sets -import { - CSV_JOB_TYPE, - CSV_JOB_TYPE_DEPRECATED, - CSV_JOB_TYPE_V2, - CSV_REPORT_TYPE, - CSV_REPORT_TYPE_V2, -} from '@kbn/reporting-export-types-csv-common'; -import { - PDF_JOB_TYPE, - PDF_JOB_TYPE_V2, - PDF_REPORT_TYPE, - PDF_REPORT_TYPE_V2, -} from '@kbn/reporting-export-types-pdf-common'; -import { - PNG_JOB_TYPE, - PNG_JOB_TYPE_V2, - PNG_REPORT_TYPE, - PNG_REPORT_TYPE_V2, -} from '@kbn/reporting-export-types-png-common'; - export const ALLOWED_JOB_CONTENT_TYPES = [ 'application/json', 'application/pdf', @@ -37,39 +16,6 @@ export const ALLOWED_JOB_CONTENT_TYPES = [ 'text/plain', ]; -export const reportTypes = [ - CSV_REPORT_TYPE, - CSV_REPORT_TYPE_V2, - PDF_REPORT_TYPE, - PDF_REPORT_TYPE_V2, - PNG_REPORT_TYPE, - PNG_REPORT_TYPE_V2, -]; - -export const jobTypes = [ - CSV_JOB_TYPE, - CSV_JOB_TYPE_V2, - PDF_JOB_TYPE, - PDF_JOB_TYPE_V2, - PNG_JOB_TYPE, - PNG_JOB_TYPE_V2, -]; - -type ReportTypeDeclaration = typeof reportTypes; -export type ReportTypes = ReportTypeDeclaration[keyof ReportTypeDeclaration]; - -type JobTypeDeclaration = typeof jobTypes; -export type JobTypes = JobTypeDeclaration[keyof JobTypeDeclaration]; - -export const USES_HEADLESS_JOB_TYPES = [ - PDF_JOB_TYPE, - PNG_JOB_TYPE, - PDF_JOB_TYPE_V2, - PNG_JOB_TYPE_V2, -]; - -export const DEPRECATED_JOB_TYPES = [CSV_JOB_TYPE_DEPRECATED]; - // APM export const REPORTING_TRANSACTION_TYPE = PLUGIN_ID; diff --git a/packages/kbn-reporting/common/tsconfig.json b/packages/kbn-reporting/common/tsconfig.json index 556abebb8a93c..80ed6308f02ff 100644 --- a/packages/kbn-reporting/common/tsconfig.json +++ b/packages/kbn-reporting/common/tsconfig.json @@ -19,8 +19,5 @@ "@kbn/utility-types", "@kbn/screenshotting-plugin", "@kbn/i18n", - "@kbn/reporting-export-types-csv-common", - "@kbn/reporting-export-types-pdf-common", - "@kbn/reporting-export-types-png-common", ] } diff --git a/x-pack/plugins/reporting/common/constants/export_types.ts b/x-pack/plugins/reporting/common/constants/export_types.ts new file mode 100644 index 0000000000000..20f8a63204e75 --- /dev/null +++ b/x-pack/plugins/reporting/common/constants/export_types.ts @@ -0,0 +1,54 @@ +/* + * 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. + */ + +// Export Type Sets +import { + CSV_JOB_TYPE, + CSV_JOB_TYPE_DEPRECATED, + CSV_JOB_TYPE_V2, + CSV_REPORT_TYPE, + CSV_REPORT_TYPE_V2, +} from '@kbn/reporting-export-types-csv-common'; +import { + PDF_JOB_TYPE, + PDF_JOB_TYPE_V2, + PDF_REPORT_TYPE, + PDF_REPORT_TYPE_V2, +} from '@kbn/reporting-export-types-pdf-common'; +import { + PNG_JOB_TYPE, + PNG_JOB_TYPE_V2, + PNG_REPORT_TYPE, + PNG_REPORT_TYPE_V2, +} from '@kbn/reporting-export-types-png-common'; + +export const reportTypes = [ + CSV_REPORT_TYPE, + CSV_REPORT_TYPE_V2, + PDF_REPORT_TYPE, + PDF_REPORT_TYPE_V2, + PNG_REPORT_TYPE, + PNG_REPORT_TYPE_V2, +]; + +export const jobTypes = [ + CSV_JOB_TYPE, + CSV_JOB_TYPE_V2, + PDF_JOB_TYPE, + PDF_JOB_TYPE_V2, + PNG_JOB_TYPE, + PNG_JOB_TYPE_V2, +]; + +export const USES_HEADLESS_JOB_TYPES = [ + PDF_JOB_TYPE, + PNG_JOB_TYPE, + PDF_JOB_TYPE_V2, + PNG_JOB_TYPE_V2, +]; + +export const DEPRECATED_JOB_TYPES = [CSV_JOB_TYPE_DEPRECATED]; diff --git a/x-pack/plugins/reporting/common/constants/index.ts b/x-pack/plugins/reporting/common/constants/index.ts index 1424ee18b7be8..44e90356027bc 100644 --- a/x-pack/plugins/reporting/common/constants/index.ts +++ b/x-pack/plugins/reporting/common/constants/index.ts @@ -6,6 +6,7 @@ */ export * from './routes'; +export * from './export_types'; // Test Subjects export const REPORT_TABLE_ID = 'reportJobListing'; diff --git a/x-pack/plugins/reporting/common/test/fixtures.ts b/x-pack/plugins/reporting/common/test/fixtures.ts index 1628fb9e6af80..823785c4eb273 100644 --- a/x-pack/plugins/reporting/common/test/fixtures.ts +++ b/x-pack/plugins/reporting/common/test/fixtures.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { JOB_STATUS } from '@kbn/reporting-common'; import { ReportApiJSON } from '@kbn/reporting-common/types'; import type { ReportMock } from './types'; @@ -43,7 +44,7 @@ export const mockJobs: ReportApiJSON[] = [ }, ], } as any, - status: 'pending', + status: JOB_STATUS.PENDING, }), buildMockReport({ id: 'k90e51pk1ieucbae0c3t8wo1', @@ -56,7 +57,7 @@ export const mockJobs: ReportApiJSON[] = [ title: 'My Canvas Workpad', }, started_at: '2020-04-14T21:01:14.526Z', - status: 'processing', + status: JOB_STATUS.PROCESSING, }), buildMockReport({ id: 'k90cmthd1gv8cbae0c2le8bo', @@ -71,7 +72,7 @@ export const mockJobs: ReportApiJSON[] = [ title: 'My Canvas Workpad', }, started_at: '2020-04-14T20:19:04.073Z', - status: 'completed', + status: JOB_STATUS.COMPLETED, }), buildMockReport({ id: 'k906958e1d4wcbae0c9hip1a', @@ -92,7 +93,7 @@ export const mockJobs: ReportApiJSON[] = [ title: 'My Canvas Workpad', }, started_at: '2020-04-14T17:20:29.444Z', - status: 'completed_with_warnings', + status: JOB_STATUS.WARNINGS, }), buildMockReport({ id: 'k9067y2a1d4wcbae0cad38n0', @@ -107,7 +108,7 @@ export const mockJobs: ReportApiJSON[] = [ title: 'My Canvas Workpad', }, started_at: '2020-04-14T17:19:39.883Z', - status: 'completed', + status: JOB_STATUS.COMPLETED, }), buildMockReport({ id: 'k9067s1m1d4wcbae0cdnvcms', @@ -122,7 +123,7 @@ export const mockJobs: ReportApiJSON[] = [ title: 'My Canvas Workpad', }, started_at: '2020-04-14T17:19:25.247Z', - status: 'completed', + status: JOB_STATUS.COMPLETED, }), buildMockReport({ id: 'k9065q3s1d4wcbae0c00fxlh', @@ -137,7 +138,7 @@ export const mockJobs: ReportApiJSON[] = [ title: 'My Canvas Workpad', }, started_at: '2020-04-14T17:17:50.379Z', - status: 'completed', + status: JOB_STATUS.COMPLETED, }), buildMockReport({ id: 'k905zdw11d34cbae0c3y6tzh', @@ -153,7 +154,7 @@ export const mockJobs: ReportApiJSON[] = [ isDeprecated: true, }, started_at: '2020-04-14T17:12:52.431Z', - status: 'completed', + status: JOB_STATUS.COMPLETED, }), buildMockReport({ id: 'k8t4ylcb07mi9d006214ifyg', @@ -169,6 +170,6 @@ export const mockJobs: ReportApiJSON[] = [ isDeprecated: true, }, started_at: '2020-04-09T19:09:54.570Z', - status: 'completed', + status: JOB_STATUS.COMPLETED, }), ]; diff --git a/x-pack/plugins/reporting/public/lib/job.test.ts b/x-pack/plugins/reporting/public/lib/job.test.ts index d8be3b3e7060b..3f1e64d57daf8 100644 --- a/x-pack/plugins/reporting/public/lib/job.test.ts +++ b/x-pack/plugins/reporting/public/lib/job.test.ts @@ -5,8 +5,7 @@ * 2.0. */ -import { jobTypes } from '@kbn/reporting-common'; - +import { jobTypes } from '../../common/constants'; import { mockJobs } from '../../common/test'; import { Job } from './job'; diff --git a/x-pack/plugins/reporting/public/lib/job.tsx b/x-pack/plugins/reporting/public/lib/job.tsx index 38fd9b70b0a74..9aadb06bf5cc8 100644 --- a/x-pack/plugins/reporting/public/lib/job.tsx +++ b/x-pack/plugins/reporting/public/lib/job.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { EuiText, EuiTextColor } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { JOB_STATUS, JobTypes } from '@kbn/reporting-common'; +import { JOB_STATUS } from '@kbn/reporting-common'; import type { BaseParamsV2, JobId, @@ -21,6 +21,8 @@ import type { TaskRunResult, } from '@kbn/reporting-common/types'; +import { JobTypes } from '../../common/types'; + const { COMPLETED, FAILED, PENDING, PROCESSING, WARNINGS } = JOB_STATUS; type ReportPayload = ReportSource['payload']; diff --git a/x-pack/plugins/reporting/public/management/components/report_info_flyout_content.tsx b/x-pack/plugins/reporting/public/management/components/report_info_flyout_content.tsx index 04a18a9572946..ca47477133f6f 100644 --- a/x-pack/plugins/reporting/public/management/components/report_info_flyout_content.tsx +++ b/x-pack/plugins/reporting/public/management/components/report_info_flyout_content.tsx @@ -16,9 +16,9 @@ import { EuiTitle, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { USES_HEADLESS_JOB_TYPES } from '@kbn/reporting-common'; import { VisualReportingSoftDisabledError } from '@kbn/reporting-common/errors'; +import { USES_HEADLESS_JOB_TYPES } from '../../../common/constants'; import type { Job } from '../../lib/job'; import { sharedI18nTexts } from '../../shared_i18n_texts'; import { useKibana } from '../../shared_imports'; diff --git a/x-pack/plugins/reporting/public/types.ts b/x-pack/plugins/reporting/public/types.ts index 705232e6f32e3..5b88f2abbf5bd 100644 --- a/x-pack/plugins/reporting/public/types.ts +++ b/x-pack/plugins/reporting/public/types.ts @@ -6,19 +6,13 @@ */ import type { CoreSetup, CoreStart } from '@kbn/core/public'; - -import type { - JobId, - JobStatus, - ReportOutput, - ReportSource, - TaskRunResult, -} from '@kbn/reporting-common/types'; +import { JOB_STATUS } from '@kbn/reporting-common'; +import type { JobId, ReportOutput, ReportSource, TaskRunResult } from '@kbn/reporting-common/types'; /* Notifier Toasts */ export interface JobSummary { id: JobId; - status: JobStatus; + status: JOB_STATUS; jobtype: ReportSource['jobtype']; title: ReportSource['payload']['title']; errorCode?: ReportOutput['error_code']; diff --git a/x-pack/plugins/reporting/server/lib/tasks/index.ts b/x-pack/plugins/reporting/server/lib/tasks/index.ts index 7708f31f7147f..54493aee6de58 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/index.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/index.ts @@ -6,8 +6,7 @@ */ import { TaskRunCreatorFunction } from '@kbn/task-manager-plugin/server'; -import { BasePayload } from '@kbn/reporting-common/types'; -import { ReportSource } from '../../../common/types'; +import { BasePayload, ReportSource } from '@kbn/reporting-common/types'; export const REPORTING_EXECUTE_TYPE = 'report:execute'; export const REPORTING_MONITOR_TYPE = 'reports:monitor'; diff --git a/x-pack/plugins/reporting/server/usage/get_export_stats.ts b/x-pack/plugins/reporting/server/usage/get_export_stats.ts index 29d73232df884..4e2b1b6ceafc3 100644 --- a/x-pack/plugins/reporting/server/usage/get_export_stats.ts +++ b/x-pack/plugins/reporting/server/usage/get_export_stats.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { DEPRECATED_JOB_TYPES } from '@kbn/reporting-common'; +import { DEPRECATED_JOB_TYPES } from '../../common/constants'; import { ExportTypesHandler } from './get_export_type_handler'; import { AvailableTotal, From e51c81cedf6775c2f0dc5b085e969f1cd295d1b1 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 15:27:08 -0700 Subject: [PATCH 15/25] Update config-server imports --- .../kbn-generate-csv/src/get_export_settings.ts | 2 +- .../server/{config.ts => config_schema.ts} | 4 +--- packages/kbn-reporting/server/index.ts | 4 ++-- packages/kbn-reporting/server/types.ts | 7 ++++++- x-pack/plugins/reporting/common/types.ts | 14 ++++++++++++++ .../reporting/server/config/create_config.ts | 2 +- x-pack/plugins/reporting/server/config/index.ts | 1 - x-pack/plugins/reporting/server/core.ts | 7 ++++--- x-pack/plugins/reporting/server/index.ts | 4 ++-- .../server/lib/tasks/execute_report.test.ts | 3 +-- .../reporting/server/lib/tasks/execute_report.ts | 2 +- .../server/lib/tasks/monitor_report.test.ts | 6 +++--- .../reporting/server/lib/tasks/monitor_reports.ts | 7 +++++-- x-pack/plugins/reporting/server/plugin.ts | 3 ++- .../test_helpers/create_mock_reportingplugin.ts | 4 ++-- x-pack/plugins/reporting/server/types.ts | 4 ++-- 16 files changed, 47 insertions(+), 27 deletions(-) rename packages/kbn-reporting/server/{config.ts => config_schema.ts} (97%) create mode 100644 x-pack/plugins/reporting/common/types.ts diff --git a/packages/kbn-generate-csv/src/get_export_settings.ts b/packages/kbn-generate-csv/src/get_export_settings.ts index f6804b5d17572..faef6fdc60f87 100644 --- a/packages/kbn-generate-csv/src/get_export_settings.ts +++ b/packages/kbn-generate-csv/src/get_export_settings.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { ByteSizeValue } from '@kbn/config-schema'; +import type { ByteSizeValue } from '@kbn/config-schema'; import type { IUiSettingsClient, Logger } from '@kbn/core/server'; import { createEscapeValue } from '@kbn/data-plugin/common'; import type { ReportingConfigType } from '@kbn/reporting-server'; diff --git a/packages/kbn-reporting/server/config.ts b/packages/kbn-reporting/server/config_schema.ts similarity index 97% rename from packages/kbn-reporting/server/config.ts rename to packages/kbn-reporting/server/config_schema.ts index f7c910d9c425b..3aab7be6e660c 100644 --- a/packages/kbn-reporting/server/config.ts +++ b/packages/kbn-reporting/server/config_schema.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { ByteSizeValue, offeringBasedSchema, schema, TypeOf } from '@kbn/config-schema'; +import { ByteSizeValue, offeringBasedSchema, schema } from '@kbn/config-schema'; import ipaddr from 'ipaddr.js'; import { sum } from 'lodash'; import moment from 'moment'; @@ -148,5 +148,3 @@ export const ConfigSchema = schema.object({ export_types: ExportTypeSchema, statefulSettings: SettingsSchema, }); - -export type ReportingConfigType = TypeOf; diff --git a/packages/kbn-reporting/server/index.ts b/packages/kbn-reporting/server/index.ts index b177c953085b4..407eae4d8ce1e 100644 --- a/packages/kbn-reporting/server/index.ts +++ b/packages/kbn-reporting/server/index.ts @@ -21,6 +21,6 @@ export { getFieldFormats, setFieldFormats } from './services'; export { validateUrls } from './validate_urls'; export type { BaseExportTypeSetupDeps, BaseExportTypeStartDeps } from './export_type'; -export * from './types'; +export { ConfigSchema } from './config_schema'; -export { ConfigSchema, ReportingConfigType } from './config'; +export * from './types'; diff --git a/packages/kbn-reporting/server/types.ts b/packages/kbn-reporting/server/types.ts index 007333de214e7..94ad1e34a19d3 100644 --- a/packages/kbn-reporting/server/types.ts +++ b/packages/kbn-reporting/server/types.ts @@ -8,11 +8,14 @@ import { Writable } from 'stream'; +import type { TypeOf } from '@kbn/config-schema'; import type { CustomRequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; import type { KibanaRequest } from '@kbn/core-http-server'; import type { CancellationToken } from '@kbn/reporting-common'; import type { BaseParams, BasePayload, TaskRunResult } from '@kbn/reporting-common/types'; -import { ExportType } from './export_type'; + +import { ConfigSchema } from './config_schema'; +import type { ExportType } from './export_type'; export interface ReportingServerPluginSetup { registerExportTypes: (item: ExportType) => void; @@ -43,3 +46,5 @@ export interface TimeRangeParams { min?: Date | string | number | null; max?: Date | string | number | null; } + +export type ReportingConfigType = TypeOf; diff --git a/x-pack/plugins/reporting/common/types.ts b/x-pack/plugins/reporting/common/types.ts new file mode 100644 index 0000000000000..09d1dc8f43e31 --- /dev/null +++ b/x-pack/plugins/reporting/common/types.ts @@ -0,0 +1,14 @@ +/* + * 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 { jobTypes, reportTypes } from './constants'; + +type ReportTypeDeclaration = typeof reportTypes; +export type ReportTypes = ReportTypeDeclaration[keyof ReportTypeDeclaration]; + +type JobTypeDeclaration = typeof jobTypes; +export type JobTypes = JobTypeDeclaration[keyof JobTypeDeclaration]; diff --git a/x-pack/plugins/reporting/server/config/create_config.ts b/x-pack/plugins/reporting/server/config/create_config.ts index d0a7770237195..3841b2920a8eb 100644 --- a/x-pack/plugins/reporting/server/config/create_config.ts +++ b/x-pack/plugins/reporting/server/config/create_config.ts @@ -10,7 +10,7 @@ import ipaddr from 'ipaddr.js'; import { sum } from 'lodash'; import type { CoreSetup, Logger } from '@kbn/core/server'; -import { ReportingConfigType } from '.'; +import type { ReportingConfigType } from '@kbn/reporting-server'; /* * Set up dynamic config defaults diff --git a/x-pack/plugins/reporting/server/config/index.ts b/x-pack/plugins/reporting/server/config/index.ts index bb47bb9658412..5965693e37c13 100644 --- a/x-pack/plugins/reporting/server/config/index.ts +++ b/x-pack/plugins/reporting/server/config/index.ts @@ -72,4 +72,3 @@ export const config: PluginConfigDescriptor = { export { createConfig } from './create_config'; export { registerUiSettings } from './ui_settings'; export { ConfigSchema }; -export type { ReportingConfigType }; diff --git a/x-pack/plugins/reporting/server/core.ts b/x-pack/plugins/reporting/server/core.ts index dd046b2daef22..03d6a1138e385 100644 --- a/x-pack/plugins/reporting/server/core.ts +++ b/x-pack/plugins/reporting/server/core.ts @@ -33,9 +33,10 @@ import { CsvSearchSourceImmediateExportType, CsvV2ExportType, } from '@kbn/reporting-export-types-csv'; -import { ExportType } from '@kbn/reporting-server'; -import { PdfV1ExportType, PdfExportType } from '@kbn/reporting-export-types-pdf'; +import { PdfExportType, PdfV1ExportType } from '@kbn/reporting-export-types-pdf'; import { PngExportType } from '@kbn/reporting-export-types-png'; +import type { ReportingConfigType } from '@kbn/reporting-server'; +import { ExportType } from '@kbn/reporting-server'; import { PdfScreenshotResult, PngScreenshotResult, @@ -52,7 +53,7 @@ import type { import type { UsageCounter } from '@kbn/usage-collection-plugin/server'; import type { ReportingSetup } from '.'; -import { ReportingConfigType, createConfig } from './config'; +import { createConfig } from './config'; import { ExportTypesRegistry, checkLicense } from './lib'; import { reportingEventLoggerFactory } from './lib/event_logger/logger'; import type { IReport, ReportingStore } from './lib/store'; diff --git a/x-pack/plugins/reporting/server/index.ts b/x-pack/plugins/reporting/server/index.ts index 1089331ccd110..e9c9ec69fecc5 100644 --- a/x-pack/plugins/reporting/server/index.ts +++ b/x-pack/plugins/reporting/server/index.ts @@ -5,8 +5,8 @@ * 2.0. */ -import { PluginInitializerContext } from '@kbn/core/server'; -import { ReportingConfigType } from './config'; +import type { PluginInitializerContext } from '@kbn/core/server'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import { ReportingPlugin } from './plugin'; export { config } from './config'; diff --git a/x-pack/plugins/reporting/server/lib/tasks/execute_report.test.ts b/x-pack/plugins/reporting/server/lib/tasks/execute_report.test.ts index a091a23bcc1f1..90b1daacc9f0c 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/execute_report.test.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/execute_report.test.ts @@ -8,13 +8,12 @@ import { loggingSystemMock } from '@kbn/core/server/mocks'; import { KibanaShuttingDownError } from '@kbn/reporting-common'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; -import type { ExportType } from '@kbn/reporting-server'; +import type { ExportType, ReportingConfigType } from '@kbn/reporting-server'; import type { RunContext } from '@kbn/task-manager-plugin/server'; import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks'; import { ExecuteReportTask } from '.'; import type { ReportingCore } from '../..'; -import type { ReportingConfigType } from '../../config'; import { createMockReportingCore } from '../../test_helpers'; import type { SavedReport } from '../store'; diff --git a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts index 32aee34caa0de..62c31c8cb185a 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts @@ -23,6 +23,7 @@ import { numberToDuration, } from '@kbn/reporting-common'; import type { ReportOutput, TaskRunResult } from '@kbn/reporting-common/types'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import type { RunContext, TaskManagerStartContract, @@ -33,7 +34,6 @@ import { REPORTING_EXECUTE_TYPE, ReportTaskParams, ReportingTask, ReportingTaskS import { ExportTypesRegistry, getContentStream } from '..'; import type { ReportingCore } from '../..'; import { mapToReportingError } from '../../../common/errors/map_to_reporting_error'; -import type { ReportingConfigType } from '../../config'; import type { ReportDocument, ReportingStore } from '../store'; import { Report, SavedReport } from '../store'; import type { ReportFailedFields, ReportProcessingFields } from '../store/store'; diff --git a/x-pack/plugins/reporting/server/lib/tasks/monitor_report.test.ts b/x-pack/plugins/reporting/server/lib/tasks/monitor_report.test.ts index 77d7204abe069..cf17fd2c65221 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/monitor_report.test.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/monitor_report.test.ts @@ -7,11 +7,11 @@ import { loggingSystemMock } from '@kbn/core/server/mocks'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; -import { RunContext } from '@kbn/task-manager-plugin/server'; +import type { RunContext } from '@kbn/task-manager-plugin/server'; import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import { MonitorReportsTask } from '.'; -import { ReportingCore } from '../..'; -import { ReportingConfigType } from '../../config'; +import type { ReportingCore } from '../..'; import { createMockReportingCore } from '../../test_helpers'; const logger = loggingSystemMock.createLogger(); diff --git a/x-pack/plugins/reporting/server/lib/tasks/monitor_reports.ts b/x-pack/plugins/reporting/server/lib/tasks/monitor_reports.ts index 867adf3617248..c42e2f8afa5b2 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/monitor_reports.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/monitor_reports.ts @@ -7,11 +7,14 @@ import type { Logger } from '@kbn/core/server'; import moment from 'moment'; -import { TaskManagerStartContract, TaskRunCreatorFunction } from '@kbn/task-manager-plugin/server'; +import type { + TaskManagerStartContract, + TaskRunCreatorFunction, +} from '@kbn/task-manager-plugin/server'; import { JOB_STATUS, numberToDuration } from '@kbn/reporting-common'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import { ReportingStore } from '..'; import { ReportingCore } from '../..'; -import { ReportingConfigType } from '../../config'; import { SavedReport } from '../store'; import { ReportingTask, ReportingTaskStatus, REPORTING_MONITOR_TYPE, ReportTaskParams } from '.'; diff --git a/x-pack/plugins/reporting/server/plugin.ts b/x-pack/plugins/reporting/server/plugin.ts index db653917cb401..b05430200c2e1 100644 --- a/x-pack/plugins/reporting/server/plugin.ts +++ b/x-pack/plugins/reporting/server/plugin.ts @@ -13,9 +13,10 @@ import type { PluginInitializerContext, } from '@kbn/core/server'; import { PLUGIN_ID } from '@kbn/reporting-common'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import { setFieldFormats } from '@kbn/reporting-server'; import { ReportingCore } from '.'; -import { ReportingConfigType, registerUiSettings } from './config'; +import { registerUiSettings } from './config'; import { registerDeprecations } from './deprecations'; import { ReportingStore } from './lib'; import { registerRoutes } from './routes'; diff --git a/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts b/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts index d92174d3d71cd..eb308d9cf0e15 100644 --- a/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts +++ b/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts @@ -24,13 +24,13 @@ import { FieldFormatsRegistry } from '@kbn/field-formats-plugin/common'; import { fieldFormatsMock } from '@kbn/field-formats-plugin/common/mocks'; import { licensingMock } from '@kbn/licensing-plugin/server/mocks'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import { setFieldFormats } from '@kbn/reporting-server'; import { createMockScreenshottingStart } from '@kbn/screenshotting-plugin/server/mock'; import { securityMock } from '@kbn/security-plugin/server/mocks'; import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks'; - import { ReportingCore } from '..'; -import { ReportingConfigType } from '../config'; + import { ReportingInternalSetup, ReportingInternalStart } from '../core'; import { ReportingStore } from '../lib'; diff --git a/x-pack/plugins/reporting/server/types.ts b/x-pack/plugins/reporting/server/types.ts index f0573af0651f1..8acfaeb8dd41b 100644 --- a/x-pack/plugins/reporting/server/types.ts +++ b/x-pack/plugins/reporting/server/types.ts @@ -13,7 +13,8 @@ import type { PluginSetupContract as FeaturesPluginSetup } from '@kbn/features-p import type { FieldFormatsStart } from '@kbn/field-formats-plugin/server'; import type { LicensingPluginStart } from '@kbn/licensing-plugin/server'; import type { UrlOrUrlLocatorTuple } from '@kbn/reporting-common/types'; -import { ReportApiJSON } from '@kbn/reporting-common/types'; +import type { ReportApiJSON } from '@kbn/reporting-common/types'; +import type { ReportingConfigType } from '@kbn/reporting-server'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; import type { PdfScreenshotOptions as BasePdfScreenshotOptions, @@ -32,7 +33,6 @@ import type { } from '@kbn/task-manager-plugin/server'; import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server'; -import type { ReportingConfigType } from './config'; import { ReportingCore } from './core'; import { ExportTypesRegistry } from './lib'; From c17f806ef066bf5b20af53df95d2c565503d3bdc Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 13 Nov 2023 22:35:15 +0000 Subject: [PATCH 16/25] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- packages/kbn-generate-csv/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kbn-generate-csv/tsconfig.json b/packages/kbn-generate-csv/tsconfig.json index a747ee469ad63..51dbd54dda73e 100644 --- a/packages/kbn-generate-csv/tsconfig.json +++ b/packages/kbn-generate-csv/tsconfig.json @@ -25,5 +25,6 @@ "@kbn/i18n", "@kbn/reporting-common", "@kbn/reporting-server", + "@kbn/reporting-export-types-csv-common", ] } From cd36152848fa822f9a724a5f8a26901d276aa6e8 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 15:38:40 -0700 Subject: [PATCH 17/25] fix types --- x-pack/plugins/reporting/server/lib/store/index.ts | 1 - x-pack/plugins/reporting/server/lib/store/saved_report.ts | 2 +- x-pack/plugins/reporting/server/lib/store/store.test.ts | 3 ++- x-pack/plugins/reporting/server/lib/store/store.ts | 4 ++-- x-pack/plugins/reporting/server/lib/tasks/execute_report.ts | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/reporting/server/lib/store/index.ts b/x-pack/plugins/reporting/server/lib/store/index.ts index 125c592c8626b..5bc72b339d89e 100644 --- a/x-pack/plugins/reporting/server/lib/store/index.ts +++ b/x-pack/plugins/reporting/server/lib/store/index.ts @@ -5,7 +5,6 @@ * 2.0. */ -export type { ReportDocument } from '../../../common/types'; export { Report } from './report'; export { SavedReport } from './saved_report'; export { ReportingStore } from './store'; diff --git a/x-pack/plugins/reporting/server/lib/store/saved_report.ts b/x-pack/plugins/reporting/server/lib/store/saved_report.ts index c4d46c167a312..090e87470a07d 100644 --- a/x-pack/plugins/reporting/server/lib/store/saved_report.ts +++ b/x-pack/plugins/reporting/server/lib/store/saved_report.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { ReportDocumentHead, ReportSource } from '../../../common/types'; +import { ReportDocumentHead, ReportSource } from '@kbn/reporting-common/types'; import { Report } from '.'; /* diff --git a/x-pack/plugins/reporting/server/lib/store/store.test.ts b/x-pack/plugins/reporting/server/lib/store/store.test.ts index d73b2df5ca172..bc872c7de5d7b 100644 --- a/x-pack/plugins/reporting/server/lib/store/store.test.ts +++ b/x-pack/plugins/reporting/server/lib/store/store.test.ts @@ -6,10 +6,11 @@ */ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks'; +import { ReportDocument } from '@kbn/reporting-common/types'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; +import { Report, ReportingStore, SavedReport } from '.'; import { ReportingCore } from '../..'; import { createMockReportingCore } from '../../test_helpers'; -import { Report, ReportDocument, ReportingStore, SavedReport } from '.'; describe('ReportingStore', () => { const mockLogger = loggingSystemMock.createLogger(); diff --git a/x-pack/plugins/reporting/server/lib/store/store.ts b/x-pack/plugins/reporting/server/lib/store/store.ts index f13f1169ade3b..710a78ffe859a 100644 --- a/x-pack/plugins/reporting/server/lib/store/store.ts +++ b/x-pack/plugins/reporting/server/lib/store/store.ts @@ -8,9 +8,9 @@ import { estypes } from '@elastic/elasticsearch'; import type { ElasticsearchClient, Logger } from '@kbn/core/server'; import { ILM_POLICY_NAME, JOB_STATUS, REPORTING_SYSTEM_INDEX } from '@kbn/reporting-common'; -import { ReportOutput, ReportSource } from '@kbn/reporting-common/types'; +import { ReportDocument, ReportOutput, ReportSource } from '@kbn/reporting-common/types'; import moment from 'moment'; -import type { IReport, Report, ReportDocument } from '.'; +import type { IReport, Report } from '.'; import { SavedReport } from '.'; import type { ReportingCore } from '../..'; import type { ReportTaskParams } from '../tasks'; diff --git a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts index 62c31c8cb185a..8bc6ba0f865ec 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts @@ -22,7 +22,7 @@ import { durationToNumber, numberToDuration, } from '@kbn/reporting-common'; -import type { ReportOutput, TaskRunResult } from '@kbn/reporting-common/types'; +import type { ReportDocument, ReportOutput, TaskRunResult } from '@kbn/reporting-common/types'; import type { ReportingConfigType } from '@kbn/reporting-server'; import type { RunContext, @@ -34,7 +34,7 @@ import { REPORTING_EXECUTE_TYPE, ReportTaskParams, ReportingTask, ReportingTaskS import { ExportTypesRegistry, getContentStream } from '..'; import type { ReportingCore } from '../..'; import { mapToReportingError } from '../../../common/errors/map_to_reporting_error'; -import type { ReportDocument, ReportingStore } from '../store'; +import type { ReportingStore } from '../store'; import { Report, SavedReport } from '../store'; import type { ReportFailedFields, ReportProcessingFields } from '../store/store'; import { errorLogger } from './error_logger'; From 4c6eaaa62f4db1304364013109ffe0e21fe7efad Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 15:50:44 -0700 Subject: [PATCH 18/25] clean up getScreenshots --- .../export_types/pdf/deprecated.ts | 19 +++-------- .../export_types/pdf/printable_pdf_v2.ts | 23 ++++--------- .../kbn-reporting/export_types/png/png_v2.ts | 22 ++++--------- x-pack/plugins/reporting/server/core.ts | 32 ++----------------- .../reporting/server/lib/store/store.test.ts | 5 +-- x-pack/plugins/reporting/server/types.ts | 2 -- .../ilm_migration_apis.ts | 2 +- 7 files changed, 26 insertions(+), 79 deletions(-) diff --git a/packages/kbn-reporting/export_types/pdf/deprecated.ts b/packages/kbn-reporting/export_types/pdf/deprecated.ts index 21f6d8881a60a..6c6aea003ba6a 100644 --- a/packages/kbn-reporting/export_types/pdf/deprecated.ts +++ b/packages/kbn-reporting/export_types/pdf/deprecated.ts @@ -19,7 +19,6 @@ import { LICENSE_TYPE_GOLD, LICENSE_TYPE_PLATINUM, LICENSE_TYPE_TRIAL, - REPORTING_REDIRECT_LOCATOR_STORE_KEY, REPORTING_TRANSACTION_TYPE, } from '@kbn/reporting-common'; import { TaskRunResult } from '@kbn/reporting-common/types'; @@ -36,7 +35,6 @@ import { getFullUrls, validateUrls, } from '@kbn/reporting-server'; -import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; /** * @deprecated @@ -60,16 +58,6 @@ export class PdfV1ExportType extends ExportType { - if (!this.startDeps.screenshotting) throw new Error('Screenshotting plugin is not initialized'); - return this.startDeps.screenshotting.getScreenshots({ - ...options, - urls: options?.urls?.map((url) => - typeof url === 'string' ? url : [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }] - ), - }); - } - public createJob = async ( { relativeUrls, ...jobParams }: JobParamsPDFDeprecated // relativeUrls does not belong in the payload of PDFV1 ) => { @@ -110,8 +98,10 @@ export class PdfV1ExportType extends ExportType - this.getScreenshots({ + const snapshotFn = () => { + if (!this.startDeps.screenshotting) + throw new Error('Screenshotting plugin is not initialized'); + return this.startDeps.screenshotting.getScreenshots({ format: 'pdf', title, logo, @@ -120,6 +110,7 @@ export class PdfV1ExportType extends ExportType { @@ -72,16 +70,6 @@ export class PdfExportType extends ExportType }; }; - public getScreenshots(options: PdfScreenshotOptions): Observable { - if (!this.startDeps.screenshotting) throw new Error('Screenshotting plugin is not initialized'); - return this.startDeps.screenshotting.getScreenshots({ - ...options, - urls: options?.urls?.map((url) => - typeof url === 'string' ? url : [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }] - ), - }); - } - /** * * @param jobId @@ -129,8 +117,10 @@ export class PdfExportType extends ExportType return generatePdfObservableV2( this.config, this.getServerInfo(), - () => - this.getScreenshots({ + () => { + if (!this.startDeps.screenshotting) + throw new Error('Screenshotting plugin is not initialized'); + return this.startDeps.screenshotting.getScreenshots({ format: 'pdf', title, logo, @@ -138,7 +128,8 @@ export class PdfExportType extends ExportType headers, layout, urls, - }), + }); + }, payload, locatorParams, { diff --git a/packages/kbn-reporting/export_types/png/png_v2.ts b/packages/kbn-reporting/export_types/png/png_v2.ts index 2aec87a1fdc0a..e8fb333f7672d 100644 --- a/packages/kbn-reporting/export_types/png/png_v2.ts +++ b/packages/kbn-reporting/export_types/png/png_v2.ts @@ -28,7 +28,6 @@ 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'; @@ -44,7 +43,6 @@ import { ExportType, generatePngObservable, } from '@kbn/reporting-server'; -import type { PngScreenshotOptions, PngScreenshotResult } from '@kbn/screenshotting-plugin/server'; import type { Context } from '@kbn/screenshotting-plugin/server/browsers'; import { SerializableRecord } from '@kbn/utility-types'; @@ -67,16 +65,6 @@ export class PngExportType extends ExportType this.logger = this.logger.get('png-export-v2'); } - public getScreenshots(options: PngScreenshotOptions): Observable { - if (!this.startDeps.screenshotting) throw new Error('Screenshotting plugin is not initialized'); - return this.startDeps.screenshotting.getScreenshots({ - ...options, - urls: options?.urls?.map((url) => - typeof url === 'string' ? url : [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }] - ), - }); - } - /** * @params JobParamsPNGV2 * @returns jobParams @@ -126,13 +114,17 @@ export class PngExportType extends ExportType apmGeneratePng = apmTrans.startSpan('generate-png-pipeline', 'execute'); return generatePngObservable( - () => - this.getScreenshots({ + () => { + if (!this.startDeps.screenshotting) + throw new Error('Screenshotting plugin is not initialized'); + + return this.startDeps.screenshotting.getScreenshots({ format: 'png', headers, layout: { ...payload.layout, id: 'preserve_layout' }, urls: [[url, locatorParams]], - }), + }); + }, jobLogger, { headers, diff --git a/x-pack/plugins/reporting/server/core.ts b/x-pack/plugins/reporting/server/core.ts index 03d6a1138e385..e21f25821b20d 100644 --- a/x-pack/plugins/reporting/server/core.ts +++ b/x-pack/plugins/reporting/server/core.ts @@ -6,7 +6,7 @@ */ import * as Rx from 'rxjs'; -import { map, switchMap, take } from 'rxjs/operators'; +import { map, take } from 'rxjs/operators'; import type { CoreSetup, @@ -26,7 +26,6 @@ import type { DiscoverServerPluginStart } from '@kbn/discover-plugin/server'; import type { PluginSetupContract as FeaturesPluginSetup } from '@kbn/features-plugin/server'; import type { FieldFormatsStart } from '@kbn/field-formats-plugin/server'; import type { LicensingPluginStart } from '@kbn/licensing-plugin/server'; -import { REPORTING_REDIRECT_LOCATOR_STORE_KEY } from '@kbn/reporting-common'; import type { ReportingServerInfo } from '@kbn/reporting-common/types'; import { CsvSearchSourceExportType, @@ -37,12 +36,7 @@ import { PdfExportType, PdfV1ExportType } from '@kbn/reporting-export-types-pdf' import { PngExportType } from '@kbn/reporting-export-types-png'; import type { ReportingConfigType } from '@kbn/reporting-server'; import { ExportType } from '@kbn/reporting-server'; -import { - PdfScreenshotResult, - PngScreenshotResult, - ScreenshotOptions, - ScreenshottingStart, -} from '@kbn/screenshotting-plugin/server'; +import { ScreenshottingStart } from '@kbn/screenshotting-plugin/server'; import type { SecurityPluginSetup, SecurityPluginStart } from '@kbn/security-plugin/server'; import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common'; import type { SpacesPluginSetup } from '@kbn/spaces-plugin/server'; @@ -58,7 +52,7 @@ import { ExportTypesRegistry, checkLicense } from './lib'; import { reportingEventLoggerFactory } from './lib/event_logger/logger'; import type { IReport, ReportingStore } from './lib/store'; import { ExecuteReportTask, MonitorReportsTask, ReportTaskParams } from './lib/tasks'; -import type { PdfScreenshotOptions, PngScreenshotOptions, ReportingPluginRouter } from './types'; +import type { ReportingPluginRouter } from './types'; export interface ReportingInternalSetup { basePath: Pick; @@ -127,7 +121,6 @@ export class ReportingCore { this.getContract = () => ({ usesUiCapabilities: () => config.roles.enabled === false, registerExportTypes: (id) => id, - getScreenshots: config.statefulSettings.enabled ? this.getScreenshots.bind(this) : undefined, getSpaceId: this.getSpaceId.bind(this), }); @@ -394,25 +387,6 @@ export class ReportingCore { } } - public getScreenshots(options: PdfScreenshotOptions): Rx.Observable; - public getScreenshots(options: PngScreenshotOptions): Rx.Observable; - public getScreenshots( - options: PngScreenshotOptions | PdfScreenshotOptions - ): Rx.Observable { - return Rx.defer(() => this.getPluginStartDeps()).pipe( - switchMap(({ screenshotting }) => { - return screenshotting!.getScreenshots({ - ...options, - urls: options.urls.map((url) => - typeof url === 'string' - ? url - : [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }] - ), - } as ScreenshotOptions); - }) - ); - } - public trackReport(reportId: string) { this.executing.add(reportId); } diff --git a/x-pack/plugins/reporting/server/lib/store/store.test.ts b/x-pack/plugins/reporting/server/lib/store/store.test.ts index bc872c7de5d7b..18fea1349373e 100644 --- a/x-pack/plugins/reporting/server/lib/store/store.test.ts +++ b/x-pack/plugins/reporting/server/lib/store/store.test.ts @@ -6,6 +6,7 @@ */ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks'; +import { JOB_STATUS } from '@kbn/reporting-common'; import { ReportDocument } from '@kbn/reporting-common/types'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; import { Report, ReportingStore, SavedReport } from '.'; @@ -186,7 +187,7 @@ describe('ReportingStore', () => { created_at: 'some time', created_by: 'some security person', jobtype: 'csv_searchsource', - status: 'pending', + status: JOB_STATUS.PENDING, meta: { testMeta: 'meta' } as any, payload: { testPayload: 'payload' } as any, attempts: 0, @@ -393,7 +394,7 @@ describe('ReportingStore', () => { _primary_term: 10002, jobtype: 'test-report-2', created_by: 'created_by_test_string', - status: 'processing', + status: JOB_STATUS.PROCESSING, process_expiration: '2002', max_attempts: 3, payload: { diff --git a/x-pack/plugins/reporting/server/types.ts b/x-pack/plugins/reporting/server/types.ts index 8acfaeb8dd41b..eb144dda1e476 100644 --- a/x-pack/plugins/reporting/server/types.ts +++ b/x-pack/plugins/reporting/server/types.ts @@ -33,7 +33,6 @@ import type { } from '@kbn/task-manager-plugin/server'; import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server'; -import { ReportingCore } from './core'; import { ExportTypesRegistry } from './lib'; /** @@ -41,7 +40,6 @@ import { ExportTypesRegistry } from './lib'; */ export interface ReportingSetup { registerExportTypes: ExportTypesRegistry['register']; - getScreenshots?: ReportingCore['getScreenshots']; /** * Used to inform plugins if Reporting config is compatible with UI Capabilities / Application Sub-Feature Controls */ diff --git a/x-pack/test/reporting_api_integration/reporting_and_security/ilm_migration_apis.ts b/x-pack/test/reporting_api_integration/reporting_and_security/ilm_migration_apis.ts index 6f71974364942..172d415ff2695 100644 --- a/x-pack/test/reporting_api_integration/reporting_and_security/ilm_migration_apis.ts +++ b/x-pack/test/reporting_api_integration/reporting_and_security/ilm_migration_apis.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { ILM_POLICY_NAME } from '@kbn/reporting-plugin/common/constants'; +import { ILM_POLICY_NAME } from '@kbn/reporting-common/constants'; import { INTERNAL_ROUTES } from '@kbn/reporting-plugin/common/constants/routes'; import { FtrProviderContext } from '../ftr_provider_context'; From 4fe843aec95556b2d3b372e0914d3e4e7be37e6f Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 15:50:44 -0700 Subject: [PATCH 19/25] clean up getScreenshots --- .../export_types/pdf/deprecated.ts | 19 +++-------- .../export_types/pdf/printable_pdf_v2.ts | 23 ++++--------- .../kbn-reporting/export_types/png/png_v2.ts | 22 ++++--------- x-pack/plugins/reporting/server/core.ts | 32 ++----------------- .../reporting/server/lib/store/store.test.ts | 5 +-- x-pack/plugins/reporting/server/types.ts | 2 -- .../server/screenshots/screenshots.ts | 2 ++ .../ilm_migration_apis.ts | 2 +- 8 files changed, 28 insertions(+), 79 deletions(-) diff --git a/packages/kbn-reporting/export_types/pdf/deprecated.ts b/packages/kbn-reporting/export_types/pdf/deprecated.ts index 21f6d8881a60a..6c6aea003ba6a 100644 --- a/packages/kbn-reporting/export_types/pdf/deprecated.ts +++ b/packages/kbn-reporting/export_types/pdf/deprecated.ts @@ -19,7 +19,6 @@ import { LICENSE_TYPE_GOLD, LICENSE_TYPE_PLATINUM, LICENSE_TYPE_TRIAL, - REPORTING_REDIRECT_LOCATOR_STORE_KEY, REPORTING_TRANSACTION_TYPE, } from '@kbn/reporting-common'; import { TaskRunResult } from '@kbn/reporting-common/types'; @@ -36,7 +35,6 @@ import { getFullUrls, validateUrls, } from '@kbn/reporting-server'; -import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; /** * @deprecated @@ -60,16 +58,6 @@ export class PdfV1ExportType extends ExportType { - if (!this.startDeps.screenshotting) throw new Error('Screenshotting plugin is not initialized'); - return this.startDeps.screenshotting.getScreenshots({ - ...options, - urls: options?.urls?.map((url) => - typeof url === 'string' ? url : [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }] - ), - }); - } - public createJob = async ( { relativeUrls, ...jobParams }: JobParamsPDFDeprecated // relativeUrls does not belong in the payload of PDFV1 ) => { @@ -110,8 +98,10 @@ export class PdfV1ExportType extends ExportType - this.getScreenshots({ + const snapshotFn = () => { + if (!this.startDeps.screenshotting) + throw new Error('Screenshotting plugin is not initialized'); + return this.startDeps.screenshotting.getScreenshots({ format: 'pdf', title, logo, @@ -120,6 +110,7 @@ export class PdfV1ExportType extends ExportType { @@ -72,16 +70,6 @@ export class PdfExportType extends ExportType }; }; - public getScreenshots(options: PdfScreenshotOptions): Observable { - if (!this.startDeps.screenshotting) throw new Error('Screenshotting plugin is not initialized'); - return this.startDeps.screenshotting.getScreenshots({ - ...options, - urls: options?.urls?.map((url) => - typeof url === 'string' ? url : [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }] - ), - }); - } - /** * * @param jobId @@ -129,8 +117,10 @@ export class PdfExportType extends ExportType return generatePdfObservableV2( this.config, this.getServerInfo(), - () => - this.getScreenshots({ + () => { + if (!this.startDeps.screenshotting) + throw new Error('Screenshotting plugin is not initialized'); + return this.startDeps.screenshotting.getScreenshots({ format: 'pdf', title, logo, @@ -138,7 +128,8 @@ export class PdfExportType extends ExportType headers, layout, urls, - }), + }); + }, payload, locatorParams, { diff --git a/packages/kbn-reporting/export_types/png/png_v2.ts b/packages/kbn-reporting/export_types/png/png_v2.ts index 2aec87a1fdc0a..e8fb333f7672d 100644 --- a/packages/kbn-reporting/export_types/png/png_v2.ts +++ b/packages/kbn-reporting/export_types/png/png_v2.ts @@ -28,7 +28,6 @@ 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'; @@ -44,7 +43,6 @@ import { ExportType, generatePngObservable, } from '@kbn/reporting-server'; -import type { PngScreenshotOptions, PngScreenshotResult } from '@kbn/screenshotting-plugin/server'; import type { Context } from '@kbn/screenshotting-plugin/server/browsers'; import { SerializableRecord } from '@kbn/utility-types'; @@ -67,16 +65,6 @@ export class PngExportType extends ExportType this.logger = this.logger.get('png-export-v2'); } - public getScreenshots(options: PngScreenshotOptions): Observable { - if (!this.startDeps.screenshotting) throw new Error('Screenshotting plugin is not initialized'); - return this.startDeps.screenshotting.getScreenshots({ - ...options, - urls: options?.urls?.map((url) => - typeof url === 'string' ? url : [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }] - ), - }); - } - /** * @params JobParamsPNGV2 * @returns jobParams @@ -126,13 +114,17 @@ export class PngExportType extends ExportType apmGeneratePng = apmTrans.startSpan('generate-png-pipeline', 'execute'); return generatePngObservable( - () => - this.getScreenshots({ + () => { + if (!this.startDeps.screenshotting) + throw new Error('Screenshotting plugin is not initialized'); + + return this.startDeps.screenshotting.getScreenshots({ format: 'png', headers, layout: { ...payload.layout, id: 'preserve_layout' }, urls: [[url, locatorParams]], - }), + }); + }, jobLogger, { headers, diff --git a/x-pack/plugins/reporting/server/core.ts b/x-pack/plugins/reporting/server/core.ts index 03d6a1138e385..e21f25821b20d 100644 --- a/x-pack/plugins/reporting/server/core.ts +++ b/x-pack/plugins/reporting/server/core.ts @@ -6,7 +6,7 @@ */ import * as Rx from 'rxjs'; -import { map, switchMap, take } from 'rxjs/operators'; +import { map, take } from 'rxjs/operators'; import type { CoreSetup, @@ -26,7 +26,6 @@ import type { DiscoverServerPluginStart } from '@kbn/discover-plugin/server'; import type { PluginSetupContract as FeaturesPluginSetup } from '@kbn/features-plugin/server'; import type { FieldFormatsStart } from '@kbn/field-formats-plugin/server'; import type { LicensingPluginStart } from '@kbn/licensing-plugin/server'; -import { REPORTING_REDIRECT_LOCATOR_STORE_KEY } from '@kbn/reporting-common'; import type { ReportingServerInfo } from '@kbn/reporting-common/types'; import { CsvSearchSourceExportType, @@ -37,12 +36,7 @@ import { PdfExportType, PdfV1ExportType } from '@kbn/reporting-export-types-pdf' import { PngExportType } from '@kbn/reporting-export-types-png'; import type { ReportingConfigType } from '@kbn/reporting-server'; import { ExportType } from '@kbn/reporting-server'; -import { - PdfScreenshotResult, - PngScreenshotResult, - ScreenshotOptions, - ScreenshottingStart, -} from '@kbn/screenshotting-plugin/server'; +import { ScreenshottingStart } from '@kbn/screenshotting-plugin/server'; import type { SecurityPluginSetup, SecurityPluginStart } from '@kbn/security-plugin/server'; import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common'; import type { SpacesPluginSetup } from '@kbn/spaces-plugin/server'; @@ -58,7 +52,7 @@ import { ExportTypesRegistry, checkLicense } from './lib'; import { reportingEventLoggerFactory } from './lib/event_logger/logger'; import type { IReport, ReportingStore } from './lib/store'; import { ExecuteReportTask, MonitorReportsTask, ReportTaskParams } from './lib/tasks'; -import type { PdfScreenshotOptions, PngScreenshotOptions, ReportingPluginRouter } from './types'; +import type { ReportingPluginRouter } from './types'; export interface ReportingInternalSetup { basePath: Pick; @@ -127,7 +121,6 @@ export class ReportingCore { this.getContract = () => ({ usesUiCapabilities: () => config.roles.enabled === false, registerExportTypes: (id) => id, - getScreenshots: config.statefulSettings.enabled ? this.getScreenshots.bind(this) : undefined, getSpaceId: this.getSpaceId.bind(this), }); @@ -394,25 +387,6 @@ export class ReportingCore { } } - public getScreenshots(options: PdfScreenshotOptions): Rx.Observable; - public getScreenshots(options: PngScreenshotOptions): Rx.Observable; - public getScreenshots( - options: PngScreenshotOptions | PdfScreenshotOptions - ): Rx.Observable { - return Rx.defer(() => this.getPluginStartDeps()).pipe( - switchMap(({ screenshotting }) => { - return screenshotting!.getScreenshots({ - ...options, - urls: options.urls.map((url) => - typeof url === 'string' - ? url - : [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }] - ), - } as ScreenshotOptions); - }) - ); - } - public trackReport(reportId: string) { this.executing.add(reportId); } diff --git a/x-pack/plugins/reporting/server/lib/store/store.test.ts b/x-pack/plugins/reporting/server/lib/store/store.test.ts index bc872c7de5d7b..18fea1349373e 100644 --- a/x-pack/plugins/reporting/server/lib/store/store.test.ts +++ b/x-pack/plugins/reporting/server/lib/store/store.test.ts @@ -6,6 +6,7 @@ */ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks'; +import { JOB_STATUS } from '@kbn/reporting-common'; import { ReportDocument } from '@kbn/reporting-common/types'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; import { Report, ReportingStore, SavedReport } from '.'; @@ -186,7 +187,7 @@ describe('ReportingStore', () => { created_at: 'some time', created_by: 'some security person', jobtype: 'csv_searchsource', - status: 'pending', + status: JOB_STATUS.PENDING, meta: { testMeta: 'meta' } as any, payload: { testPayload: 'payload' } as any, attempts: 0, @@ -393,7 +394,7 @@ describe('ReportingStore', () => { _primary_term: 10002, jobtype: 'test-report-2', created_by: 'created_by_test_string', - status: 'processing', + status: JOB_STATUS.PROCESSING, process_expiration: '2002', max_attempts: 3, payload: { diff --git a/x-pack/plugins/reporting/server/types.ts b/x-pack/plugins/reporting/server/types.ts index 8acfaeb8dd41b..eb144dda1e476 100644 --- a/x-pack/plugins/reporting/server/types.ts +++ b/x-pack/plugins/reporting/server/types.ts @@ -33,7 +33,6 @@ import type { } from '@kbn/task-manager-plugin/server'; import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server'; -import { ReportingCore } from './core'; import { ExportTypesRegistry } from './lib'; /** @@ -41,7 +40,6 @@ import { ExportTypesRegistry } from './lib'; */ export interface ReportingSetup { registerExportTypes: ExportTypesRegistry['register']; - getScreenshots?: ReportingCore['getScreenshots']; /** * Used to inform plugins if Reporting config is compatible with UI Capabilities / Application Sub-Feature Controls */ diff --git a/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts b/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts index 64f6ecdb5264a..5ee41f9fa77fe 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts @@ -174,6 +174,8 @@ export class Screenshots { getScreenshots(options: PdfScreenshotOptions): Observable; getScreenshots(options: ScreenshotOptions): Observable; getScreenshots(options: ScreenshotOptions): Observable { + console.log('urls', JSON.stringify({ urls: options.urls})); + if (this.systemHasInsufficientMemory()) { return throwError(() => new errors.InsufficientMemoryAvailableOnCloudError()); } diff --git a/x-pack/test/reporting_api_integration/reporting_and_security/ilm_migration_apis.ts b/x-pack/test/reporting_api_integration/reporting_and_security/ilm_migration_apis.ts index 6f71974364942..172d415ff2695 100644 --- a/x-pack/test/reporting_api_integration/reporting_and_security/ilm_migration_apis.ts +++ b/x-pack/test/reporting_api_integration/reporting_and_security/ilm_migration_apis.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { ILM_POLICY_NAME } from '@kbn/reporting-plugin/common/constants'; +import { ILM_POLICY_NAME } from '@kbn/reporting-common/constants'; import { INTERNAL_ROUTES } from '@kbn/reporting-plugin/common/constants/routes'; import { FtrProviderContext } from '../ftr_provider_context'; From acfcad3a96b1375e8b5f6fba923ef83e1d511d05 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 17:10:43 -0700 Subject: [PATCH 20/25] Consolidate getScreenshots and generateScreenshotObservable --- .../export_types/pdf/deprecated.ts | 10 ++++------ .../pdf}/generate_pdf.ts | 0 .../pdf}/generate_pdf_v2.ts | 4 +--- .../pdf}/pdf_tracker.ts | 0 .../export_types/pdf/printable_pdf_v2.ts | 19 ++++++++----------- .../png}/generate_png.ts | 0 .../kbn-reporting/export_types/png/png_v2.ts | 19 ++++++------------- packages/kbn-reporting/server/index.ts | 4 ---- 8 files changed, 19 insertions(+), 37 deletions(-) rename packages/kbn-reporting/{server => export_types/pdf}/generate_pdf.ts (100%) rename packages/kbn-reporting/{server => export_types/pdf}/generate_pdf_v2.ts (96%) rename packages/kbn-reporting/{server => export_types/pdf}/pdf_tracker.ts (100%) rename packages/kbn-reporting/{server => export_types/png}/generate_png.ts (100%) diff --git a/packages/kbn-reporting/export_types/pdf/deprecated.ts b/packages/kbn-reporting/export_types/pdf/deprecated.ts index 6c6aea003ba6a..f173baa927c07 100644 --- a/packages/kbn-reporting/export_types/pdf/deprecated.ts +++ b/packages/kbn-reporting/export_types/pdf/deprecated.ts @@ -30,12 +30,13 @@ import { import { ExportType, decryptJobHeaders, - generatePdfObservable, getCustomLogo, getFullUrls, validateUrls, } from '@kbn/reporting-server'; +import { generatePdfObservable } from './generate_pdf'; + /** * @deprecated */ @@ -98,10 +99,8 @@ export class PdfV1ExportType extends ExportType { - if (!this.startDeps.screenshotting) - throw new Error('Screenshotting plugin is not initialized'); - return this.startDeps.screenshotting.getScreenshots({ + const snapshotFn = () => + this.startDeps.screenshotting!.getScreenshots({ format: 'pdf', title, logo, @@ -110,7 +109,6 @@ export class PdfV1ExportType extends ExportType { id = PDF_REPORT_TYPE_V2; @@ -98,7 +98,7 @@ export class PdfExportType extends ExportType }), mergeMap(({ logo, headers }) => { const { browserTimezone, layout, title, locatorParams } = payload; - let urls: UrlOrUrlWithContext[]; + let urls: UrlOrUrlLocatorTuple[]; if (locatorParams) { urls = locatorParams.map((locator) => [ getFullRedirectAppUrl( @@ -108,7 +108,7 @@ export class PdfExportType extends ExportType payload.forceNow ), locator, - ]) as unknown as UrlOrUrlWithContext[]; + ]) as unknown as UrlOrUrlLocatorTuple[]; } apmGetAssets?.end(); @@ -117,10 +117,8 @@ export class PdfExportType extends ExportType return generatePdfObservableV2( this.config, this.getServerInfo(), - () => { - if (!this.startDeps.screenshotting) - throw new Error('Screenshotting plugin is not initialized'); - return this.startDeps.screenshotting.getScreenshots({ + () => + this.startDeps.screenshotting!.getScreenshots({ format: 'pdf', title, logo, @@ -128,8 +126,7 @@ export class PdfExportType extends ExportType headers, layout, urls, - }); - }, + }), payload, locatorParams, { diff --git a/packages/kbn-reporting/server/generate_png.ts b/packages/kbn-reporting/export_types/png/generate_png.ts similarity index 100% rename from packages/kbn-reporting/server/generate_png.ts rename to packages/kbn-reporting/export_types/png/generate_png.ts diff --git a/packages/kbn-reporting/export_types/png/png_v2.ts b/packages/kbn-reporting/export_types/png/png_v2.ts index e8fb333f7672d..cff0fcf23afca 100644 --- a/packages/kbn-reporting/export_types/png/png_v2.ts +++ b/packages/kbn-reporting/export_types/png/png_v2.ts @@ -37,15 +37,12 @@ import { PNG_REPORT_TYPE_V2, TaskPayloadPNGV2, } from '@kbn/reporting-export-types-png-common'; -import { - decryptJobHeaders, - getFullRedirectAppUrl, - ExportType, - generatePngObservable, -} from '@kbn/reporting-server'; +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'; + export class PngExportType extends ExportType { id = PNG_REPORT_TYPE_V2; name = 'PNG'; @@ -114,17 +111,13 @@ export class PngExportType extends ExportType apmGeneratePng = apmTrans.startSpan('generate-png-pipeline', 'execute'); return generatePngObservable( - () => { - if (!this.startDeps.screenshotting) - throw new Error('Screenshotting plugin is not initialized'); - - return this.startDeps.screenshotting.getScreenshots({ + () => + this.startDeps.screenshotting!.getScreenshots({ format: 'png', headers, layout: { ...payload.layout, id: 'preserve_layout' }, urls: [[url, locatorParams]], - }); - }, + }), jobLogger, { headers, diff --git a/packages/kbn-reporting/server/index.ts b/packages/kbn-reporting/server/index.ts index 407eae4d8ce1e..45a559b51d5ee 100644 --- a/packages/kbn-reporting/server/index.ts +++ b/packages/kbn-reporting/server/index.ts @@ -9,14 +9,10 @@ export { cryptoFactory } from './crypto'; export { decryptJobHeaders } from './decrypt_job_headers'; export { ExportType } from './export_type'; -export { generatePdfObservable } from './generate_pdf'; -export { generatePdfObservableV2 } from './generate_pdf_v2'; -export { generatePngObservable } from './generate_png'; export { getAbsoluteUrlFactory } from './get_absolute_url'; export { getCustomLogo } from './get_custom_logo'; export { getFullRedirectAppUrl } from './get_full_redirect_app_url'; export { getFullUrls } from './get_full_urls'; -export { getTracker } from './pdf_tracker'; export { getFieldFormats, setFieldFormats } from './services'; export { validateUrls } from './validate_urls'; From 19d789f7b7673b2c4e5e52ca69b0d92747d344b7 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 17:14:36 -0700 Subject: [PATCH 21/25] Fix screenshotting --- .../export_types/pdf/generate_pdf_v2.ts | 1 + .../kbn-reporting/export_types/pdf/index.ts | 2 +- .../pdf/{deprecated.ts => printable_pdf.ts} | 3 +- .../export_types/pdf/printable_pdf_v2.ts | 27 ++++++++++------- .../kbn-reporting/export_types/png/png_v2.ts | 29 +++++++++---------- .../server/screenshots/screenshots.ts | 2 -- 6 files changed, 34 insertions(+), 30 deletions(-) rename packages/kbn-reporting/export_types/pdf/{deprecated.ts => printable_pdf.ts} (98%) diff --git a/packages/kbn-reporting/export_types/pdf/generate_pdf_v2.ts b/packages/kbn-reporting/export_types/pdf/generate_pdf_v2.ts index e569a998ebdf5..54489c6258bd8 100644 --- a/packages/kbn-reporting/export_types/pdf/generate_pdf_v2.ts +++ b/packages/kbn-reporting/export_types/pdf/generate_pdf_v2.ts @@ -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) { diff --git a/packages/kbn-reporting/export_types/pdf/index.ts b/packages/kbn-reporting/export_types/pdf/index.ts index efc80348480b6..e4ce328f9026e 100644 --- a/packages/kbn-reporting/export_types/pdf/index.ts +++ b/packages/kbn-reporting/export_types/pdf/index.ts @@ -7,4 +7,4 @@ */ export { PdfExportType } from './printable_pdf_v2'; -export { PdfV1ExportType } from './deprecated'; +export { PdfV1ExportType } from './printable_pdf'; diff --git a/packages/kbn-reporting/export_types/pdf/deprecated.ts b/packages/kbn-reporting/export_types/pdf/printable_pdf.ts similarity index 98% rename from packages/kbn-reporting/export_types/pdf/deprecated.ts rename to packages/kbn-reporting/export_types/pdf/printable_pdf.ts index f173baa927c07..59868962c0606 100644 --- a/packages/kbn-reporting/export_types/pdf/deprecated.ts +++ b/packages/kbn-reporting/export_types/pdf/printable_pdf.ts @@ -98,7 +98,7 @@ export class PdfV1ExportType extends ExportType this.startDeps.screenshotting!.getScreenshots({ format: 'pdf', @@ -109,6 +109,7 @@ export class PdfV1ExportType extends ExportType 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, { diff --git a/packages/kbn-reporting/export_types/png/png_v2.ts b/packages/kbn-reporting/export_types/png/png_v2.ts index cff0fcf23afca..13f26be0ea243 100644 --- a/packages/kbn-reporting/export_types/png/png_v2.ts +++ b/packages/kbn-reporting/export_types/png/png_v2.ts @@ -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'; @@ -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'; @@ -105,27 +105,24 @@ export class PngExportType extends ExportType 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 }) => ({ diff --git a/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts b/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts index 5ee41f9fa77fe..64f6ecdb5264a 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts @@ -174,8 +174,6 @@ export class Screenshots { getScreenshots(options: PdfScreenshotOptions): Observable; getScreenshots(options: ScreenshotOptions): Observable; getScreenshots(options: ScreenshotOptions): Observable { - console.log('urls', JSON.stringify({ urls: options.urls})); - if (this.systemHasInsufficientMemory()) { return throwError(() => new errors.InsufficientMemoryAvailableOnCloudError()); } From 59ea16c0c9725fbe93bf266d488b0fe4d5266012 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 14 Nov 2023 00:49:59 +0000 Subject: [PATCH 22/25] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- packages/kbn-reporting/export_types/png/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kbn-reporting/export_types/png/tsconfig.json b/packages/kbn-reporting/export_types/png/tsconfig.json index eea9041934e26..67535a2bb6f76 100644 --- a/packages/kbn-reporting/export_types/png/tsconfig.json +++ b/packages/kbn-reporting/export_types/png/tsconfig.json @@ -24,5 +24,6 @@ "@kbn/reporting-export-types-png-common", "@kbn/core", "@kbn/reporting-mocks-server", + "@kbn/logging", ] } From 04f9d5efd394991326b803bd647e75b3e5c571a0 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 17:57:39 -0700 Subject: [PATCH 23/25] Fix css --- .../csv/csv_searchsource_immediate.ts | 13 +++---------- .../kbn-reporting/export_types/csv/csv_v2.ts | 5 ++++- .../kbn-reporting/export_types/csv/types.ts | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 packages/kbn-reporting/export_types/csv/types.ts diff --git a/packages/kbn-reporting/export_types/csv/csv_searchsource_immediate.ts b/packages/kbn-reporting/export_types/csv/csv_searchsource_immediate.ts index a167b728f5e5f..ed690935d4582 100644 --- a/packages/kbn-reporting/export_types/csv/csv_searchsource_immediate.ts +++ b/packages/kbn-reporting/export_types/csv/csv_searchsource_immediate.ts @@ -8,7 +8,6 @@ import { Writable } from 'stream'; -import { CustomRequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; import { KibanaRequest } from '@kbn/core-http-server'; import { DataPluginStart } from '@kbn/data-plugin/server/plugin'; import { DiscoverServerPluginStart } from '@kbn/discover-plugin/server'; @@ -27,23 +26,17 @@ import { CSV_SEARCHSOURCE_IMMEDIATE_TYPE, JobParamsDownloadCSV, } from '@kbn/reporting-export-types-csv-common'; -import type { - BaseExportTypeSetupDeps, - BaseExportTypeStartDeps, - ReportingServerPluginSetup, -} from '@kbn/reporting-server'; +import type { BaseExportTypeSetupDeps, BaseExportTypeStartDeps } from '@kbn/reporting-server'; import { ExportType, getFieldFormats } from '@kbn/reporting-server'; +import { ReportingRequestHandlerContext } from './types'; + type CsvSearchSourceImmediateExportTypeSetupDeps = BaseExportTypeSetupDeps; interface CsvSearchSourceImmediateExportTypeStartDeps extends BaseExportTypeStartDeps { discover: DiscoverServerPluginStart; data: DataPluginStart; } -type ReportingRequestHandlerContext = CustomRequestHandlerContext<{ - reporting: ReportingServerPluginSetup | null; -}>; - /* * ImmediateExecuteFn receives the job doc payload because the payload was * generated in the ScheduleFn diff --git a/packages/kbn-reporting/export_types/csv/csv_v2.ts b/packages/kbn-reporting/export_types/csv/csv_v2.ts index bec3c4ff63e3a..9ef87011ba6dc 100644 --- a/packages/kbn-reporting/export_types/csv/csv_v2.ts +++ b/packages/kbn-reporting/export_types/csv/csv_v2.ts @@ -35,7 +35,10 @@ import { type BaseExportTypeStartDeps, } from '@kbn/reporting-server'; +import { ReportingRequestHandlerContext } from './types'; + type CsvV2ExportTypeSetupDeps = BaseExportTypeSetupDeps; + export interface CsvV2ExportTypeStartDeps extends BaseExportTypeStartDeps { discover: DiscoverServerPluginStart; data: DataPluginStart; @@ -68,7 +71,7 @@ export class CsvV2ExportType extends ExportType< public createJob = async ( jobParams: JobParamsCsvFromSavedObject, - _context: unknown, + _context: ReportingRequestHandlerContext, req: KibanaRequest ) => { // 1. Validation of locatorParams diff --git a/packages/kbn-reporting/export_types/csv/types.ts b/packages/kbn-reporting/export_types/csv/types.ts new file mode 100644 index 0000000000000..7d06b67f61381 --- /dev/null +++ b/packages/kbn-reporting/export_types/csv/types.ts @@ -0,0 +1,18 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import type { CustomRequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; +import { ReportingServerPluginSetup } from '@kbn/reporting-server'; + +/** + * Needed because of CsvSearchSourceImmediateExportType + * @internal + */ +export type ReportingRequestHandlerContext = CustomRequestHandlerContext<{ + reporting: ReportingServerPluginSetup | null; +}>; From 7833d715cf34bf37793c6df6f4d01ef681b8cacf Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 18:07:27 -0700 Subject: [PATCH 24/25] polish --- .../export_types/pdf/printable_pdf.ts | 27 ++-- .../export_types/pdf/printable_pdf_v2.ts | 29 ++-- .../kbn-reporting/export_types/png/png_v2.ts | 24 ++-- .../server/config_schema.test.ts | 134 ++++++++++++++++++ x-pack/plugins/reporting/server/core.ts | 2 +- 5 files changed, 176 insertions(+), 40 deletions(-) create mode 100644 packages/kbn-reporting/server/config_schema.test.ts diff --git a/packages/kbn-reporting/export_types/pdf/printable_pdf.ts b/packages/kbn-reporting/export_types/pdf/printable_pdf.ts index 59868962c0606..cdc3635d397f3 100644 --- a/packages/kbn-reporting/export_types/pdf/printable_pdf.ts +++ b/packages/kbn-reporting/export_types/pdf/printable_pdf.ts @@ -99,8 +99,18 @@ export class PdfV1ExportType extends ExportType - this.startDeps.screenshotting!.getScreenshots({ + return generatePdfObservable( + () => + this.startDeps.screenshotting!.getScreenshots({ + format: 'pdf', + title, + logo, + urls, + browserTimezone, + headers, + layout, + }), + { format: 'pdf', title, logo, @@ -108,17 +118,8 @@ export class PdfV1ExportType extends ExportType { apmGeneratePdf?.end(); diff --git a/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.ts b/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.ts index a589dfbbc72e6..5e533d1fe94e9 100644 --- a/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.ts +++ b/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.ts @@ -116,24 +116,23 @@ export class PdfExportType extends ExportType 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(), - 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] }] + ), + }), payload, locatorParams, { diff --git a/packages/kbn-reporting/export_types/png/png_v2.ts b/packages/kbn-reporting/export_types/png/png_v2.ts index 13f26be0ea243..7b8c10af767b9 100644 --- a/packages/kbn-reporting/export_types/png/png_v2.ts +++ b/packages/kbn-reporting/export_types/png/png_v2.ts @@ -110,19 +110,21 @@ export class PngExportType extends ExportType apmGetAssets?.end(); apmGeneratePng = apmTrans.startSpan('generate-png-pipeline', 'execute'); - const snapshotFn = () => - this.startDeps.screenshotting!.getScreenshots({ - format: 'png', + return generatePngObservable( + () => + this.startDeps.screenshotting!.getScreenshots({ + format: 'png', + headers, + layout: { ...payload.layout, id: 'preserve_layout' }, + urls: [[url, { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: locatorParams }]], + }), + jobLogger, + { headers, + browserTimezone: payload.browserTimezone, layout: { ...payload.layout, id: 'preserve_layout' }, - 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 }) => ({ diff --git a/packages/kbn-reporting/server/config_schema.test.ts b/packages/kbn-reporting/server/config_schema.test.ts new file mode 100644 index 0000000000000..069218e988019 --- /dev/null +++ b/packages/kbn-reporting/server/config_schema.test.ts @@ -0,0 +1,134 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ConfigSchema } from './config_schema'; + +describe('Reporting Config Schema', () => { + it(`context {"dev":false,"dist":false} produces correct config`, () => { + expect(ConfigSchema.validate({}, { dev: false, dist: false })).toMatchSnapshot(); + }); + + it(`context {"dev":false,"dist":true} produces correct config`, () => { + expect(ConfigSchema.validate({}, { dev: false, dist: true })).toMatchSnapshot(); + }); + + it('allows ByteSizeValue values for certain keys', () => { + expect(ConfigSchema.validate({ csv: { maxSizeBytes: '12mb' } }).csv.maxSizeBytes) + .toMatchInlineSnapshot(` + ByteSizeValue { + "valueInBytes": 12582912, + } + `); + }); + + it(`allows optional settings`, () => { + // encryption key + expect( + ConfigSchema.validate({ encryptionKey: 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq' }) + .encryptionKey + ).toBe('qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'); + + expect(ConfigSchema.validate({ encryptionKey: 'weaksauce' }).encryptionKey).toBe('weaksauce'); + // kibanaServer + expect( + ConfigSchema.validate({ kibanaServer: { hostname: 'Frodo' } }).kibanaServer + ).toMatchObject({ hostname: 'Frodo' }); + }); + + it.each(['0', '0.0', '0.0.0'])( + `fails to validate "kibanaServer.hostname" with an invalid hostname: "%s"`, + (address) => { + expect(() => + ConfigSchema.validate({ + kibanaServer: { hostname: address }, + }) + ).toThrowError(`[kibanaServer.hostname]: value must be a valid hostname (see RFC 1123).`); + } + ); + + it.each(['0.0.0.0', '0000:0000:0000:0000:0000:0000:0000:0000', '::'])( + `fails to validate "kibanaServer.hostname" hostname as zero: "%s"`, + (address) => { + expect(() => + ConfigSchema.validate({ + kibanaServer: { hostname: address }, + }) + ).toThrowError( + `[kibanaServer.hostname]: cannot use '0.0.0.0' as Kibana host name, consider using the default (localhost) instead` + ); + } + ); + + it('permits csv with serverless', () => { + expect(() => + ConfigSchema.validate({ export_types: { pdf: { enabled: true } } }, { dev: true }) + ).not.toThrow(); + }); + + it('enables all export types by default', () => { + expect(ConfigSchema.validate({}, { serverless: false }).export_types).toMatchInlineSnapshot(` + Object { + "csv": Object { + "enabled": true, + }, + "pdf": Object { + "enabled": true, + }, + "png": Object { + "enabled": true, + }, + } + `); + }); + + it('disables ilm settings in serverless', () => { + expect(ConfigSchema.validate({}, { serverless: true }).statefulSettings).toMatchInlineSnapshot(` + Object { + "enabled": false, + } + `); + }); + + it('disables screenshot type exports in serverless', () => { + expect(ConfigSchema.validate({}, { serverless: true }).export_types).toMatchInlineSnapshot(` + Object { + "csv": Object { + "enabled": true, + }, + "pdf": Object { + "enabled": false, + }, + "png": Object { + "enabled": false, + }, + } + `); + }); + + it('it should allow image reporting for any non-serverless config', () => { + expect(() => + ConfigSchema.validate({ export_types: { pdf: { enabled: true } } }, { dev: true }) + ).not.toThrow(); + expect(() => + ConfigSchema.validate({ export_types: { png: { enabled: true } } }, { dev: true }) + ).not.toThrow(); + expect(() => + ConfigSchema.validate({ export_types: { csv: { enabled: true } } }, { dev: true }) + ).not.toThrow(); + }); + + describe('roles', () => { + it('should have roles enabled set to false for serverless by default', () => { + expect(ConfigSchema.validate({}, { serverless: true }).roles.enabled).toBe(false); + }); + + it('should have roles enabled set to true for non-serverless by default', () => { + expect(ConfigSchema.validate({}).roles.enabled).toBe(true); + }); + }); +}); diff --git a/x-pack/plugins/reporting/server/core.ts b/x-pack/plugins/reporting/server/core.ts index e21f25821b20d..c4af9d15f8c4c 100644 --- a/x-pack/plugins/reporting/server/core.ts +++ b/x-pack/plugins/reporting/server/core.ts @@ -157,7 +157,7 @@ export class ReportingCore { this.pluginStartDeps = startDeps; // cache this.exportTypesRegistry.getAll().forEach((et) => { - return et.start({ ...startDeps }); + et.start({ ...startDeps }); }); const { taskManager } = startDeps; From 80bd0c43124642640f11e28ad8f75043f4cb11c1 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 13 Nov 2023 18:46:54 -0700 Subject: [PATCH 25/25] fix checks --- .../kbn-reporting/export_types/pdf/printable_pdf.test.ts | 5 +++-- .../kbn-reporting/export_types/pdf/printable_pdf_v2.test.ts | 5 +++-- packages/kbn-reporting/export_types/png/png_v2.test.ts | 5 +++-- x-pack/plugins/translations/translations/fr-FR.json | 3 --- x-pack/plugins/translations/translations/ja-JP.json | 3 --- x-pack/plugins/translations/translations/zh-CN.json | 3 --- 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/packages/kbn-reporting/export_types/pdf/printable_pdf.test.ts b/packages/kbn-reporting/export_types/pdf/printable_pdf.test.ts index 079ebf8f69688..f683da2e3508c 100644 --- a/packages/kbn-reporting/export_types/pdf/printable_pdf.test.ts +++ b/packages/kbn-reporting/export_types/pdf/printable_pdf.test.ts @@ -12,13 +12,14 @@ import { Writable } from 'stream'; import { coreMock, elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks'; import { CancellationToken } from '@kbn/reporting-common'; import { TaskPayloadPDF } from '@kbn/reporting-export-types-pdf-common'; -import { cryptoFactory, generatePdfObservable } from '@kbn/reporting-server'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; +import { cryptoFactory } from '@kbn/reporting-server'; import { ScreenshottingStart } from '@kbn/screenshotting-plugin/server'; import { PdfV1ExportType } from '.'; +import { generatePdfObservable } from './generate_pdf'; -jest.mock('@kbn/reporting-server/generate_pdf'); +jest.mock('./generate_pdf'); let content: string; let mockPdfExportType: PdfV1ExportType; diff --git a/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.test.ts b/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.test.ts index 4706542ac4284..c8d8c39456e4e 100644 --- a/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.test.ts +++ b/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.test.ts @@ -14,12 +14,13 @@ import { CancellationToken } from '@kbn/reporting-common'; import type { LocatorParams } from '@kbn/reporting-common/types'; import type { TaskPayloadPDFV2 } from '@kbn/reporting-export-types-pdf-common'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; -import { cryptoFactory, generatePdfObservableV2 } from '@kbn/reporting-server'; +import { cryptoFactory } from '@kbn/reporting-server'; import type { ScreenshottingStart } from '@kbn/screenshotting-plugin/server'; import { PdfExportType } from '.'; +import { generatePdfObservableV2 } from './generate_pdf_v2'; -jest.mock('@kbn/reporting-server/generate_pdf_v2'); +jest.mock('./generate_pdf_v2'); let content: string; let mockPdfExportType: PdfExportType; diff --git a/packages/kbn-reporting/export_types/png/png_v2.test.ts b/packages/kbn-reporting/export_types/png/png_v2.test.ts index 734e00a751ded..e1031e4170949 100644 --- a/packages/kbn-reporting/export_types/png/png_v2.test.ts +++ b/packages/kbn-reporting/export_types/png/png_v2.test.ts @@ -14,12 +14,13 @@ import { CancellationToken } from '@kbn/reporting-common'; import type { LocatorParams } from '@kbn/reporting-common/types'; import type { TaskPayloadPNGV2 } from '@kbn/reporting-export-types-png-common'; import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; -import { cryptoFactory, generatePngObservable } from '@kbn/reporting-server'; +import { cryptoFactory } from '@kbn/reporting-server'; import type { ScreenshottingStart } from '@kbn/screenshotting-plugin/server'; import { PngExportType } from '.'; +import { generatePngObservable } from './generate_png'; -jest.mock('@kbn/reporting-server/generate_png'); +jest.mock('./generate_png'); let content: string; let mockPngExportType: PngExportType; diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index 6d2ca1f4bd137..a7aafc4a0bda5 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -43328,9 +43328,6 @@ "observabilityAlertDetails.alertThresholdTimeRangeRect.detailsTooltip": "Seuil", "randomSampling.ui.sliderControl.accuracyLabel": "Précision", "randomSampling.ui.sliderControl.performanceLabel": "Performances", - "generateCsv.browserCouldNotLaunchErrorMessage": "Impossible de générer des captures d'écran, car le navigateur ne s’est pas lancé. Consultez les logs de serveur pour en savoir plus.", - "generateCsv.cloud.insufficientSystemMemoryError": "Impossible de générer ce rapport en raison d’un manque de mémoire.", - "generateCsv.pdfWorkerOutOfMemoryErrorMessage": "Impossible de générer un PDF en raison d’un manque de mémoire. Essayez de réduire la taille du PDF et relancez ce rapport.", "reporting.commonExportTypesHelpers.missingJobHeadersErrorMessage": "Les en-têtes de tâche sont manquants", "reporting.commonExportTypesHelpers.failedToDecryptReportJobDataErrorMessage": "Impossible de déchiffrer les données de la tâche de reporting. Veuillez vous assurer que {encryptionKey} est défini et générez à nouveau ce rapport. {err}", "reactPackages.mountPointPortal.errorMessage": "Erreur lors du rendu du contenu du portail.", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index ee16b8077ff6b..fdbdc223efbba 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -43318,9 +43318,6 @@ "observabilityAlertDetails.alertThresholdTimeRangeRect.detailsTooltip": "しきい値", "randomSampling.ui.sliderControl.accuracyLabel": "精度", "randomSampling.ui.sliderControl.performanceLabel": "パフォーマンス", - "generateCsv.browserCouldNotLaunchErrorMessage": "ブラウザーが起動していないため、スクリーンショットを生成できません。詳細については、サーバーログを参照してください。", - "generateCsv.cloud.insufficientSystemMemoryError": "メモリ不足のため、このレポートを生成できません。", - "generateCsv.pdfWorkerOutOfMemoryErrorMessage": "メモリ不足のため、PDFを生成できません。PDFのサイズを小さくして、このレポートを再試行してください。", "reporting.commonExportTypesHelpers.failedToDecryptReportJobDataErrorMessage": "レポートジョブデータの解読に失敗しました。{encryptionKey} が設定されていることを確認してこのレポートを再生成してください。{err}", "reporting.commonExportTypesHelpers.missingJobHeadersErrorMessage": "ジョブヘッダーがありません", "reactPackages.mountPointPortal.errorMessage": "ポータルコンテンツのレンダリングエラー", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 27b478edafcbc..b7d34037b477d 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -43312,9 +43312,6 @@ "observabilityAlertDetails.alertThresholdTimeRangeRect.detailsTooltip": "阈值", "randomSampling.ui.sliderControl.accuracyLabel": "准确性", "randomSampling.ui.sliderControl.performanceLabel": "性能", - "generateCsv.browserCouldNotLaunchErrorMessage": "无法生成屏幕截图,因为浏览器未启动。有关更多信息,请查看服务器日志。", - "generateCsv.cloud.insufficientSystemMemoryError": "由于内存不足,无法生成此报告。", - "generateCsv.pdfWorkerOutOfMemoryErrorMessage": "由于内存不足,无法生成 PDF。尝试生成更小的 PDF,然后重试此报告。", "reporting.commonExportTypesHelpers.missingJobHeadersErrorMessage": "作业标头缺失", "reporting.commonExportTypesHelpers.failedToDecryptReportJobDataErrorMessage": "无法解密报告作业数据。请确保已设置 {encryptionKey},然后重新生成此报告。{err}", "reactPackages.mountPointPortal.errorMessage": "呈现门户内容时出错",