Skip to content

Commit

Permalink
Merge pull request #13 from tsullivan/reporting-packages
Browse files Browse the repository at this point in the history
Reporting packages
  • Loading branch information
rshen91 authored Nov 14, 2023
2 parents d7368f0 + 80bd0c4 commit 3fcc451
Show file tree
Hide file tree
Showing 131 changed files with 635 additions and 859 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-generate-csv/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"type": "shared-server",
"id": "@kbn/generate-csv",
"owner": "@elastic/appex-sharedux"
}
2 changes: 1 addition & 1 deletion packages/kbn-generate-csv/src/generate_csv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-generate-csv/src/generate_csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-generate-csv/src/get_export_settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-generate-csv/src/get_export_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-generate-csv/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}
18 changes: 18 additions & 0 deletions packages/kbn-generate-csv/types.ts
Original file line number Diff line number Diff line change
@@ -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[];
}
44 changes: 44 additions & 0 deletions packages/kbn-reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
*
Expand All @@ -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';
6 changes: 3 additions & 3 deletions packages/kbn-reporting/common/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
});
}
Expand All @@ -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.`,
});
}
Expand Down Expand Up @@ -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.`,
});
}
Expand Down
84 changes: 84 additions & 0 deletions packages/kbn-reporting/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<ReportSource, 'payload' | 'output'> {
payload: Omit<ReportSource['payload'], 'headers'>;
output?: Omit<ReportOutput, 'content'>; // 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.';

Expand Down Expand Up @@ -69,7 +68,6 @@ beforeAll(async () => {
uiSettings: mockCoreStart.uiSettings,
discover: discoverPluginMock.createStartContract(),
data: dataPluginMock.createStartContract(),
screenshotting: createMockScreenshottingStart(),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-reporting/export_types/csv/csv_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,7 +71,7 @@ export class CsvV2ExportType extends ExportType<

public createJob = async (
jobParams: JobParamsCsvFromSavedObject,
_context: unknown,
_context: ReportingRequestHandlerContext,
req: KibanaRequest
) => {
// 1. Validation of locatorParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/packages/kbn-reporting/export_types/csv_common'],
roots: ['<rootDir>/packages/kbn-reporting/export_types/csv'],
};
1 change: 0 additions & 1 deletion packages/kbn-reporting/export_types/csv/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}
Loading

0 comments on commit 3fcc451

Please sign in to comment.