Deprecate CSV job type (#89794)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tim Sullivan 2021-02-01 09:36:49 -07:00 committed by GitHub
parent 9f4dae82c5
commit 8701ac85d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 62 additions and 47 deletions

View file

@ -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

View file

@ -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';
@ -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:

View file

@ -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 });
@ -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

View file

@ -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';
@ -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[],

View file

@ -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'));
@ -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,

View file

@ -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));
@ -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';

View file

@ -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');

View file

@ -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: {

View file

@ -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
@ -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
) {

View file

@ -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';
@ -39,7 +39,7 @@ interface SearchRequest {
export interface GenerateCsvParams {
browserTimezone?: string;
searchRequest: SearchRequest;
indexPatternSavedObject: IndexPatternSavedObject;
indexPatternSavedObject: IndexPatternSavedObjectDeprecatedCSV;
fields: string[];
metaFields: string[];
conflictedTypesFields: string[];

View file

@ -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,
@ -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,

View file

@ -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[];
@ -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:
| {
@ -66,7 +66,7 @@ export interface SearchRequest {
| any;
}
type FormatsMap = Map<
type FormatsMapDeprecatedCSV = Map<
string,
{
id: string;

View file

@ -4,7 +4,7 @@
* 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(
@ -12,10 +12,10 @@ export async function getDataSource(
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) {

View file

@ -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';
@ -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);

View file

@ -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(
@ -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[];