Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into implement/dll…
Browse files Browse the repository at this point in the history
…-syntax-check
  • Loading branch information
spalger committed Mar 27, 2020
2 parents e8ebcb2 + 878ab20 commit d6f34bd
Show file tree
Hide file tree
Showing 26 changed files with 788 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,19 @@ describe('handleUpdateIncident', () => {
const res = await handleUpdateIncident({
incidentId: '123',
serviceNow,
params,
params: {
...params,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
},
comments: [],
mapping: finalMapping,
});

expect(serviceNow.updateIncident).toHaveBeenCalled();
expect(serviceNow.updateIncident).toHaveBeenCalledWith('123', {
short_description: 'a title (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
description: 'a description (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
short_description: 'a title (updated at 2020-03-15T08:34:53.450Z by Another User)',
description: 'a description (updated at 2020-03-15T08:34:53.450Z by Another User)',
});
expect(serviceNow.updateIncident).toHaveReturned();
expect(serviceNow.batchCreateComments).not.toHaveBeenCalled();
Expand All @@ -256,7 +260,11 @@ describe('handleUpdateIncident', () => {
const res = await handleUpdateIncident({
incidentId: '123',
serviceNow,
params,
params: {
...params,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
},
comments: [
{
comment: 'first comment',
Expand All @@ -278,10 +286,10 @@ describe('handleUpdateIncident', () => {
fullName: 'Elastic User',
username: 'elastic',
},
updatedAt: '2020-03-13T08:34:53.450Z',
updatedAt: '2020-03-16T08:34:53.450Z',
updatedBy: {
fullName: 'Elastic User',
username: 'elastic',
fullName: 'Another User',
username: 'anotherUser',
},
version: 'WzU3LDFd',
},
Expand All @@ -291,8 +299,8 @@ describe('handleUpdateIncident', () => {

expect(serviceNow.updateIncident).toHaveBeenCalled();
expect(serviceNow.updateIncident).toHaveBeenCalledWith('123', {
description: 'a description (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
short_description: 'a title (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
description: 'a description (updated at 2020-03-15T08:34:53.450Z by Another User)',
short_description: 'a title (updated at 2020-03-15T08:34:53.450Z by Another User)',
});
expect(serviceNow.updateIncident).toHaveReturned();
expect(serviceNow.batchCreateComments).toHaveBeenCalled();
Expand All @@ -312,17 +320,17 @@ describe('handleUpdateIncident', () => {
version: 'WzU3LDFd',
},
{
comment: 'second comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
comment: 'second comment (added at 2020-03-16T08:34:53.450Z by Another User)',
commentId: '789',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: {
fullName: 'Elastic User',
username: 'elastic',
},
updatedAt: '2020-03-13T08:34:53.450Z',
updatedAt: '2020-03-16T08:34:53.450Z',
updatedBy: {
fullName: 'Elastic User',
username: 'elastic',
fullName: 'Another User',
username: 'anotherUser',
},
version: 'WzU3LDFd',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,31 @@ describe('transformFields', () => {

test('transform fields for update correctly', () => {
const fields = prepareFieldsForTransformation({
params: fullParams,
params: {
...fullParams,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { username: 'anotherUser', fullName: 'Another User' },
},
mapping: finalMapping,
defaultPipes: ['informationUpdated'],
});

const res = transformFields({
params: fullParams,
params: {
...fullParams,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { username: 'anotherUser', fullName: 'Another User' },
},
fields,
currentIncident: {
short_description: 'first title (created at 2020-03-13T08:34:53.450Z by Elastic User)',
description: 'first description (created at 2020-03-13T08:34:53.450Z by Elastic User)',
},
});
expect(res).toEqual({
short_description: 'a title (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
short_description: 'a title (updated at 2020-03-15T08:34:53.450Z by Another User)',
description:
'first description (created at 2020-03-13T08:34:53.450Z by Elastic User) \r\na description (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
'first description (created at 2020-03-13T08:34:53.450Z by Elastic User) \r\na description (updated at 2020-03-15T08:34:53.450Z by Another User)',
});
});

Expand All @@ -229,7 +237,7 @@ describe('transformFields', () => {
expect(res.description?.includes('\r\n')).toBe(true);
});

test('append username if fullname is undefined', () => {
test('append username if fullname is undefined when create', () => {
const fields = prepareFieldsForTransformation({
params: fullParams,
mapping: finalMapping,
Expand All @@ -245,6 +253,32 @@ describe('transformFields', () => {
description: 'a description (created at 2020-03-13T08:34:53.450Z by elastic)',
});
});

test('append username if fullname is undefined when update', () => {
const fields = prepareFieldsForTransformation({
params: {
...fullParams,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { username: 'anotherUser', fullName: 'Another User' },
},
mapping: finalMapping,
defaultPipes: ['informationUpdated'],
});

const res = transformFields({
params: {
...fullParams,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { username: 'anotherUser', fullName: null },
},
fields,
});

expect(res).toEqual({
short_description: 'a title (updated at 2020-03-15T08:34:53.450Z by anotherUser)',
description: 'a description (updated at 2020-03-15T08:34:53.450Z by anotherUser)',
});
});
});

describe('appendField', () => {
Expand Down Expand Up @@ -330,20 +364,20 @@ describe('transformComments', () => {
comment: 'first comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
updatedAt: null,
updatedBy: null,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
},
];
const res = transformComments(comments, fullParams, ['informationUpdated']);
expect(res).toEqual([
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
comment: 'first comment (updated at 2020-03-15T08:34:53.450Z by Another User)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
updatedAt: null,
updatedBy: null,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ export const transformFields = ({
const transform = flow(...cur.pipes.map(p => t[p]));
prev[cur.key] = transform({
value: cur.value,
date: params.createdAt,
user: params.createdBy.fullName ?? params.createdBy.username,
date: params.updatedAt ?? params.createdAt,
user:
params.updatedBy != null
? params.updatedBy.fullName ?? params.updatedBy.username
: params.createdBy.fullName ?? params.createdBy.username,
previousValue: currentIncident ? currentIncident[cur.key] : '',
}).value;
return prev;
Expand Down Expand Up @@ -112,8 +115,11 @@ export const transformComments = (
...c,
comment: flow(...pipes.map(p => t[p]))({
value: c.comment,
date: c.createdAt,
user: c.createdBy.fullName ?? '',
date: c.updatedAt ?? c.createdAt,
user:
c.updatedBy != null
? c.updatedBy.fullName ?? c.updatedBy.username
: c.createdBy.fullName ?? c.createdBy.username,
}).value,
}));
};
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ describe('execute()', () => {
const executorOptions: ActionTypeExecutorOptions = {
actionId,
config: mockOptions.config,
params: { ...mockOptions.params, executorAction: 'updateIncident' },
params: {
...mockOptions.params,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
},
secrets: mockOptions.secrets,
services,
};
Expand All @@ -244,7 +248,11 @@ describe('execute()', () => {
const executorOptions: ActionTypeExecutorOptions = {
actionId,
config: mockOptions.config,
params: { ...mockOptions.params, executorAction: 'updateIncident' },
params: {
...mockOptions.params,
updatedAt: '2020-03-15T08:34:53.450Z',
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
},
secrets: mockOptions.secrets,
services,
};
Expand Down
37 changes: 22 additions & 15 deletions x-pack/plugins/infra/common/log_analysis/log_analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@ export type JobStatus =
| 'finished'
| 'failed';

export type SetupStatusRequiredReason =
| 'missing' // jobs are missing
| 'reconfiguration' // the configurations don't match the source configurations
| 'update'; // the definitions don't match the module definitions

export type SetupStatus =
| 'initializing' // acquiring job statuses to determine setup status
| 'unknown' // job status could not be acquired (failed request etc)
| 'required' // jobs are missing
| 'requiredForReconfiguration' // the configurations don't match the source configurations
| 'requiredForUpdate' // the definitions don't match the module definitions
| 'pending' // In the process of setting up the module for the first time or retrying, waiting for response
| 'succeeded' // setup succeeded, notifying user
| 'failed' // setup failed, notifying user
| 'hiddenAfterSuccess' // hide the setup screen and we show the results for the first time
| 'skipped' // setup hidden because the module is in a correct state already
| 'skippedButReconfigurable' // setup hidden even though the job configurations are outdated
| 'skippedButUpdatable'; // setup hidden even though the job definitions are outdated
| { type: 'initializing' } // acquiring job statuses to determine setup status
| { type: 'unknown' } // job status could not be acquired (failed request etc)
| {
type: 'required';
reason: SetupStatusRequiredReason;
} // setup required
| { type: 'pending' } // In the process of setting up the module for the first time or retrying, waiting for response
| { type: 'succeeded' } // setup succeeded, notifying user
| {
type: 'failed';
reasons: string[];
} // setup failed, notifying user
| {
type: 'skipped';
newlyCreated?: boolean;
}; // setup is hidden

/**
* Maps a job status to the possibility that results have already been produced
Expand All @@ -43,9 +52,7 @@ export const isHealthyJobStatus = (jobStatus: JobStatus) =>
* produced before this state was reached.
*/
export const isSetupStatusWithResults = (setupStatus: SetupStatus) =>
['skipped', 'hiddenAfterSuccess', 'skippedButReconfigurable', 'skippedButUpdatable'].includes(
setupStatus
);
setupStatus.type === 'skipped';

const KIBANA_SAMPLE_DATA_INDICES = ['kibana_sample_data_logs*'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,36 @@

import React from 'react';

import { JobStatus, SetupStatus } from '../../../../common/log_analysis';
import { JobConfigurationOutdatedCallout } from './job_configuration_outdated_callout';
import { JobDefinitionOutdatedCallout } from './job_definition_outdated_callout';
import { JobStoppedCallout } from './job_stopped_callout';
import { FirstUseCallout } from '../log_analysis_results';

export const LogAnalysisJobProblemIndicator: React.FC<{
jobStatus: JobStatus;
setupStatus: SetupStatus;
hasOutdatedJobConfigurations: boolean;
hasOutdatedJobDefinitions: boolean;
hasStoppedJobs: boolean;
isFirstUse: boolean;
onRecreateMlJobForReconfiguration: () => void;
onRecreateMlJobForUpdate: () => void;
}> = ({ jobStatus, setupStatus, onRecreateMlJobForReconfiguration, onRecreateMlJobForUpdate }) => {
if (isStopped(jobStatus)) {
return <JobStoppedCallout />;
} else if (isUpdatable(setupStatus)) {
return <JobDefinitionOutdatedCallout onRecreateMlJob={onRecreateMlJobForUpdate} />;
} else if (isReconfigurable(setupStatus)) {
return <JobConfigurationOutdatedCallout onRecreateMlJob={onRecreateMlJobForReconfiguration} />;
}

return null; // no problem to indicate
}> = ({
hasOutdatedJobConfigurations,
hasOutdatedJobDefinitions,
hasStoppedJobs,
isFirstUse,
onRecreateMlJobForReconfiguration,
onRecreateMlJobForUpdate,
}) => {
return (
<>
{hasOutdatedJobDefinitions ? (
<JobDefinitionOutdatedCallout onRecreateMlJob={onRecreateMlJobForUpdate} />
) : null}
{hasOutdatedJobConfigurations ? (
<JobConfigurationOutdatedCallout onRecreateMlJob={onRecreateMlJobForReconfiguration} />
) : null}
{hasStoppedJobs ? <JobStoppedCallout /> : null}
{isFirstUse ? <FirstUseCallout /> : null}
</>
);
};

const isStopped = (jobStatus: JobStatus) => jobStatus === 'stopped';

const isUpdatable = (setupStatus: SetupStatus) => setupStatus === 'skippedButUpdatable';

const isReconfigurable = (setupStatus: SetupStatus) => setupStatus === 'skippedButReconfigurable';

export const jobHasProblem = (jobStatus: JobStatus, setupStatus: SetupStatus) =>
isStopped(jobStatus) || isUpdatable(setupStatus) || isReconfigurable(setupStatus);
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const InitialConfigurationStep: React.FunctionComponent<InitialConfigurat
setValidatedIndices,
validationErrors = [],
}: InitialConfigurationStepProps) => {
const disabled = useMemo(() => !editableFormStatus.includes(setupStatus), [setupStatus]);
const disabled = useMemo(() => !editableFormStatus.includes(setupStatus.type), [setupStatus]);

return (
<>
Expand All @@ -72,12 +72,7 @@ export const InitialConfigurationStep: React.FunctionComponent<InitialConfigurat
);
};

const editableFormStatus = [
'required',
'requiredForReconfiguration',
'requiredForUpdate',
'failed',
];
const editableFormStatus = ['required', 'failed'];

const errorCalloutTitle = i18n.translate(
'xpack.infra.analysisSetup.steps.initialConfigurationStep.errorCalloutTitle',
Expand Down
Loading

0 comments on commit d6f34bd

Please sign in to comment.