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] Add "warning" status as an alternate type of completed job #63498

Merged
merged 9 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,27 @@ describe('Worker class', function() {
});
});

it('handle warnings in the output by reflecting a warning status', () => {
const workerFn = () => {
return Promise.resolve({
...payload,
warnings: [`Don't run with scissors!`],
});
};
worker = new Worker(mockQueue, 'test', workerFn, defaultWorkerOptions);

return worker
._performJob({
test: true,
...job,
})
.then(() => {
sinon.assert.calledOnce(updateSpy);
const doc = updateSpy.firstCall.args[1].body.doc;
expect(doc).to.have.property('status', constants.JOB_STATUS_WARNINGS);
});
});

it('should emit completion event', function(done) {
worker = new Worker(mockQueue, 'test', noop, defaultWorkerOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const statuses = {
JOB_STATUS_PENDING: 'pending',
JOB_STATUS_PROCESSING: 'processing',
JOB_STATUS_COMPLETED: 'completed',
JOB_STATUS_WARNINGS: 'completed_with_warnings',
JOB_STATUS_FAILED: 'failed',
JOB_STATUS_CANCELLED: 'cancelled',
};
9 changes: 8 additions & 1 deletion x-pack/legacy/plugins/reporting/server/lib/esqueue/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,15 @@ export class Worker extends events.EventEmitter {
const completedTime = moment().toISOString();
const docOutput = this._formatOutput(output);

let status;
tsullivan marked this conversation as resolved.
Show resolved Hide resolved
if (output && output.warnings && output.warnings.length > 0) {
status = constants.JOB_STATUS_WARNINGS;
} else {
status = constants.JOB_STATUS_COMPLETED;
}

const doc = {
status: constants.JOB_STATUS_COMPLETED,
status: status,
tsullivan marked this conversation as resolved.
Show resolved Hide resolved
completed_at: completedTime,
output: docOutput,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import contentDisposition from 'content-disposition';
import * as _ from 'lodash';
import { CSV_JOB_TYPE } from '../../../common/constants';
import { ExportTypeDefinition, ExportTypesRegistry, JobDocOutput, JobSource } from '../../../types';
import { statuses } from '../../lib/esqueue/constants/statuses';
Copy link
Contributor

Choose a reason for hiding this comment

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

nice


interface ICustomHeaders {
[x: string]: any;
Expand Down Expand Up @@ -99,11 +100,11 @@ export function getDocumentPayloadFactory(exportTypesRegistry: ExportTypesRegist
const { status, jobtype: jobType, payload: { title } = { title: '' } } = doc._source;
const { output } = doc._source;

if (status === 'completed') {
if (status === statuses.JOB_STATUS_COMPLETED || status === statuses.JOB_STATUS_WARNINGS) {
return getCompleted(output, jobType, title);
}

if (status === 'failed') {
if (status === statuses.JOB_STATUS_FAILED) {
return getFailure(output);
}

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/reporting/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export const REPORTING_MANAGEMENT_HOME = '/app/kibana#/management/kibana/reporti
// Statuses
export const JOB_STATUS_FAILED = 'failed';
export const JOB_STATUS_COMPLETED = 'completed';
export const JOB_STATUS_WARNINGS = 'completed_with_warnings';

export enum JobStatuses {
PENDING = 'pending',
PROCESSING = 'processing',
COMPLETED = 'completed',
FAILED = 'failed',
CANCELLED = 'cancelled',
WARNINGS = 'completed_with_warnings',
}

// Types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Props = { record: ListingJob } & ListingProps;
export const ReportDownloadButton: FunctionComponent<Props> = (props: Props) => {
const { record, apiClient, intl } = props;

if (record.status !== JobStatuses.COMPLETED) {
if (!([JobStatuses.COMPLETED, JobStatuses.WARNINGS] as string[]).includes(record.status)) {
return null;
}

Expand Down
12 changes: 11 additions & 1 deletion x-pack/plugins/reporting/public/components/report_listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ const jobStatusLabelsMap = new Map<JobStatuses, string>([
defaultMessage: 'Completed',
}),
],
[
JobStatuses.WARNINGS,
i18n.translate('xpack.reporting.jobStatuses.warningText', {
defaultMessage: 'Completed with warnings',
}),
],
[
JobStatuses.FAILED,
i18n.translate('xpack.reporting.jobStatuses.failedText', {
Expand Down Expand Up @@ -410,7 +416,11 @@ class ReportListingUi extends Component<Props, State> {
statusTimestamp = this.formatDate(record.started_at);
} else if (
record.completed_at &&
(status === JobStatuses.COMPLETED || status === JobStatuses.FAILED)
([
JobStatuses.COMPLETED,
JobStatuses.FAILED,
JobStatuses.WARNINGS,
] as string[]).includes(status)
) {
statusTimestamp = this.formatDate(record.completed_at);
}
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/reporting/public/lib/stream_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY,
JOB_STATUS_COMPLETED,
JOB_STATUS_FAILED,
JOB_STATUS_WARNINGS,
} from '../../constants';

import {
Expand Down Expand Up @@ -112,7 +113,7 @@ export class ReportingNotifierStreamHandler {
_source: { status: jobStatus },
} = job;
if (storedJobs.includes(jobId)) {
if (jobStatus === JOB_STATUS_COMPLETED) {
if (jobStatus === JOB_STATUS_COMPLETED || JOB_STATUS_WARNINGS) {
completedJobs.push(summarizeJob(job));
} else if (jobStatus === JOB_STATUS_FAILED) {
failedJobs.push(summarizeJob(job));
Expand Down