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 diff --git a/package.json b/package.json index cfda249da8f10..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", @@ -604,6 +603,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-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..59e69e9989c8e 100644 --- a/packages/kbn-generate-csv/src/generate_csv.ts +++ b/packages/kbn-generate-csv/src/generate_csv.ts @@ -27,13 +27,13 @@ import { byteSizeValueToNumber, } from '@kbn/reporting-common'; import type { TaskRunResult } from '@kbn/reporting-common/types'; -import { ReportingConfigType } from '@kbn/reporting-config-server'; -import { JobParamsCSV } from '@kbn/reporting-export-types-csv-common'; +import type { ReportingConfigType } from '@kbn/reporting-server'; 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/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..faef6fdc60f87 100644 --- a/packages/kbn-generate-csv/src/get_export_settings.ts +++ b/packages/kbn-generate-csv/src/get_export_settings.ts @@ -6,10 +6,10 @@ * 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 { 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..51dbd54dda73e 100644 --- a/packages/kbn-generate-csv/tsconfig.json +++ b/packages/kbn-generate-csv/tsconfig.json @@ -24,7 +24,7 @@ "@kbn/config-schema", "@kbn/i18n", "@kbn/reporting-common", + "@kbn/reporting-server", "@kbn/reporting-export-types-csv-common", - "@kbn/reporting-config-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 52f8808f3e925..02926a53a14eb 100644 --- a/packages/kbn-reporting/common/constants.ts +++ b/packages/kbn-reporting/common/constants.ts @@ -8,7 +8,17 @@ export const PLUGIN_ID = 'reporting'; +export const ALLOWED_JOB_CONTENT_TYPES = [ + 'application/json', + 'application/pdf', + 'text/csv', + 'image/png', + 'text/plain', +]; + +// APM 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 +33,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 +47,32 @@ 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'; + +/* + * 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', + 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/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.`, }); } diff --git a/packages/kbn-reporting/common/types.ts b/packages/kbn-reporting/common/types.ts index 679ac59432571..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'; @@ -99,3 +100,86 @@ 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: JOB_STATUS; + + /* + * `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; +} + +/* + * 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/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(), }); }); 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_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/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/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; +}>; diff --git a/packages/kbn-reporting/server/generate_pdf.ts b/packages/kbn-reporting/export_types/pdf/generate_pdf.ts similarity index 100% rename from packages/kbn-reporting/server/generate_pdf.ts rename to packages/kbn-reporting/export_types/pdf/generate_pdf.ts diff --git a/packages/kbn-reporting/server/generate_pdf_v2.ts b/packages/kbn-reporting/export_types/pdf/generate_pdf_v2.ts similarity index 92% rename from packages/kbn-reporting/server/generate_pdf_v2.ts rename to packages/kbn-reporting/export_types/pdf/generate_pdf_v2.ts index af6b7b208723e..54489c6258bd8 100644 --- a/packages/kbn-reporting/server/generate_pdf_v2.ts +++ b/packages/kbn-reporting/export_types/pdf/generate_pdf_v2.ts @@ -10,11 +10,10 @@ 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 { getFullRedirectAppUrl } from '.'; +import { type ReportingConfigType, getFullRedirectAppUrl } from '@kbn/reporting-server'; import { getTracker } from './pdf_tracker'; @@ -44,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/png_common/jest.config.js b/packages/kbn-reporting/export_types/pdf/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/pdf/jest.config.js index ea305c905ed87..eb1d1bff052d0 100644 --- a/packages/kbn-reporting/export_types/png_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/png_common'], + roots: ['/packages/kbn-reporting/export_types/pdf'], }; diff --git a/packages/kbn-reporting/server/pdf_tracker.ts b/packages/kbn-reporting/export_types/pdf/pdf_tracker.ts similarity index 100% rename from packages/kbn-reporting/server/pdf_tracker.ts rename to packages/kbn-reporting/export_types/pdf/pdf_tracker.ts 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/deprecated.ts b/packages/kbn-reporting/export_types/pdf/printable_pdf.ts similarity index 80% rename from packages/kbn-reporting/export_types/pdf/deprecated.ts rename to packages/kbn-reporting/export_types/pdf/printable_pdf.ts index 21f6d8881a60a..cdc3635d397f3 100644 --- a/packages/kbn-reporting/export_types/pdf/deprecated.ts +++ b/packages/kbn-reporting/export_types/pdf/printable_pdf.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'; @@ -31,12 +30,12 @@ import { import { ExportType, decryptJobHeaders, - generatePdfObservable, getCustomLogo, getFullUrls, validateUrls, } from '@kbn/reporting-server'; -import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; + +import { generatePdfObservable } from './generate_pdf'; /** * @deprecated @@ -60,16 +59,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 ) => { @@ -109,9 +98,19 @@ export class PdfV1ExportType extends ExportType - this.getScreenshots({ + + return generatePdfObservable( + () => + this.startDeps.screenshotting!.getScreenshots({ + format: 'pdf', + title, + logo, + urls, + browserTimezone, + headers, + layout, + }), + { format: 'pdf', title, logo, @@ -119,16 +118,8 @@ export class PdfV1ExportType extends ExportType { apmGeneratePdf?.end(); 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/pdf/printable_pdf_v2.ts b/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.ts index 35204cf7368b6..5e533d1fe94e9 100644 --- a/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.ts +++ b/packages/kbn-reporting/export_types/pdf/printable_pdf_v2.ts @@ -8,7 +8,7 @@ import apm from 'elastic-apm-node'; import * as Rx from 'rxjs'; -import { catchError, map, mergeMap, Observable, of, takeUntil, tap } from 'rxjs'; +import { catchError, map, mergeMap, of, takeUntil, tap } from 'rxjs'; import { Writable } from 'stream'; import { Headers } from '@kbn/core/server'; @@ -22,7 +22,7 @@ import { REPORTING_REDIRECT_LOCATOR_STORE_KEY, REPORTING_TRANSACTION_TYPE, } from '@kbn/reporting-common'; -import type { TaskRunResult } from '@kbn/reporting-common/types'; +import type { TaskRunResult, UrlOrUrlLocatorTuple } from '@kbn/reporting-common/types'; import { JobParamsPDFV2, PDF_JOB_TYPE_V2, @@ -33,11 +33,10 @@ import { decryptJobHeaders, getFullRedirectAppUrl, ExportType, - generatePdfObservableV2, getCustomLogo, } from '@kbn/reporting-server'; -import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; -import { UrlOrUrlWithContext } from '@kbn/screenshotting-plugin/server/screenshots'; + +import { generatePdfObservableV2 } from './generate_pdf_v2'; export class PdfExportType extends ExportType { id = PDF_REPORT_TYPE_V2; @@ -72,16 +71,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 @@ -110,7 +99,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( @@ -120,24 +109,29 @@ export class PdfExportType extends ExportType payload.forceNow ), locator, - ]) as unknown as UrlOrUrlWithContext[]; + ]) as unknown as UrlOrUrlLocatorTuple[]; } apmGetAssets?.end(); apmGeneratePdf = apmTrans.startSpan('generate-pdf-pipeline', 'execute'); + return generatePdfObservableV2( this.config, this.getServerInfo(), () => - this.getScreenshots({ + this.startDeps.screenshotting!.getScreenshots({ format: 'pdf', title, logo, browserTimezone, headers, layout, - urls, + 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/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/pdf_common/jest.config.js b/packages/kbn-reporting/export_types/png/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/png/jest.config.js index a9935a9a75462..467708b5bfe9f 100644 --- a/packages/kbn-reporting/export_types/pdf_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/pdf_common'], + roots: ['/packages/kbn-reporting/export_types/png'], }; 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/packages/kbn-reporting/export_types/png/png_v2.ts b/packages/kbn-reporting/export_types/png/png_v2.ts index 2aec87a1fdc0a..7b8c10af767b9 100644 --- a/packages/kbn-reporting/export_types/png/png_v2.ts +++ b/packages/kbn-reporting/export_types/png/png_v2.ts @@ -38,16 +38,11 @@ import { PNG_REPORT_TYPE_V2, TaskPayloadPNGV2, } from '@kbn/reporting-export-types-png-common'; -import { - decryptJobHeaders, - getFullRedirectAppUrl, - 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 { decryptJobHeaders, getFullRedirectAppUrl, ExportType } from '@kbn/reporting-server'; import { SerializableRecord } from '@kbn/utility-types'; +import { generatePngObservable } from './generate_png'; + export class PngExportType extends ExportType { id = PNG_REPORT_TYPE_V2; name = 'PNG'; @@ -67,16 +62,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 @@ -120,25 +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.getScreenshots({ + this.startDeps.screenshotting!.getScreenshots({ format: 'png', headers, layout: { ...payload.layout, id: 'preserve_layout' }, - urls: [[url, locatorParams]], + urls: [[url, { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: locatorParams }]], }), jobLogger, { headers, browserTimezone: payload.browserTimezone, layout: { ...payload.layout, id: 'preserve_layout' }, - urls: [[url, locatorParams]], } ); }), 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", ] } 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/config_server/README.md b/packages/kbn-reporting/public/README.md similarity index 57% rename from packages/kbn-reporting/config_server/README.md rename to packages/kbn-reporting/public/README.md index 08a8499bdb2d5..76d4926820b7f 100644 --- a/packages/kbn-reporting/config_server/README.md +++ b/packages/kbn-reporting/public/README.md @@ -1,3 +1,3 @@ -# @kbn/reporting-config-server +# @kbn/reporting-public Empty package generated by @kbn/generate diff --git a/packages/kbn-reporting/config_server/index.ts b/packages/kbn-reporting/public/index.ts similarity index 79% rename from packages/kbn-reporting/config_server/index.ts rename to packages/kbn-reporting/public/index.ts index 57ddce550f9b1..7168d6768c5a2 100644 --- a/packages/kbn-reporting/config_server/index.ts +++ b/packages/kbn-reporting/public/index.ts @@ -6,5 +6,4 @@ * Side Public License, v 1. */ -export { ConfigSchema } from './schema'; -export type { ReportingConfigType } from './schema'; +export type { ClientConfigType } from './types'; diff --git a/packages/kbn-reporting/config_server/jest.config.js b/packages/kbn-reporting/public/jest.config.js similarity index 87% rename from packages/kbn-reporting/config_server/jest.config.js rename to packages/kbn-reporting/public/jest.config.js index 050f036d10e37..9b1a02aee8ea6 100644 --- a/packages/kbn-reporting/config_server/jest.config.js +++ b/packages/kbn-reporting/public/jest.config.js @@ -9,5 +9,5 @@ module.exports = { preset: '@kbn/test/jest_node', rootDir: '../../..', - roots: ['/packages/kbn-reporting/config_server'], + roots: ['/packages/kbn-reporting/public'], }; diff --git a/packages/kbn-reporting/config_server/kibana.jsonc b/packages/kbn-reporting/public/kibana.jsonc similarity index 62% rename from packages/kbn-reporting/config_server/kibana.jsonc rename to packages/kbn-reporting/public/kibana.jsonc index 0f3884ea6d5ff..9d506d6ed7199 100644 --- a/packages/kbn-reporting/config_server/kibana.jsonc +++ b/packages/kbn-reporting/public/kibana.jsonc @@ -1,5 +1,5 @@ { "type": "shared-common", - "id": "@kbn/reporting-config-server", + "id": "@kbn/reporting-public", "owner": "@elastic/appex-sharedux" } diff --git a/packages/kbn-reporting/config_server/package.json b/packages/kbn-reporting/public/package.json similarity index 68% rename from packages/kbn-reporting/config_server/package.json rename to packages/kbn-reporting/public/package.json index 9df47eaa9f737..b9a4abf894c64 100644 --- a/packages/kbn-reporting/config_server/package.json +++ b/packages/kbn-reporting/public/package.json @@ -1,5 +1,5 @@ { - "name": "@kbn/reporting-config-server", + "name": "@kbn/reporting-public", "private": true, "version": "1.0.0", "license": "SSPL-1.0 OR Elastic License 2.0" diff --git a/packages/kbn-reporting/config_server/tsconfig.json b/packages/kbn-reporting/public/tsconfig.json similarity index 81% rename from packages/kbn-reporting/config_server/tsconfig.json rename to packages/kbn-reporting/public/tsconfig.json index 3df73f778fdc1..6d27b06d5f8ba 100644 --- a/packages/kbn-reporting/config_server/tsconfig.json +++ b/packages/kbn-reporting/public/tsconfig.json @@ -13,7 +13,5 @@ "exclude": [ "target/**/*" ], - "kbn_references": [ - "@kbn/config-schema", - ] + "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/packages/kbn-reporting/config_server/schema.test.ts b/packages/kbn-reporting/server/config_schema.test.ts similarity index 98% rename from packages/kbn-reporting/config_server/schema.test.ts rename to packages/kbn-reporting/server/config_schema.test.ts index 58f2cc1a5e893..069218e988019 100644 --- a/packages/kbn-reporting/config_server/schema.test.ts +++ b/packages/kbn-reporting/server/config_schema.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { ConfigSchema } from './schema'; +import { ConfigSchema } from './config_schema'; describe('Reporting Config Schema', () => { it(`context {"dev":false,"dist":false} produces correct config`, () => { diff --git a/packages/kbn-reporting/config_server/schema.ts b/packages/kbn-reporting/server/config_schema.ts similarity index 97% rename from packages/kbn-reporting/config_server/schema.ts rename to packages/kbn-reporting/server/config_schema.ts index f7c910d9c425b..3aab7be6e660c 100644 --- a/packages/kbn-reporting/config_server/schema.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/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/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..45a559b51d5ee 100644 --- a/packages/kbn-reporting/server/index.ts +++ b/packages/kbn-reporting/server/index.ts @@ -9,15 +9,14 @@ 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'; 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 * from './types'; export { validateUrls } from './validate_urls'; + +export type { BaseExportTypeSetupDeps, BaseExportTypeStartDeps } from './export_type'; +export { ConfigSchema } from './config_schema'; + +export * from './types'; diff --git a/packages/kbn-reporting/server/tsconfig.json b/packages/kbn-reporting/server/tsconfig.json index 7bc92e31bddb5..26e1dfd461d21 100644 --- a/packages/kbn-reporting/server/tsconfig.json +++ b/packages/kbn-reporting/server/tsconfig.json @@ -34,6 +34,6 @@ "@kbn/core-http-router-server-internal", "@kbn/core-http-request-handler-context-server", "@kbn/reporting-export-types-pdf-common", - "@kbn/reporting-config-server", + "@kbn/config-schema", ] } diff --git a/packages/kbn-reporting/server/types.ts b/packages/kbn-reporting/server/types.ts index 8fac04cbc5f6c..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; @@ -38,3 +41,10 @@ export type RunTaskFn = ( cancellationToken: CancellationToken, stream: Writable ) => Promise; + +export interface TimeRangeParams { + min?: Date | string | number | null; + max?: Date | string | number | null; +} + +export type ReportingConfigType = TypeOf; diff --git a/tsconfig.base.json b/tsconfig.base.json index f49cb59b967d8..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"], @@ -1192,6 +1190,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/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 d3de630932a75..44e90356027bc 100644 --- a/x-pack/plugins/reporting/common/constants/index.ts +++ b/x-pack/plugins/reporting/common/constants/index.ts @@ -5,123 +5,9 @@ * 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 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', - CONTENT_TYPE_CSV, - 'image/png', - 'text/plain', -]; - -export type JobId = string; - -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]; - -// 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', -} +export * from './routes'; +export * from './export_types'; // 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/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/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(); -}; diff --git a/x-pack/plugins/reporting/common/test/fixtures.ts b/x-pack/plugins/reporting/common/test/fixtures.ts index 16f748c0a15f7..823785c4eb273 100644 --- a/x-pack/plugins/reporting/common/test/fixtures.ts +++ b/x-pack/plugins/reporting/common/test/fixtures.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { ReportApiJSON } from '../types'; +import { JOB_STATUS } from '@kbn/reporting-common'; +import { ReportApiJSON } from '@kbn/reporting-common/types'; import type { ReportMock } from './types'; const buildMockReport = (baseObj: ReportMock): ReportApiJSON => ({ @@ -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/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 index d541e2ed203d2..09d1dc8f43e31 100644 --- a/x-pack/plugins/reporting/common/types.ts +++ b/x-pack/plugins/reporting/common/types.ts @@ -5,123 +5,10 @@ * 2.0. */ -import type { - BasePayload, - ReportOutput, - TaskRunMetrics, - TaskRunResult, -} from '@kbn/reporting-common/types'; -import type { JobId } from './constants'; +import { jobTypes, reportTypes } from './constants'; -export interface ReportDocumentHead { - _id: string; - _index: string; - _seq_no: number; - _primary_term: number; -} +type ReportTypeDeclaration = typeof reportTypes; +export type ReportTypes = ReportTypeDeclaration[keyof ReportTypeDeclaration]; -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[]; -} +type JobTypeDeclaration = typeof jobTypes; +export type JobTypes = JobTypeDeclaration[keyof JobTypeDeclaration]; diff --git a/x-pack/plugins/reporting/public/lib/job.tsx b/x-pack/plugins/reporting/public/lib/job.tsx index 7b5b0b4347a2b..9aadb06bf5cc8 100644 --- a/x-pack/plugins/reporting/public/lib/job.tsx +++ b/x-pack/plugins/reporting/public/lib/job.tsx @@ -10,12 +10,20 @@ 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 { JOB_STATUS } from '@kbn/reporting-common'; +import type { + BaseParamsV2, + JobId, + ReportApiJSON, + ReportFields, + ReportOutput, + ReportSource, + TaskRunResult, +} from '@kbn/reporting-common/types'; -import { JobId, JobTypes, JOB_STATUSES } from '../../common/constants'; -import type { ReportApiJSON, ReportFields, ReportSource } from '../../common/types'; +import { JobTypes } from '../../common/types'; -const { COMPLETED, FAILED, PENDING, PROCESSING, WARNINGS } = JOB_STATUSES; +const { COMPLETED, FAILED, PENDING, PROCESSING, WARNINGS } = JOB_STATUS; type ReportPayload = ReportSource['payload']; @@ -40,7 +48,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']; @@ -74,7 +82,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; @@ -159,7 +167,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 { @@ -315,7 +323,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.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/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_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/components/report_info_flyout_content.tsx b/x-pack/plugins/reporting/public/management/components/report_info_flyout_content.tsx index e111285d02d52..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 @@ -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 { 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/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/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 906fab4c4195b..a0ff30f775260 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 { durationToNumber } from '../common/schema_utils'; -import { JobSummarySet } from '../common/types'; -import { ReportingSetup, ReportingStart } from '.'; +import { ManagementSetup, ManagementStart } from '@kbn/management-plugin/public'; +import { ClientConfigType } from '@kbn/reporting-public'; +import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/public'; + +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'; 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,17 +45,7 @@ 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 }; -} - +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/public/types.ts b/x-pack/plugins/reporting/public/types.ts index 3be354bada72e..5b88f2abbf5bd 100644 --- a/x-pack/plugins/reporting/public/types.ts +++ b/x-pack/plugins/reporting/public/types.ts @@ -6,6 +6,24 @@ */ import type { CoreSetup, CoreStart } from '@kbn/core/public'; +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: JOB_STATUS; + 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']; 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, - }, -} -`; 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 01b9574d07b47..5965693e37c13 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 }, @@ -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/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/core.ts b/x-pack/plugins/reporting/server/core.ts index dd046b2daef22..c4af9d15f8c4c 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,22 +26,17 @@ 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, 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 { - PdfScreenshotResult, - PngScreenshotResult, - ScreenshotOptions, - ScreenshottingStart, -} from '@kbn/screenshotting-plugin/server'; +import type { ReportingConfigType } from '@kbn/reporting-server'; +import { ExportType } from '@kbn/reporting-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'; @@ -52,12 +47,12 @@ 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'; import { ExecuteReportTask, MonitorReportsTask, ReportTaskParams } from './lib/tasks'; -import type { PdfScreenshotOptions, PngScreenshotOptions, ReportingPluginRouter } from './types'; +import type { ReportingPluginRouter } from './types'; export interface ReportingInternalSetup { basePath: Pick; @@ -126,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), }); @@ -163,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; @@ -393,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/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/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/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/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/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/report.ts b/x-pack/plugins/reporting/server/lib/store/report.ts index 6f23c23e9066a..e4ed610eeecd6 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_STATUS } 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'; @@ -95,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/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..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,10 +6,12 @@ */ 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 '.'; import { ReportingCore } from '../..'; import { createMockReportingCore } from '../../test_helpers'; -import { Report, ReportDocument, ReportingStore, SavedReport } from '.'; describe('ReportingStore', () => { const mockLogger = loggingSystemMock.createLogger(); @@ -185,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, @@ -392,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/lib/store/store.ts b/x-pack/plugins/reporting/server/lib/store/store.ts index 47db231a87f70..710a78ffe859a 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 { ReportDocument, 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 type { IReport, Report } 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.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 e0b43153456da..8bc6ba0f865ec 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,27 +19,22 @@ import { KibanaShuttingDownError, QueueTimeoutError, ReportingError, + 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, 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 type { ReportingStore } from '../store'; import { Report, SavedReport } from '../store'; import type { ReportFailedFields, ReportProcessingFields } from '../store/store'; import { errorLogger } from './error_logger'; 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/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 fa599d225b77d..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,12 +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 { 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 +98,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 +109,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 +117,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..b05430200c2e1 100644 --- a/x-pack/plugins/reporting/server/plugin.ts +++ b/x-pack/plugins/reporting/server/plugin.ts @@ -12,10 +12,11 @@ import type { Plugin, 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 { PLUGIN_ID } from '../common/constants'; -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/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 00a47c703ff90..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 { ReportApiJSON } from '../../../../common/types'; -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 588f5c9f661b3..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 @@ -5,14 +5,16 @@ * 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 { JOB_STATUS } from '@kbn/reporting-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 { getContentStream } from '../../../lib'; import { jobsQueryFactory } from './jobs_query'; export interface ErrorFromPayload { @@ -107,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/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.test.ts b/x-pack/plugins/reporting/server/routes/common/jobs/jobs_query.test.ts index f0c656da2050a..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 @@ -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 { statuses } from '../../../lib'; -import { createMockConfigSchema, createMockReportingCore } from '../../../test_helpers'; +import { JOB_STATUS } from '@kbn/reporting-common'; +import { createMockConfigSchema } from '@kbn/reporting-mocks-server'; +import { createMockReportingCore } from '../../../test_helpers'; import { jobsQueryFactory } from './jobs_query'; describe('jobsQuery', () => { @@ -184,7 +186,7 @@ describe('jobsQuery', () => { _id: 'id1', jobtype: 'pdf', output: { content: 'Some error' }, - status: statuses.JOB_STATUS_FAILED, + status: JOB_STATUS.FAILED, }, }, ]) @@ -218,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 87bf38648bd2f..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 @@ -5,13 +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 { JOB_STATUS, 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'; 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/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 2a9f61ef1f99c..eb144dda1e476 100644 --- a/x-pack/plugins/reporting/server/types.ts +++ b/x-pack/plugins/reporting/server/types.ts @@ -6,12 +6,15 @@ */ 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'; 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 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, @@ -30,9 +33,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'; /** @@ -40,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 */ @@ -78,6 +77,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 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/plugins/reporting/tsconfig.json b/x-pack/plugins/reporting/tsconfig.json index e29ad2120925f..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", @@ -49,8 +48,8 @@ "@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", + "@kbn/reporting-public", ], "exclude": [ "target/**/*", 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": "呈现门户内容时出错", 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_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'; 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'; 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", ] } diff --git a/yarn.lock b/yarn.lock index 33d5a847a930e..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 "" @@ -5288,6 +5284,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 ""