Skip to content

Commit 0414532

Browse files
author
Joel Griffith
committed
Merge remote-tracking branch 'upstream/master' into reporting/np-migration-server-config
2 parents 412635e + 878ab20 commit 0414532

26 files changed

Lines changed: 788 additions & 422 deletions

x-pack/plugins/actions/server/builtin_action_types/servicenow/action_handlers.test.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,19 @@ describe('handleUpdateIncident', () => {
226226
const res = await handleUpdateIncident({
227227
incidentId: '123',
228228
serviceNow,
229-
params,
229+
params: {
230+
...params,
231+
updatedAt: '2020-03-15T08:34:53.450Z',
232+
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
233+
},
230234
comments: [],
231235
mapping: finalMapping,
232236
});
233237

234238
expect(serviceNow.updateIncident).toHaveBeenCalled();
235239
expect(serviceNow.updateIncident).toHaveBeenCalledWith('123', {
236-
short_description: 'a title (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
237-
description: 'a description (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
240+
short_description: 'a title (updated at 2020-03-15T08:34:53.450Z by Another User)',
241+
description: 'a description (updated at 2020-03-15T08:34:53.450Z by Another User)',
238242
});
239243
expect(serviceNow.updateIncident).toHaveReturned();
240244
expect(serviceNow.batchCreateComments).not.toHaveBeenCalled();
@@ -256,7 +260,11 @@ describe('handleUpdateIncident', () => {
256260
const res = await handleUpdateIncident({
257261
incidentId: '123',
258262
serviceNow,
259-
params,
263+
params: {
264+
...params,
265+
updatedAt: '2020-03-15T08:34:53.450Z',
266+
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
267+
},
260268
comments: [
261269
{
262270
comment: 'first comment',
@@ -278,10 +286,10 @@ describe('handleUpdateIncident', () => {
278286
fullName: 'Elastic User',
279287
username: 'elastic',
280288
},
281-
updatedAt: '2020-03-13T08:34:53.450Z',
289+
updatedAt: '2020-03-16T08:34:53.450Z',
282290
updatedBy: {
283-
fullName: 'Elastic User',
284-
username: 'elastic',
291+
fullName: 'Another User',
292+
username: 'anotherUser',
285293
},
286294
version: 'WzU3LDFd',
287295
},
@@ -291,8 +299,8 @@ describe('handleUpdateIncident', () => {
291299

292300
expect(serviceNow.updateIncident).toHaveBeenCalled();
293301
expect(serviceNow.updateIncident).toHaveBeenCalledWith('123', {
294-
description: 'a description (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
295-
short_description: 'a title (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
302+
description: 'a description (updated at 2020-03-15T08:34:53.450Z by Another User)',
303+
short_description: 'a title (updated at 2020-03-15T08:34:53.450Z by Another User)',
296304
});
297305
expect(serviceNow.updateIncident).toHaveReturned();
298306
expect(serviceNow.batchCreateComments).toHaveBeenCalled();
@@ -312,17 +320,17 @@ describe('handleUpdateIncident', () => {
312320
version: 'WzU3LDFd',
313321
},
314322
{
315-
comment: 'second comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
323+
comment: 'second comment (added at 2020-03-16T08:34:53.450Z by Another User)',
316324
commentId: '789',
317325
createdAt: '2020-03-13T08:34:53.450Z',
318326
createdBy: {
319327
fullName: 'Elastic User',
320328
username: 'elastic',
321329
},
322-
updatedAt: '2020-03-13T08:34:53.450Z',
330+
updatedAt: '2020-03-16T08:34:53.450Z',
323331
updatedBy: {
324-
fullName: 'Elastic User',
325-
username: 'elastic',
332+
fullName: 'Another User',
333+
username: 'anotherUser',
326334
},
327335
version: 'WzU3LDFd',
328336
},

x-pack/plugins/actions/server/builtin_action_types/servicenow/helpers.test.ts

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,31 @@ describe('transformFields', () => {
191191

192192
test('transform fields for update correctly', () => {
193193
const fields = prepareFieldsForTransformation({
194-
params: fullParams,
194+
params: {
195+
...fullParams,
196+
updatedAt: '2020-03-15T08:34:53.450Z',
197+
updatedBy: { username: 'anotherUser', fullName: 'Another User' },
198+
},
195199
mapping: finalMapping,
196200
defaultPipes: ['informationUpdated'],
197201
});
198202

199203
const res = transformFields({
200-
params: fullParams,
204+
params: {
205+
...fullParams,
206+
updatedAt: '2020-03-15T08:34:53.450Z',
207+
updatedBy: { username: 'anotherUser', fullName: 'Another User' },
208+
},
201209
fields,
202210
currentIncident: {
203211
short_description: 'first title (created at 2020-03-13T08:34:53.450Z by Elastic User)',
204212
description: 'first description (created at 2020-03-13T08:34:53.450Z by Elastic User)',
205213
},
206214
});
207215
expect(res).toEqual({
208-
short_description: 'a title (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
216+
short_description: 'a title (updated at 2020-03-15T08:34:53.450Z by Another User)',
209217
description:
210-
'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)',
218+
'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)',
211219
});
212220
});
213221

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

232-
test('append username if fullname is undefined', () => {
240+
test('append username if fullname is undefined when create', () => {
233241
const fields = prepareFieldsForTransformation({
234242
params: fullParams,
235243
mapping: finalMapping,
@@ -245,6 +253,32 @@ describe('transformFields', () => {
245253
description: 'a description (created at 2020-03-13T08:34:53.450Z by elastic)',
246254
});
247255
});
256+
257+
test('append username if fullname is undefined when update', () => {
258+
const fields = prepareFieldsForTransformation({
259+
params: {
260+
...fullParams,
261+
updatedAt: '2020-03-15T08:34:53.450Z',
262+
updatedBy: { username: 'anotherUser', fullName: 'Another User' },
263+
},
264+
mapping: finalMapping,
265+
defaultPipes: ['informationUpdated'],
266+
});
267+
268+
const res = transformFields({
269+
params: {
270+
...fullParams,
271+
updatedAt: '2020-03-15T08:34:53.450Z',
272+
updatedBy: { username: 'anotherUser', fullName: null },
273+
},
274+
fields,
275+
});
276+
277+
expect(res).toEqual({
278+
short_description: 'a title (updated at 2020-03-15T08:34:53.450Z by anotherUser)',
279+
description: 'a description (updated at 2020-03-15T08:34:53.450Z by anotherUser)',
280+
});
281+
});
248282
});
249283

250284
describe('appendField', () => {
@@ -330,20 +364,20 @@ describe('transformComments', () => {
330364
comment: 'first comment',
331365
createdAt: '2020-03-13T08:34:53.450Z',
332366
createdBy: { fullName: 'Elastic User', username: 'elastic' },
333-
updatedAt: null,
334-
updatedBy: null,
367+
updatedAt: '2020-03-15T08:34:53.450Z',
368+
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
335369
},
336370
];
337371
const res = transformComments(comments, fullParams, ['informationUpdated']);
338372
expect(res).toEqual([
339373
{
340374
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
341375
version: 'WzU3LDFd',
342-
comment: 'first comment (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
376+
comment: 'first comment (updated at 2020-03-15T08:34:53.450Z by Another User)',
343377
createdAt: '2020-03-13T08:34:53.450Z',
344378
createdBy: { fullName: 'Elastic User', username: 'elastic' },
345-
updatedAt: null,
346-
updatedBy: null,
379+
updatedAt: '2020-03-15T08:34:53.450Z',
380+
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
347381
},
348382
]);
349383
});

x-pack/plugins/actions/server/builtin_action_types/servicenow/helpers.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ export const transformFields = ({
8383
const transform = flow(...cur.pipes.map(p => t[p]));
8484
prev[cur.key] = transform({
8585
value: cur.value,
86-
date: params.createdAt,
87-
user: params.createdBy.fullName ?? params.createdBy.username,
86+
date: params.updatedAt ?? params.createdAt,
87+
user:
88+
params.updatedBy != null
89+
? params.updatedBy.fullName ?? params.updatedBy.username
90+
: params.createdBy.fullName ?? params.createdBy.username,
8891
previousValue: currentIncident ? currentIncident[cur.key] : '',
8992
}).value;
9093
return prev;
@@ -112,8 +115,11 @@ export const transformComments = (
112115
...c,
113116
comment: flow(...pipes.map(p => t[p]))({
114117
value: c.comment,
115-
date: c.createdAt,
116-
user: c.createdBy.fullName ?? '',
118+
date: c.updatedAt ?? c.createdAt,
119+
user:
120+
c.updatedBy != null
121+
? c.updatedBy.fullName ?? c.updatedBy.username
122+
: c.createdBy.fullName ?? c.createdBy.username,
117123
}).value,
118124
}));
119125
};

x-pack/plugins/actions/server/builtin_action_types/servicenow/index.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ describe('execute()', () => {
226226
const executorOptions: ActionTypeExecutorOptions = {
227227
actionId,
228228
config: mockOptions.config,
229-
params: { ...mockOptions.params, executorAction: 'updateIncident' },
229+
params: {
230+
...mockOptions.params,
231+
updatedAt: '2020-03-15T08:34:53.450Z',
232+
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
233+
},
230234
secrets: mockOptions.secrets,
231235
services,
232236
};
@@ -244,7 +248,11 @@ describe('execute()', () => {
244248
const executorOptions: ActionTypeExecutorOptions = {
245249
actionId,
246250
config: mockOptions.config,
247-
params: { ...mockOptions.params, executorAction: 'updateIncident' },
251+
params: {
252+
...mockOptions.params,
253+
updatedAt: '2020-03-15T08:34:53.450Z',
254+
updatedBy: { fullName: 'Another User', username: 'anotherUser' },
255+
},
248256
secrets: mockOptions.secrets,
249257
services,
250258
};

x-pack/plugins/infra/common/log_analysis/log_analysis.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,28 @@ export type JobStatus =
1414
| 'finished'
1515
| 'failed';
1616

17+
export type SetupStatusRequiredReason =
18+
| 'missing' // jobs are missing
19+
| 'reconfiguration' // the configurations don't match the source configurations
20+
| 'update'; // the definitions don't match the module definitions
21+
1722
export type SetupStatus =
18-
| 'initializing' // acquiring job statuses to determine setup status
19-
| 'unknown' // job status could not be acquired (failed request etc)
20-
| 'required' // jobs are missing
21-
| 'requiredForReconfiguration' // the configurations don't match the source configurations
22-
| 'requiredForUpdate' // the definitions don't match the module definitions
23-
| 'pending' // In the process of setting up the module for the first time or retrying, waiting for response
24-
| 'succeeded' // setup succeeded, notifying user
25-
| 'failed' // setup failed, notifying user
26-
| 'hiddenAfterSuccess' // hide the setup screen and we show the results for the first time
27-
| 'skipped' // setup hidden because the module is in a correct state already
28-
| 'skippedButReconfigurable' // setup hidden even though the job configurations are outdated
29-
| 'skippedButUpdatable'; // setup hidden even though the job definitions are outdated
23+
| { type: 'initializing' } // acquiring job statuses to determine setup status
24+
| { type: 'unknown' } // job status could not be acquired (failed request etc)
25+
| {
26+
type: 'required';
27+
reason: SetupStatusRequiredReason;
28+
} // setup required
29+
| { type: 'pending' } // In the process of setting up the module for the first time or retrying, waiting for response
30+
| { type: 'succeeded' } // setup succeeded, notifying user
31+
| {
32+
type: 'failed';
33+
reasons: string[];
34+
} // setup failed, notifying user
35+
| {
36+
type: 'skipped';
37+
newlyCreated?: boolean;
38+
}; // setup is hidden
3039

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

5057
const KIBANA_SAMPLE_DATA_INDICES = ['kibana_sample_data_logs*'];
5158

x-pack/plugins/infra/public/components/logging/log_analysis_job_status/log_analysis_job_problem_indicator.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,36 @@
66

77
import React from 'react';
88

9-
import { JobStatus, SetupStatus } from '../../../../common/log_analysis';
109
import { JobConfigurationOutdatedCallout } from './job_configuration_outdated_callout';
1110
import { JobDefinitionOutdatedCallout } from './job_definition_outdated_callout';
1211
import { JobStoppedCallout } from './job_stopped_callout';
12+
import { FirstUseCallout } from '../log_analysis_results';
1313

1414
export const LogAnalysisJobProblemIndicator: React.FC<{
15-
jobStatus: JobStatus;
16-
setupStatus: SetupStatus;
15+
hasOutdatedJobConfigurations: boolean;
16+
hasOutdatedJobDefinitions: boolean;
17+
hasStoppedJobs: boolean;
18+
isFirstUse: boolean;
1719
onRecreateMlJobForReconfiguration: () => void;
1820
onRecreateMlJobForUpdate: () => void;
19-
}> = ({ jobStatus, setupStatus, onRecreateMlJobForReconfiguration, onRecreateMlJobForUpdate }) => {
20-
if (isStopped(jobStatus)) {
21-
return <JobStoppedCallout />;
22-
} else if (isUpdatable(setupStatus)) {
23-
return <JobDefinitionOutdatedCallout onRecreateMlJob={onRecreateMlJobForUpdate} />;
24-
} else if (isReconfigurable(setupStatus)) {
25-
return <JobConfigurationOutdatedCallout onRecreateMlJob={onRecreateMlJobForReconfiguration} />;
26-
}
27-
28-
return null; // no problem to indicate
21+
}> = ({
22+
hasOutdatedJobConfigurations,
23+
hasOutdatedJobDefinitions,
24+
hasStoppedJobs,
25+
isFirstUse,
26+
onRecreateMlJobForReconfiguration,
27+
onRecreateMlJobForUpdate,
28+
}) => {
29+
return (
30+
<>
31+
{hasOutdatedJobDefinitions ? (
32+
<JobDefinitionOutdatedCallout onRecreateMlJob={onRecreateMlJobForUpdate} />
33+
) : null}
34+
{hasOutdatedJobConfigurations ? (
35+
<JobConfigurationOutdatedCallout onRecreateMlJob={onRecreateMlJobForReconfiguration} />
36+
) : null}
37+
{hasStoppedJobs ? <JobStoppedCallout /> : null}
38+
{isFirstUse ? <FirstUseCallout /> : null}
39+
</>
40+
);
2941
};
30-
31-
const isStopped = (jobStatus: JobStatus) => jobStatus === 'stopped';
32-
33-
const isUpdatable = (setupStatus: SetupStatus) => setupStatus === 'skippedButUpdatable';
34-
35-
const isReconfigurable = (setupStatus: SetupStatus) => setupStatus === 'skippedButReconfigurable';
36-
37-
export const jobHasProblem = (jobStatus: JobStatus, setupStatus: SetupStatus) =>
38-
isStopped(jobStatus) || isUpdatable(setupStatus) || isReconfigurable(setupStatus);

x-pack/plugins/infra/public/components/logging/log_analysis_setup/initial_configuration_step/initial_configuration_step.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const InitialConfigurationStep: React.FunctionComponent<InitialConfigurat
4545
setValidatedIndices,
4646
validationErrors = [],
4747
}: InitialConfigurationStepProps) => {
48-
const disabled = useMemo(() => !editableFormStatus.includes(setupStatus), [setupStatus]);
48+
const disabled = useMemo(() => !editableFormStatus.includes(setupStatus.type), [setupStatus]);
4949

5050
return (
5151
<>
@@ -72,12 +72,7 @@ export const InitialConfigurationStep: React.FunctionComponent<InitialConfigurat
7272
);
7373
};
7474

75-
const editableFormStatus = [
76-
'required',
77-
'requiredForReconfiguration',
78-
'requiredForUpdate',
79-
'failed',
80-
];
75+
const editableFormStatus = ['required', 'failed'];
8176

8277
const errorCalloutTitle = i18n.translate(
8378
'xpack.infra.analysisSetup.steps.initialConfigurationStep.errorCalloutTitle',

0 commit comments

Comments
 (0)