-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary Fixes two blockers: 1) Anomaly table would spin forever if you zero jobs configured on a fresh install. 2) If you get Network or ML errors this will report the error to the user in the form of the global toaster. Two examples of Error Toaster before the "See the full error(s)" is clicked: ![toast](https://user-images.githubusercontent.com/1151048/61415060-f2089200-a8ac-11e9-8293-3dfcdbbe069e.png) <img width="348" alt="Screen Shot 2019-07-17 at 4 04 30 PM" src="https://user-images.githubusercontent.com/1151048/61414971-ac4bc980-a8ac-11e9-9d15-28ab1229922f.png"> Example Error Toasters from start job expanded and collapsed: <img width="800" alt="Screen Shot 2019-07-17 at 12 15 04 PM" src="https://user-images.githubusercontent.com/1151048/61414610-9e497900-a8ab-11e9-97cd-ec68e77a555c.png"> <img width="808" alt="Screen Shot 2019-07-17 at 12 14 58 PM" src="https://user-images.githubusercontent.com/1151048/61414628-aacdd180-a8ab-11e9-8ad8-edc67deb8874.png"> Example Network Error Toaster: <img width="437" alt="Screen Shot 2019-07-17 at 12 21 10 PM" src="https://user-images.githubusercontent.com/1151048/61414635-b3260c80-a8ab-11e9-8e50-a35a05fc6d2b.png"> Example API Error if you send in something bad such as a bad payload: <img width="442" alt="Screen Shot 2019-07-17 at 12 34 04 PM" src="https://user-images.githubusercontent.com/1151048/61414658-c0db9200-a8ab-11e9-88ed-e6634f17103a.png"> Example Anomalies Table Error if you have a network issue: <img width="464" alt="Screen Shot 2019-07-17 at 12 39 57 PM" src="https://user-images.githubusercontent.com/1151048/61414691-cf29ae00-a8ab-11e9-882c-3cc770776f2f.png"> ### Checklist Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR. - [x] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md) - [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios - [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist) ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process) - [x] This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)
- Loading branch information
1 parent
919c22a
commit 48a2bd2
Showing
18 changed files
with
851 additions
and
301 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
x-pack/legacy/plugins/siem/public/components/ml/anomaly/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const SIEM_TABLE_FETCH_FAILURE = i18n.translate( | ||
'xpack.siem.components.ml.anomaly.errors.anomaliesTableFetchFailureTitle', | ||
{ | ||
defaultMessage: 'Anomalies table fetch failure', | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
x-pack/legacy/plugins/siem/public/components/ml/api/error_to_toaster.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { isAnError, isToasterError, errorToToaster } from './error_to_toaster'; | ||
import { ToasterErrors } from './throw_if_not_ok'; | ||
|
||
describe('error_to_toaster', () => { | ||
let dispatchToaster = jest.fn(); | ||
|
||
beforeEach(() => { | ||
dispatchToaster = jest.fn(); | ||
}); | ||
|
||
describe('#errorToToaster', () => { | ||
test('adds a ToastError given multiple toaster errors', () => { | ||
const error = new ToasterErrors(['some error 1', 'some error 2']); | ||
errorToToaster({ id: 'some-made-up-id', title: 'some title', error, dispatchToaster }); | ||
expect(dispatchToaster.mock.calls[0]).toEqual([ | ||
{ | ||
toast: { | ||
color: 'danger', | ||
errors: ['some error 1', 'some error 2'], | ||
iconType: 'alert', | ||
id: 'some-made-up-id', | ||
title: 'some title', | ||
}, | ||
type: 'addToaster', | ||
}, | ||
]); | ||
}); | ||
|
||
test('adds a ToastError given a single toaster errors', () => { | ||
const error = new ToasterErrors(['some error 1']); | ||
errorToToaster({ id: 'some-made-up-id', title: 'some title', error, dispatchToaster }); | ||
expect(dispatchToaster.mock.calls[0]).toEqual([ | ||
{ | ||
toast: { | ||
color: 'danger', | ||
errors: ['some error 1'], | ||
iconType: 'alert', | ||
id: 'some-made-up-id', | ||
title: 'some title', | ||
}, | ||
type: 'addToaster', | ||
}, | ||
]); | ||
}); | ||
|
||
test('adds a regular Error given a single error', () => { | ||
const error = new Error('some error 1'); | ||
errorToToaster({ id: 'some-made-up-id', title: 'some title', error, dispatchToaster }); | ||
expect(dispatchToaster.mock.calls[0]).toEqual([ | ||
{ | ||
toast: { | ||
color: 'danger', | ||
errors: ['some error 1'], | ||
iconType: 'alert', | ||
id: 'some-made-up-id', | ||
title: 'some title', | ||
}, | ||
type: 'addToaster', | ||
}, | ||
]); | ||
}); | ||
|
||
test('adds a generic Network Error given a non Error object such as a string', () => { | ||
const error = 'terrible string'; | ||
errorToToaster({ id: 'some-made-up-id', title: 'some title', error, dispatchToaster }); | ||
expect(dispatchToaster.mock.calls[0]).toEqual([ | ||
{ | ||
toast: { | ||
color: 'danger', | ||
errors: ['Network Error'], | ||
iconType: 'alert', | ||
id: 'some-made-up-id', | ||
title: 'some title', | ||
}, | ||
type: 'addToaster', | ||
}, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('#isAnError', () => { | ||
test('returns true if given an error object', () => { | ||
const error = new Error('some error'); | ||
expect(isAnError(error)).toEqual(true); | ||
}); | ||
|
||
test('returns false if given a regular object', () => { | ||
expect(isAnError({})).toEqual(false); | ||
}); | ||
|
||
test('returns false if given a string', () => { | ||
expect(isAnError('som string')).toEqual(false); | ||
}); | ||
|
||
test('returns true if given a toaster error', () => { | ||
const error = new ToasterErrors(['some error']); | ||
expect(isAnError(error)).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('#isToasterError', () => { | ||
test('returns true if given a ToasterErrors object', () => { | ||
const error = new ToasterErrors(['some error']); | ||
expect(isToasterError(error)).toEqual(true); | ||
}); | ||
|
||
test('returns false if given a regular object', () => { | ||
expect(isToasterError({})).toEqual(false); | ||
}); | ||
|
||
test('returns false if given a string', () => { | ||
expect(isToasterError('som string')).toEqual(false); | ||
}); | ||
|
||
test('returns false if given a regular error', () => { | ||
const error = new Error('some error'); | ||
expect(isToasterError(error)).toEqual(false); | ||
}); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
x-pack/legacy/plugins/siem/public/components/ml/api/error_to_toaster.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { isError } from 'lodash/fp'; | ||
import uuid from 'uuid'; | ||
import { ActionToaster, AppToast } from '../../toasters'; | ||
import { ToasterErrorsType, ToasterErrors } from './throw_if_not_ok'; | ||
|
||
export type ErrorToToasterArgs = Partial<AppToast> & { | ||
error: unknown; | ||
dispatchToaster: React.Dispatch<ActionToaster>; | ||
}; | ||
|
||
export const errorToToaster = ({ | ||
id = uuid.v4(), | ||
title, | ||
error, | ||
color = 'danger', | ||
iconType = 'alert', | ||
dispatchToaster, | ||
}: ErrorToToasterArgs) => { | ||
if (isToasterError(error)) { | ||
const toast: AppToast = { | ||
id, | ||
title, | ||
color, | ||
iconType, | ||
errors: error.messages, | ||
}; | ||
dispatchToaster({ | ||
type: 'addToaster', | ||
toast, | ||
}); | ||
} else if (isAnError(error)) { | ||
const toast: AppToast = { | ||
id, | ||
title, | ||
color, | ||
iconType, | ||
errors: [error.message], | ||
}; | ||
dispatchToaster({ | ||
type: 'addToaster', | ||
toast, | ||
}); | ||
} else { | ||
const toast: AppToast = { | ||
id, | ||
title, | ||
color, | ||
iconType, | ||
errors: ['Network Error'], | ||
}; | ||
dispatchToaster({ | ||
type: 'addToaster', | ||
toast, | ||
}); | ||
} | ||
}; | ||
|
||
export const isAnError = (error: unknown): error is Error => isError(error); | ||
|
||
export const isToasterError = (error: unknown): error is ToasterErrorsType => | ||
error instanceof ToasterErrors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.