Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting] Label the existing CSV job type as Deprecated #89794

Merged
merged 2 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions x-pack/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,19 @@ export const LAYOUT_TYPES = {
};

// Export Type Definitions
export const CSV_REPORT_TYPE = 'CSV';
export const PDF_REPORT_TYPE = 'printablePdf';
export const PNG_REPORT_TYPE = 'PNG';

export const PDF_JOB_TYPE = 'printable_pdf';

export const PNG_REPORT_TYPE = 'PNG';
export const PNG_JOB_TYPE = 'PNG';
export const CSV_JOB_TYPE = 'csv';

export const CSV_FROM_SAVEDOBJECT_JOB_TYPE = 'csv_from_savedobject';

// This is deprecated because it lacks support for runtime fields
// but the extension points are still needed for pre-existing scripted automation, until 8.0
export const CSV_REPORT_TYPE_DEPRECATED = 'CSV';
export const CSV_JOB_TYPE_DEPRECATED = 'csv';

export const USES_HEADLESS_JOB_TYPES = [PDF_JOB_TYPE, PNG_JOB_TYPE];

// Licenses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import React, { Component, ReactElement } from 'react';
import { ToastsSetup } from 'src/core/public';
import url from 'url';
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public';
import { CSV_REPORT_TYPE, PDF_REPORT_TYPE, PNG_REPORT_TYPE } from '../../common/constants';
import {
CSV_REPORT_TYPE_DEPRECATED,
PDF_REPORT_TYPE,
PNG_REPORT_TYPE,
} from '../../common/constants';
import { BaseParams } from '../../common/types';
import { ReportingAPIClient } from '../lib/reporting_api_client';

Expand Down Expand Up @@ -173,7 +177,7 @@ class ReportingPanelContentUi extends Component<Props, State> {
case PDF_REPORT_TYPE:
return 'PDF';
case 'csv':
return CSV_REPORT_TYPE;
return CSV_REPORT_TYPE_DEPRECATED;
case 'png':
return PNG_REPORT_TYPE;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export class GetCsvReportPanelAction implements ActionDefinition<ActionContext>
const kibanaTimezone = this.core.uiSettings.get('dateFormat:tz');

const id = `search:${embeddable.getSavedSearch().id}`;
const filename = embeddable.getSavedSearch().title;
const timezone = kibanaTimezone === 'Browser' ? moment.tz.guess() : kibanaTimezone;
const fromTime = dateMath.parse(from);
const toTime = dateMath.parse(to, { roundUp: true });
Expand Down Expand Up @@ -140,7 +139,7 @@ export class GetCsvReportPanelAction implements ActionDefinition<ActionContext>
.then((rawResponse: string) => {
this.isDownloading = false;

const download = `${filename}.csv`;
const download = `${embeddable.getSavedSearch().title}.csv`;
const blob = new Blob([rawResponse], { type: 'text/csv;charset=utf-8;' });

// Hack for IE11 Support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import React from 'react';
import { IUiSettingsClient, ToastsSetup } from 'src/core/public';
import { ShareContext } from '../../../../../src/plugins/share/public';
import { LicensingPluginSetup } from '../../../licensing/public';
import { JobParamsCSV, SearchRequest } from '../../server/export_types/csv/types';
import {
JobParamsDeprecatedCSV,
SearchRequestDeprecatedCSV,
} from '../../server/export_types/csv/types';
import { ReportingPanelContent } from '../components/reporting_panel_content_lazy';
import { checkLicense } from '../lib/license_check';
import { ReportingAPIClient } from '../lib/reporting_api_client';
Expand Down Expand Up @@ -59,12 +62,12 @@ export const csvReportingProvider = ({
return [];
}

const jobParams: JobParamsCSV = {
const jobParams: JobParamsDeprecatedCSV = {
browserTimezone,
objectType,
title: sharingData.title as string,
indexPatternId: sharingData.indexPatternId as string,
searchRequest: sharingData.searchRequest as SearchRequest,
searchRequest: sharingData.searchRequest as SearchRequestDeprecatedCSV,
fields: sharingData.fields as string[],
metaFields: sharingData.metaFields as string[],
conflictedTypesFields: sharingData.conflictedTypesFields as string[],
Expand Down
14 changes: 9 additions & 5 deletions x-pack/plugins/reporting/server/export_types/csv/create_job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CSV_JOB_TYPE } from '../../../common/constants';
import { CSV_JOB_TYPE_DEPRECATED } from '../../../common/constants';
import { cryptoFactory } from '../../lib';
import { CreateJobFn, CreateJobFnFactory } from '../../types';
import { IndexPatternSavedObject, JobParamsCSV, TaskPayloadCSV } from './types';
import {
IndexPatternSavedObjectDeprecatedCSV,
JobParamsDeprecatedCSV,
TaskPayloadDeprecatedCSV,
} from './types';

export const createJobFnFactory: CreateJobFnFactory<
CreateJobFn<JobParamsCSV, TaskPayloadCSV>
CreateJobFn<JobParamsDeprecatedCSV, TaskPayloadDeprecatedCSV>
> = function createJobFactoryFn(reporting, parentLogger) {
const logger = parentLogger.clone([CSV_JOB_TYPE, 'create-job']);
const logger = parentLogger.clone([CSV_JOB_TYPE_DEPRECATED, 'create-job']);

const config = reporting.getConfig();
const crypto = cryptoFactory(config.get('encryptionKey'));
Expand All @@ -24,7 +28,7 @@ export const createJobFnFactory: CreateJobFnFactory<
const indexPatternSavedObject = ((await savedObjectsClient.get(
'index-pattern',
jobParams.indexPatternId
)) as unknown) as IndexPatternSavedObject; // FIXME
)) as unknown) as IndexPatternSavedObjectDeprecatedCSV;

return {
headers: serializedEncryptedHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { LevelLogger } from '../../lib';
import { setFieldFormats } from '../../services';
import { createMockReportingCore } from '../../test_helpers';
import { runTaskFnFactory } from './execute_job';
import { TaskPayloadCSV } from './types';
import { TaskPayloadDeprecatedCSV } from './types';

const delay = (ms: number) => new Promise<void>((resolve) => setTimeout(() => resolve(), ms));

Expand All @@ -31,7 +31,7 @@ const getRandomScrollId = () => {
return puid.generate();
};

const getBasePayload = (baseObj: any) => baseObj as TaskPayloadCSV;
const getBasePayload = (baseObj: any) => baseObj as TaskPayloadDeprecatedCSV;

describe('CSV Execute Job', function () {
const encryptionKey = 'testEncryptionKey';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CONTENT_TYPE_CSV, CSV_JOB_TYPE } from '../../../common/constants';
import { CONTENT_TYPE_CSV, CSV_JOB_TYPE_DEPRECATED } from '../../../common/constants';
import { RunTaskFn, RunTaskFnFactory } from '../../types';
import { decryptJobHeaders } from '../common';
import { createGenerateCsv } from './generate_csv';
import { TaskPayloadCSV } from './types';
import { TaskPayloadDeprecatedCSV } from './types';

export const runTaskFnFactory: RunTaskFnFactory<
RunTaskFn<TaskPayloadCSV>
RunTaskFn<TaskPayloadDeprecatedCSV>
> = function executeJobFactoryFn(reporting, parentLogger) {
const config = reporting.getConfig();

return async function runTask(jobId, job, cancellationToken) {
const elasticsearch = reporting.getElasticsearchService();
const logger = parentLogger.clone([CSV_JOB_TYPE, 'execute-job', jobId]);
const logger = parentLogger.clone([CSV_JOB_TYPE_DEPRECATED, 'execute-job', jobId]);
const generateCsv = createGenerateCsv(logger);

const encryptionKey = config.get('encryptionKey');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import expect from '@kbn/expect';
import { fieldFormats, FieldFormatsGetConfigFn, UI_SETTINGS } from 'src/plugins/data/server';
import { IndexPatternSavedObject } from '../types';
import { IndexPatternSavedObjectDeprecatedCSV } from '../types';
import { fieldFormatMapFactory } from './field_format_map';

type ConfigValue = { number: { id: string; params: {} } } | string;

describe('field format map', function () {
const indexPatternSavedObject: IndexPatternSavedObject = {
const indexPatternSavedObject: IndexPatternSavedObjectDeprecatedCSV = {
timeFieldName: '@timestamp',
title: 'logstash-*',
attributes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import _ from 'lodash';
import { FieldFormat } from 'src/plugins/data/common';
import { FieldFormatConfig, IFieldFormatsRegistry } from 'src/plugins/data/server';
import { IndexPatternSavedObject } from '../types';
import { IndexPatternSavedObjectDeprecatedCSV } from '../types';

/**
* Create a map of FieldFormat instances for index pattern fields
Expand All @@ -17,7 +17,7 @@ import { IndexPatternSavedObject } from '../types';
* @return {Map} key: field name, value: FieldFormat instance
*/
export function fieldFormatMapFactory(
indexPatternSavedObject: IndexPatternSavedObject,
indexPatternSavedObject: IndexPatternSavedObjectDeprecatedCSV,
fieldFormatsRegistry: IFieldFormatsRegistry,
timezone: string | undefined
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CSV_BOM_CHARS } from '../../../../common/constants';
import { byteSizeValueToNumber } from '../../../../common/schema_utils';
import { LevelLogger } from '../../../lib';
import { getFieldFormats } from '../../../services';
import { IndexPatternSavedObject, SavedSearchGeneratorResult } from '../types';
import { IndexPatternSavedObjectDeprecatedCSV, SavedSearchGeneratorResult } from '../types';
import { checkIfRowsHaveFormulas } from './check_cells_for_formulas';
import { createEscapeValue } from './escape_value';
import { fieldFormatMapFactory } from './field_format_map';
Expand All @@ -39,7 +39,7 @@ interface SearchRequest {
export interface GenerateCsvParams {
browserTimezone?: string;
searchRequest: SearchRequest;
indexPatternSavedObject: IndexPatternSavedObject;
indexPatternSavedObject: IndexPatternSavedObjectDeprecatedCSV;
fields: string[];
metaFields: string[];
conflictedTypesFields: string[];
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/reporting/server/export_types/csv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import {
CSV_JOB_TYPE as jobType,
CSV_JOB_TYPE_DEPRECATED as jobType,
LICENSE_TYPE_BASIC,
LICENSE_TYPE_ENTERPRISE,
LICENSE_TYPE_GOLD,
Expand All @@ -17,11 +17,11 @@ import { CreateJobFn, ExportTypeDefinition, RunTaskFn } from '../../types';
import { createJobFnFactory } from './create_job';
import { runTaskFnFactory } from './execute_job';
import { metadata } from './metadata';
import { JobParamsCSV, TaskPayloadCSV } from './types';
import { JobParamsDeprecatedCSV, TaskPayloadDeprecatedCSV } from './types';

export const getExportType = (): ExportTypeDefinition<
CreateJobFn<JobParamsCSV>,
RunTaskFn<TaskPayloadCSV>
CreateJobFn<JobParamsDeprecatedCSV>,
RunTaskFn<TaskPayloadDeprecatedCSV>
> => ({
...metadata,
jobType,
Expand Down
16 changes: 8 additions & 8 deletions x-pack/plugins/reporting/server/export_types/csv/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BaseParams, BasePayload } from '../../types';

export type RawValue = string | object | null | undefined;

export interface IndexPatternSavedObject {
export interface IndexPatternSavedObjectDeprecatedCSV {
title: string;
timeFieldName: string;
fields?: any[];
Expand All @@ -18,25 +18,25 @@ export interface IndexPatternSavedObject {
};
}

interface BaseParamsCSV {
searchRequest: SearchRequest;
interface BaseParamsDeprecatedCSV {
searchRequest: SearchRequestDeprecatedCSV;
fields: string[];
metaFields: string[];
conflictedTypesFields: string[];
}

export type JobParamsCSV = BaseParamsCSV &
export type JobParamsDeprecatedCSV = BaseParamsDeprecatedCSV &
BaseParams & {
indexPatternId: string;
};

// CSV create job method converts indexPatternID to indexPatternSavedObject
export type TaskPayloadCSV = BaseParamsCSV &
export type TaskPayloadDeprecatedCSV = BaseParamsDeprecatedCSV &
BasePayload & {
indexPatternSavedObject: IndexPatternSavedObject;
indexPatternSavedObject: IndexPatternSavedObjectDeprecatedCSV;
};

export interface SearchRequest {
export interface SearchRequestDeprecatedCSV {
index: string;
body:
| {
Expand Down Expand Up @@ -66,7 +66,7 @@ export interface SearchRequest {
| any;
}

type FormatsMap = Map<
type FormatsMapDeprecatedCSV = Map<
string,
{
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IndexPatternSavedObject } from '../../csv/types';
import { IndexPatternSavedObjectDeprecatedCSV } from '../../csv/types';
import { SavedObjectReference, SavedSearchObjectAttributesJSON, SearchSource } from '../types';

export async function getDataSource(
savedObjectsClient: any,
indexPatternId?: string,
savedSearchObjectId?: string
): Promise<{
indexPatternSavedObject: IndexPatternSavedObject;
indexPatternSavedObject: IndexPatternSavedObjectDeprecatedCSV;
searchSource: SearchSource | null;
}> {
let indexPatternSavedObject: IndexPatternSavedObject;
let indexPatternSavedObject: IndexPatternSavedObjectDeprecatedCSV;
let searchSource: SearchSource | null = null;

if (savedSearchObjectId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// @ts-ignore
import contentDisposition from 'content-disposition';
import { get } from 'lodash';
import { CSV_JOB_TYPE } from '../../../common/constants';
import { CSV_JOB_TYPE_DEPRECATED } from '../../../common/constants';
import { ExportTypesRegistry, statuses } from '../../lib';
import { ReportDocument } from '../../lib/store';
import { TaskRunResult } from '../../lib/tasks';
Expand All @@ -33,7 +33,7 @@ const getTitle = (exportType: ExportTypeDefinition, title?: string): string =>
const getReportingHeaders = (output: TaskRunResult, exportType: ExportTypeDefinition) => {
const metaDataHeaders: Record<string, boolean> = {};

if (exportType.jobType === CSV_JOB_TYPE) {
if (exportType.jobType === CSV_JOB_TYPE_DEPRECATED) {
const csvContainsFormulas = get(output, 'csv_contains_formulas', false);
const maxSizedReach = get(output, 'max_size_reached', false);

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/reporting/server/usage/decorate_range_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { uniq } from 'lodash';
import { CSV_JOB_TYPE, PDF_JOB_TYPE, PNG_JOB_TYPE } from '../../common/constants';
import { CSV_JOB_TYPE_DEPRECATED, PDF_JOB_TYPE, PNG_JOB_TYPE } from '../../common/constants';
import { AvailableTotal, ExportType, FeatureAvailabilityMap, RangeStats } from './types';

function getForFeature(
Expand Down Expand Up @@ -54,7 +54,7 @@ export const decorateRangeStats = (

// combine the known types with any unknown type found in reporting data
const keysBasic = uniq([
CSV_JOB_TYPE,
CSV_JOB_TYPE_DEPRECATED,
PNG_JOB_TYPE,
...Object.keys(rangeStatsBasic),
]) as ExportType[];
Expand Down