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

[ML] Improving client side error handling #76743

Merged

Conversation

jgowdyelastic
Copy link
Member

@jgowdyelastic jgowdyelastic commented Sep 4, 2020

Fixes error reporting on the client side introduced by #74965 which caused changes to the error objects returned from kibana.

  • Updates extractErrorProperties to extract the error properties from the new error formats.
  • Removes older getErrorMessage function for converting the error to a string. Copies it to the transforms plugin where it is still used and was originally being imported from the ML plugin.
  • Removes mlMessageBarService, and replaces it with a similar function getToastNotificationService which uses the dependency cache for getting ToastsStart to retain backwards compatibility with all existing mlMessageBarService uses.
  • Adds the ability to override the error stack in MLRequestFailure. This allows for the correct error message to be displayed when clicking the See full error button in the toast.
    Previously it would show the client side JS stack, which was unrelated to the actual error.

Before:
image

After:
image

@jgowdyelastic
Copy link
Member Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@jgowdyelastic
Copy link
Member Author

@elasticmachine merge upstream

const { displayErrorToast } = toastNotificationServiceProvider(notifications.toasts);
displayErrorToast(
error,
i18n.translate('xpack.ml.newJob.wizard.summaryStep.createJobError', {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we meant for the same i18n id here but if we are using the same block for both places I wonder if we should consolidate them in one function.

Copy link
Member Author

Choose a reason for hiding this comment

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

these ids have always been the same, which surprises me, but i guess it doesn't complain if the ids are the same and the text is the same.
I'll remove the duplication.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed in 9027b2a

// takes an Error object and and optional response object
// if error is falsy (null) the response object will be used
// notify will show the full expandable stack trace of the response if a response object is used and no error is passed in.

constructor(error: any, resp: any) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can be more explicit here with the error: any since if error obj is required and if .message is undefined, the error message shown to the user will be blank.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in 430dbdb
I've also broken the error processing file into multiple files and moved the MLRequestFailure into common and changed it so it is no longer a subclass of KbnError, as it didn't gain us anything and meant it had to live in public.

@qn895
Copy link
Member

qn895 commented Sep 9, 2020

Gave this a quick test. I modified the names of the jobIds to test the delete operations and for some reasons it's showing success messages even though the jobs weren't deleted.

        if (datafeedResp.acknowledged) {
          try {
            await forceDeleteJob(`${jobId}_INVALID`);
            results[jobId] = { deleted: true };
          } catch (error) {...}

2020-09-09 at 10 28 AM

For starting invalid datafeed, I wonder if we should get rid of this 0 jobs started successfully. Perhaps out of scope of this PR.

Screen Shot 2020-09-09 at 10 37 14 AM

@jgowdyelastic
Copy link
Member Author

Gave this a quick test. I modified the names of the jobIds to test the delete operations and for some reasons it's showing success messages even though the jobs weren't deleted.

This is the same behaviour as master. The problem is that the jobs aren't really deleted at the point that the request returns. Instead they are deleted in tasks that happen later. We only get an acknowledgement that the delete request has gone through.
The success text could be updated here to something that reflects the real state of the deletion.
Similar to your other comment about the started success, I'd suggest these changes should be done in a follow up review of the success toasts.

@qn895
Copy link
Member

qn895 commented Sep 9, 2020

Changes LGTM 💯

@@ -83,12 +83,12 @@ export const useResultsViewConfig = (jobId: string) => {
setIsLoadingJobConfig(false);
}
} catch (e) {
setJobCapsServiceErrorMessage(getErrorMessage(e));
setJobCapsServiceErrorMessage(extractErrorMessage(e));
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 Sep 9, 2020

Choose a reason for hiding this comment

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

Noticed while testing this section that errors never get into this block when the error occurs in initializeFromIndexPattern since that function catches any error and logs it and does not propagate it. This means the results view table just fails silently and is empty. Maybe outside the scope of this PR but would be good to talk about whether the errors should be propagated somehow to code calling the service.

Once the error is propagated it does show up correctly so extractErrorMessage appears to be extracting things correctly. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

yes the errors probably should be propagated. initializeFromIndexPattern is called a few places and it's only here that we're expecting to catch anything.
I agree that it's outside of the scope of this PR, but definitely worth revisiting.

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a comment

Choose a reason for hiding this comment

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

Gave this a local test and LGTM ⚡

@peteharverson
Copy link
Contributor

Just found this one message which isn't displaying the reason for the error.

Test case is to use the Advanced Anomaly Detection wizard, and add two categorization detectors, with per-partition categorization enabled, but then pick a different partition field for each detector:

image

@jgowdyelastic
Copy link
Member Author

Just found this one message which isn't displaying the reason for the error.

Fixed in 8875cfa

image

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

LGTM

@jgowdyelastic
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
transform 459 +1 458

async chunks size

id value diff baseline
ml 8.0MB +207.0B 8.0MB
transform 759.6KB +273.0B 759.3KB
total +480.0B

page load bundle size

id value diff baseline
ml 844.8KB -2.9KB 847.8KB

distributable file count

id value diff baseline
default 45526 +4 45522

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jgowdyelastic jgowdyelastic merged commit ea8086b into elastic:master Sep 11, 2020
@jgowdyelastic jgowdyelastic deleted the improving-client-side-error-handling branch September 11, 2020 07:53
jgowdyelastic added a commit to jgowdyelastic/kibana that referenced this pull request Sep 11, 2020
* [ML] Improving client side error handling

* adding stacktrace to request errors

* copying error parsing to transforms

* update snapshot

* fixing jest tests

* adding test and removing debug log output

* updating translations

* rewriting error extracting code

* fixing tests

* removing message bar service

* removing test code

* updating translations

* combining job creation error handling

* refactoring error files

* updating test

* fixing bug in DFA deletion

* improving mml warning

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
jgowdyelastic added a commit that referenced this pull request Sep 11, 2020
* [ML] Improving client side error handling

* adding stacktrace to request errors

* copying error parsing to transforms

* update snapshot

* fixing jest tests

* adding test and removing debug log output

* updating translations

* rewriting error extracting code

* fixing tests

* removing message bar service

* removing test code

* updating translations

* combining job creation error handling

* refactoring error files

* updating test

* fixing bug in DFA deletion

* improving mml warning

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 14, 2020
…s-for-710

* 'master' of github.com:elastic/kibana: (65 commits)
  Separate url forwarding logic and legacy services (elastic#76892)
  Bump yargs-parser to v13.1.2+ (elastic#77009)
  [Ingest Manager] Shared Fleet agent policy action (elastic#76013)
  [Search] Re-add support for aborting when a connection is closed (elastic#76470)
  [Search] Remove long-running query pop-up (elastic#75385)
  [Monitoring] Fix UI error when alerting is not available (elastic#77179)
  do not log plugin id format warning in dist mode (elastic#77134)
  [ML] Improving client side error handling (elastic#76743)
  [Alerting][Connectors] Refactor IBM Resilient: Generic Implementation (phase one) (elastic#74357)
  [Docs] some basic searchsource api docs (elastic#77038)
  add  cGroupOverrides to the legacy config (elastic#77180)
  Change saved object bulkUpdate to work across multiple namespaces (elastic#75478)
  [Security Solution][Resolver] Replace Selectable popover with badges (elastic#76997)
  Removing ml-state index from archive (elastic#77143)
  [Security Solution] Add unit tests for histograms (elastic#77081)
  [Lens] Filters aggregation  (elastic#75635)
  [Enterprise Search] Update WS Overview logic to use new config data (elastic#77122)
  Cleanup type output before building new types (elastic#77211)
  [Security Solution] Use safe type in resolver backend (elastic#76969)
  Use proper lodash syntax (elastic#77105)
  ...

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/node_allocation.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants