Skip to content
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
2 changes: 2 additions & 0 deletions x-pack/plugins/reporting/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface ReportOutput extends TaskRunResult {
export interface TaskRunResult {
content_type: string | null;
csv_contains_formulas?: boolean;
csv_rows?: number;
max_size_reached?: boolean;
warnings?: string[];
}
Expand Down Expand Up @@ -130,6 +131,7 @@ export interface JobSummary {
title: ReportSource['payload']['title'];
maxSizeReached: TaskRunResult['max_size_reached'];
csvContainsFormulas: TaskRunResult['csv_contains_formulas'];
csvRows: TaskRunResult['csv_rows'];
}

export interface JobSummarySet {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions x-pack/plugins/reporting/public/lib/job.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class Job {
public size?: ReportOutput['size'];
public content_type?: TaskRunResult['content_type'];
public csv_contains_formulas?: TaskRunResult['csv_contains_formulas'];
public csv_rows?: TaskRunResult['csv_rows'];
public max_size_reached?: TaskRunResult['max_size_reached'];
public warnings?: TaskRunResult['warnings'];

Expand Down Expand Up @@ -87,6 +88,7 @@ export class Job {
this.isDeprecated = report.payload.isDeprecated || false;
this.spaceId = report.payload.spaceId;
this.csv_contains_formulas = report.output?.csv_contains_formulas;
this.csv_rows = report.output?.csv_rows;
this.max_size_reached = report.output?.max_size_reached;
this.warnings = report.output?.warnings;
this.locatorParams = (report.payload as BaseParamsV2).locatorParams;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/reporting/public/lib/stream_handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const mockJobsFound: Job[] = [
{ id: 'job-source-mock1', status: 'completed', output: { csv_contains_formulas: false, max_size_reached: false }, payload: { title: 'specimen' } },
{ id: 'job-source-mock2', status: 'failed', output: { csv_contains_formulas: false, max_size_reached: false }, payload: { title: 'specimen' } },
{ id: 'job-source-mock3', status: 'pending', output: { csv_contains_formulas: false, max_size_reached: false }, payload: { title: 'specimen' } },
{ id: 'job-source-mock4', status: 'completed', output: { csv_contains_formulas: true, csv_rows: 42000000, max_size_reached: false }, payload: { title: 'specimen' } },
].map((j) => new Job(j as ReportApiJSON)); // prettier-ignore

const coreSetup = coreMock.createSetup();
Expand Down Expand Up @@ -74,6 +75,7 @@ describe('stream handler', () => {
'job-source-mock1',
'job-source-mock2',
'job-source-mock3',
'job-source-mock4',
]);

findJobs.subscribe((data) => {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/public/lib/stream_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function getReportStatus(src: Job): JobSummary {
jobtype: src.prettyJobTypeName ?? src.jobtype,
maxSizeReached: src.max_size_reached,
csvContainsFormulas: src.csv_contains_formulas,
csvRows: src.csv_rows,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const ReportInfoFlyoutContent: FunctionComponent<Props> = ({ info }) => {

const formatDate = createDateFormatter(uiSettings.get('dateFormat'), timezone);

const hasCsvRows = info.csv_rows != null;
const hasScreenshot = USES_HEADLESS_JOB_TYPES.includes(info.jobtype);

const outputInfo = [
Expand Down Expand Up @@ -94,6 +95,12 @@ export const ReportInfoFlyoutContent: FunctionComponent<Props> = ({ info }) => {
}),
description: info.size?.toString() || NA,
},
hasCsvRows && {
title: i18n.translate('xpack.reporting.listing.infoPanel.csvRows', {
defaultMessage: 'CSV rows',
}),
description: info.csv_rows?.toString() || NA,
},

hasScreenshot && {
title: i18n.translate('xpack.reporting.listing.infoPanel.dimensionsInfoHeight', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export class CsvGenerator {
return {
content_type: CONTENT_TYPE_CSV,
csv_contains_formulas: this.csvContainsFormulas && !escapeFormulaValues,
csv_rows: this.csvRowCount,
max_size_reached: this.maxSizeReached,
warnings,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Event Logger', () => {
jest.spyOn(logger.completionLogger, 'stopTiming');
logger.logExecutionStart();

const result = logger.logExecutionComplete({ byteSize: 444 });
const result = logger.logExecutionComplete({ byteSize: 444, csvRows: 440000 });
expect([result.event, result.kibana.reporting, result.message]).toMatchInlineSnapshot(`
Array [
Object {
Expand All @@ -125,6 +125,7 @@ describe('Event Logger', () => {
Object {
"actionType": "execute-complete",
"byteSize": 444,
"csvRows": 440000,
"id": "12348",
"jobType": "csv",
},
Expand Down
26 changes: 13 additions & 13 deletions x-pack/plugins/reporting/server/lib/event_logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ErrorAction,
ExecuteError,
FailedReport,
ReportingAction,
SavedReport,
ScheduledRetry,
ScheduledTask,
Expand All @@ -28,6 +27,7 @@ import {
/** @internal */
export interface ExecutionCompleteMetrics {
byteSize: number;
csvRows?: number;
}

export interface IReportingEventLogger {
Expand All @@ -36,21 +36,21 @@ export interface IReportingEventLogger {
stopTiming(): void;
}

export interface BaseEvent {
event: { timezone: string };
kibana: {
reporting: { id?: string; jobType: string };
task?: { id: string };
};
user?: { name: string };
}

/** @internal */
export function reportingEventLoggerFactory(logger: LevelLogger) {
const genericLogger = new EcsLogAdapter(logger, { event: { provider: PLUGIN_ID } });

return class ReportingEventLogger {
readonly eventObj: {
event: {
timezone: string;
};
kibana: {
reporting: ReportingAction<ActionType>['kibana']['reporting'];
task?: { id: string };
};
user?: { name: string };
};
readonly eventObj: BaseEvent;

readonly report: IReport;
readonly task?: { id: string };
Expand Down Expand Up @@ -102,13 +102,13 @@ export function reportingEventLoggerFactory(logger: LevelLogger) {
return event;
}

logExecutionComplete({ byteSize }: ExecutionCompleteMetrics): CompletedExecution {
logExecutionComplete({ byteSize, csvRows }: ExecutionCompleteMetrics): CompletedExecution {
const message = `completed ${this.report.jobtype} execution`;
this.completionLogger.stopTiming();
const event = deepMerge(
{
message,
kibana: { reporting: { actionType: ActionType.EXECUTE_COMPLETE, byteSize } },
kibana: { reporting: { actionType: ActionType.EXECUTE_COMPLETE, byteSize, csvRows } },
} as Partial<CompletedExecution>,
this.eventObj
);
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/reporting/server/lib/event_logger/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
import { LogMeta } from 'src/core/server';
import { ActionType } from './';

interface ActionBase<A extends ActionType> {
export interface ReportingAction<A extends ActionType> extends LogMeta {
event: {
timezone: string;
};
message: string;
kibana: {
reporting: {
actionType?: A;
actionType: A;
id?: string; // "immediate download" exports have no ID
jobType: string;
byteSize?: number;
csvRows?: number;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wonder if this should be:

csv?: { rows: number; };

We could have more CSV-specific metrics: number of columns in the CSV is one. But if there are other settings that affect performance, we should think of adding them as well.

};
} & { task?: { id?: string } };
task?: { id?: string };
};
user?: { name: string };
}

Expand All @@ -31,8 +33,6 @@ export interface ErrorAction {
type?: string;
}

export type ReportingAction<A extends ActionType> = ActionBase<A> & LogMeta;

export type ScheduledTask = ReportingAction<ActionType.SCHEDULE_TASK>;
export type StartedExecution = ReportingAction<ActionType.EXECUTE_START>;
export type CompletedExecution = ReportingAction<ActionType.EXECUTE_COMPLETE>;
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/reporting/server/lib/tasks/execute_report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export class ExecuteReportTask implements ReportingTask {
docOutput.content_type = output.content_type || unknownMime;
docOutput.max_size_reached = output.max_size_reached;
docOutput.csv_contains_formulas = output.csv_contains_formulas;
docOutput.csv_rows = output.csv_rows;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is missing in x-pack/plugins/reporting/server/lib/store/mapping.ts.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed moving the location csv_rows in the interface. Since we are not aggregating on the value yet, not having it in the mapping makes sense for now. :)

docOutput.size = output.size;
docOutput.warnings =
output.warnings && output.warnings.length > 0 ? output.warnings : undefined;
Expand Down Expand Up @@ -363,7 +364,10 @@ export class ExecuteReportTask implements ReportingTask {
report._seq_no = stream.getSeqNo()!;
report._primary_term = stream.getPrimaryTerm()!;

eventLog.logExecutionComplete({ byteSize: stream.bytesWritten });
eventLog.logExecutionComplete({
byteSize: stream.bytesWritten,
csvRows: output?.csv_rows,
});

if (output) {
this.logger.debug(`Job output size: ${stream.bytesWritten} bytes.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ export function registerGenerateCsvFromSavedObjectImmediate(
try {
eventLog.logExecutionStart();
const taskPromise = runTaskFn(null, req.body, context, stream, req)
.then(() => {
.then((output) => {
logger.info(`Job output size: ${stream.bytesWritten} bytes.`);

if (!stream.bytesWritten) {
logger.warn('CSV Job Execution created empty content result');
}

eventLog.logExecutionComplete({ byteSize: stream.bytesWritten });
eventLog.logExecutionComplete({
byteSize: stream.bytesWritten,
csvRows: output.csv_rows,
});
})
.finally(() => stream.end());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('getDocumentPayload', () => {
output: {
content_type: 'text/csv',
csv_contains_formulas: true,
csv_rows: 42000000,
max_size_reached: true,
size: 1024,
},
Expand Down