-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[SIEM] Add toaster logic for Machine Learning #41401
[SIEM] Add toaster logic for Machine Learning #41401
Conversation
x-pack/legacy/plugins/siem/public/components/ml/api/throw_if_not_ok.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/public/components/ml/api/throw_if_not_ok.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/public/components/ml/api/throw_if_not_ok.ts
Outdated
Show resolved
Hide resolved
💚 Build Succeeded |
x-pack/legacy/plugins/siem/public/components/ml/anomaly/use_anomalies_table_data.ts
Show resolved
Hide resolved
import { ToasterErrorsType, ToasterErrors } from './throw_if_not_ok'; | ||
|
||
export type ErrorToToasterArgs = Partial<AppToast> & { | ||
error: unknown; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ on the unknown
here! And thanks for the reading material -- good stuff!
x-pack/legacy/plugins/siem/public/components/ml/api/throw_if_not_ok.ts
Outdated
Show resolved
Hide resolved
}); | ||
|
||
await throwIfNotOk(closeJobsResponse); | ||
return [stopDatafeedsResponseJson, await closeJobsResponse.json()]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file cleaned up real well with the way you've structured you're error reporting -- very nice! 👏
x-pack/legacy/plugins/siem/public/components/ml_popover/translations.ts
Outdated
Show resolved
Hide resolved
Pinging @elastic/secops |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performed code review, checked out, tested locally against an Elastic Cloud 7.3.0 BC4 deployment in all browsers (Chrome, FF, Safari & IE11), and was getting errors everywhere expected. Did additional testing with multiple ml_nodes, disabling nodes while jobs were running, and so on and so forth and everything is looked good. LGTM 👍
💚 Build Succeeded |
* Initial toaster logic * Updated toaster error handling * Cleanups of code not used * Added i18n support * Added missing i18n keys and fixed the name spaces of all of them * Added unit test * Added the rest of the unit tests * Updated from feedback from the PR review * Fix capitalization issue
* Initial toaster logic * Updated toaster error handling * Cleanups of code not used * Added i18n support * Added missing i18n keys and fixed the name spaces of all of them * Added unit test * Added the rest of the unit tests * Updated from feedback from the PR review * Fix capitalization issue
## 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)
## 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)
@@ -75,6 +79,7 @@ export const useAnomaliesTableData = ({ | |||
const config = useContext(KibanaConfigContext); | |||
const capabilities = useContext(MlCapabilitiesContext); | |||
const userPermissions = hasMlUserPermissions(capabilities); | |||
const [, dispatchToaster] = useStateToaster(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit -I am used to see it the other way around like const dispatchToaster = useStateToaster()[1];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing wrong with that way since it is valid ts/js, but in the all the videos for React Hooks, including the introduction of them, they use array destructoring which is the reasoning for my choice.
Let me know if I'm not seeing something with the tutorials or others that have hooks which use array indexes over destructoring as I am curious.
iconType = 'alert', | ||
dispatchToaster, | ||
}: ErrorToToasterArgs) => { | ||
if (isToasterError(error)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, I think that you can simplify it like that
const toast: AppToast = {
id,
title,
color,
iconType,
errors: ['Network Error'],
};
if (isToasterError(error)) {
toast.errors = error.messages;
} else if (isAnError(error)) {
toast.errors = [error.message];
}
dispatchToaster({
type: 'addToaster',
toast,
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate it, I will try to work it into a follow up PR 🤞 here soon.
Thank you for looking at my PR Xavier and giving me feedback.
Summary
Fixes two blockers:
Anomaly table would spin forever if you zero jobs configured on a fresh install.
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:
Example Error Toasters from start job expanded and collapsed:
Example Network Error Toaster:
Example API Error if you send in something bad such as a bad payload:
Example Anomalies Table Error if you have a network issue:
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.For maintainers