[Reporting] Allow csvV2 export type to run with a custom paging strategy (#175748)

## Summary

Follows https://github.com/elastic/kibana/pull/174980

This PR updates the "task payload" data of the "new" CSV export type to
allow the `scroll` option as a method for paging the search when
generating the CSV report.
This commit is contained in:
Tim Sullivan 2024-01-30 11:43:19 -07:00 committed by GitHub
parent 3b2e7d2150
commit 5dc0c2f121
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 18 additions and 7 deletions

View file

@ -8,4 +8,3 @@
export { CsvGenerator } from './src/generate_csv';
export { CsvESQLGenerator, type JobParamsCsvESQL } from './src/generate_csv_esql';
export type { CsvPagingStrategy } from './types';

View file

@ -55,6 +55,11 @@ export interface ReportOutput extends TaskRunResult {
size: number;
}
/**
* @see also {@link packages/kbn-reporting/common/types.ts}
*/
export type CsvPagingStrategy = 'pit' | 'scroll';
/**
* @deprecated
*/
@ -64,7 +69,7 @@ export interface BaseParams {
title: string;
version: string; // to handle any state migrations
layout?: LayoutParams; // png & pdf only
pagingStrategy?: 'pit' | 'scroll'; // csv only
pagingStrategy?: CsvPagingStrategy; // csv only
}
/**

View file

@ -10,7 +10,7 @@ import { Writable } from 'stream';
import type { DataPluginStart } from '@kbn/data-plugin/server/plugin';
import type { DiscoverServerPluginStart } from '@kbn/discover-plugin/server';
import { CsvGenerator, type CsvPagingStrategy } from '@kbn/generate-csv';
import { CsvGenerator } from '@kbn/generate-csv';
import {
CancellationToken,
LICENSE_TYPE_BASIC,
@ -20,7 +20,7 @@ import {
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
} from '@kbn/reporting-common';
import { TaskInstanceFields } from '@kbn/reporting-common/types';
import { CsvPagingStrategy, TaskInstanceFields } from '@kbn/reporting-common/types';
import {
CSV_JOB_TYPE,
CSV_REPORT_TYPE,

View file

@ -93,7 +93,10 @@ export class CsvV2ExportType extends ExportType<
const locatorClient = await discoverPluginStart.locator.asScopedClient(req);
const title = jobParams.title || (await locatorClient.titleFromLocator(params));
return { ...jobParams, title, objectType: 'search', isDeprecated: false };
const objectType = 'search' as const;
const pagingStrategy = this.config.csv.scroll.strategy;
return { ...jobParams, title, objectType, pagingStrategy };
};
public runTask = async (

View file

@ -12,6 +12,7 @@ import type {
BaseParamsV2,
BasePayload,
BasePayloadV2,
CsvPagingStrategy,
} from '@kbn/reporting-common/types';
export * from './constants';
@ -41,7 +42,10 @@ interface CsvFromSavedObjectBase {
export type JobParamsCsvFromSavedObject = CsvFromSavedObjectBase &
Omit<BaseParamsV2, 'title'> & { title?: string };
export type TaskPayloadCsvFromSavedObject = CsvFromSavedObjectBase & BasePayloadV2;
export interface TaskPayloadCsvFromSavedObject extends CsvFromSavedObjectBase, BasePayloadV2 {
objectType: 'search';
pagingStrategy: CsvPagingStrategy;
}
export const CSV_REPORTING_ACTION = 'downloadCsvReport';

View file

@ -55,7 +55,7 @@ export abstract class ExportType<
abstract jobContentEncoding?: 'base64' | 'csv';
abstract jobContentExtension: 'pdf' | 'png' | 'csv';
abstract createJob: CreateJobFn<JobParamsType>;
abstract createJob: CreateJobFn<JobParamsType, TaskPayloadType>;
abstract runTask: RunTaskFn<TaskPayloadType>;
abstract validLicenses: LicenseType[];