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

[Vega] Better error explanation for EsErrors and inspector now showing error responses #112634

Merged
merged 10 commits into from
Sep 23, 2021

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Sep 21, 2021

Summary

Fixes #106478

This PR addresses two main bugs in Vega:

  • When showing an EsError it now produces a better explanation of what it gone wrong

Screenshot 2021-09-20 at 19 19 26

  • The inspector panel will show the response tab even when the something has gone wrong

Screenshot 2021-09-21 at 09 10 54

Screenshot 2021-09-21 at 09 11 00

Note: part of the fix here comes from the Lens error formatter. It would be nice to port most of the Lens error helpers logic into the data/search plugin in order to provide better error feedback for all Kibana.

Checklist

Delete any items that are not applicable to this PR.

@dej611 dej611 added release_note:fix Feature:Vega Vega visualizations Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 auto-backport Deprecated - use backport:version if exact versions are needed v7.16.0 labels Sep 21, 2021
@dej611 dej611 marked this pull request as ready for review September 21, 2021 10:03
@dej611 dej611 requested review from a team as code owners September 21, 2021 10:03
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors (Team:VisEditors)

@stratoula stratoula requested a review from alexwizp September 21, 2021 10:31
@@ -17,7 +17,7 @@ export class EsError extends KbnError {
readonly attributes: IEsError['attributes'];

constructor(protected readonly err: IEsError) {
super('EsError');
super(`EsError: ${getRootCause(err)?.reason || err.attributes?.reason || 'unknown'}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

just interesting is || err.attributes?.reason needed? I see that case is handled in getRootCause -> getNestedCause.

requestResponders[requestId]
);
// now throw it again as the Vega parser will catch it and carry on with its flow
return throwError(err);
Copy link
Contributor

@alexwizp alexwizp Sep 21, 2021

Choose a reason for hiding this comment

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

nit: what if we continue to inspect search results as a side effects without modifying the main stream. I don't insist but I think the following code is more semantically right

tap(
 (data) => this.inspectSearchResult(data, requestResponders[requestId]),
 (err) =>
   this.inspectSearchResult(
    {
      rawResponse: 'err' in err ? err.err : undefined,
     },
      requestResponders[requestId]
   )
)

// catch the error and log it into the inspector
this.inspectSearchResult(
{
rawResponse: 'err' in err ? err.err : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: what if we replace it to err?.err

@@ -15,6 +15,15 @@ export function getFailedShards(err: KibanaServerError<any>): FailedShard | unde
return failedShards ? failedShards[0] : undefined;
}

function getNestedCause(err: KibanaServerError<any>): Reason {
Copy link
Contributor

@alexwizp alexwizp Sep 21, 2021

Choose a reason for hiding this comment

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

nit: you call getNestedCause from getRootCause. In parent method I see KibanaServerError instead of KibanaServerError<any>. I think we can remove <any>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thought about that.
But removing the any will set the generic T to unknown with types errors that need to be addressed. I think this is a major problem with EsErrors that should be addressed in another PR by providing better types.

Copy link
Contributor

@alexwizp alexwizp left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

I love this PR! LGTM, works like a charm :D

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

@dej611 this is a great improvement that will definitely help a lot of users!

I have one suggestion about avoiding the use of any that I'd like to get your thoughts on. Let me know what you think!

@@ -17,7 +17,7 @@ export class EsError extends KbnError {
readonly attributes: IEsError['attributes'];

constructor(protected readonly err: IEsError) {
super('EsError');
super(`EsError: ${getRootCause(err)?.reason || 'unknown'}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is user-facing, we should consider translation:

i18n.translate('...', { defaultMessage: 'unknown' })

Comment on lines 18 to 19
function getNestedCause(err: KibanaServerError<any>): Reason {
const { type, reason, caused_by: causedBy } = err.attributes || err;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid introducing additional anys. Here is a possible alternative:

import type { ErrorCause } from '@elastic/elasticsearch/api/types';
...
function getNestedCause(err: KibanaServerError | ErrorCause): Reason {
  const attr = ((err as KibanaServerError).attributes || err) as ErrorCause;
  const { type, reason, caused_by: causedBy } = attr;
  if (causedBy) {
    return getNestedCause(causedBy);
  }
  return { type, reason };
}

We could improve KibanaServerError by defaulting the generic to ErrorCause. I'll open up an issue so that we can discuss that change separately. We could also add a new isKibanaServerError predicate to avoid using as as an improvement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. There's some more type work to do, in Lens we did inspect quite a bit the EsError shape (for our use cases) but the type error source is not precise itself (I've discussed with @delvedor before about mapping all possible EsError in types but it's a big task to tackle right now).

It's definitely possible to patch this now and open a discussion about error types improvement later on.

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my feedback @dej611 !

Did not test this locally but code changes look good to me!

@dej611
Copy link
Contributor Author

dej611 commented Sep 22, 2021

@elasticmachine merge upstream

@dej611
Copy link
Contributor Author

dej611 commented Sep 22, 2021

Let's give it another round of tests.

@dej611
Copy link
Contributor Author

dej611 commented Sep 22, 2021

jenkins, test this

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 492.3KB 492.5KB +243.0B
visTypeVega 35.8KB 35.9KB +69.0B
total +312.0B

History

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

@dej611 dej611 merged commit 9dcacf7 into elastic:master Sep 23, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Sep 23, 2021
…g error responses (elastic#112634)

* 🐛 Fix EsError not showing info

* 🐛 Record error response in the inspector

* 🏷️ Fix type issue

* 👌 Integrate feedback

* 👌 Integrated latest feedback

* 👌 i18n unknwon message

* 👌 Integrate feedback

* 🐛 Fix syntax error

* 🏷️ Fix type issue

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Sep 23, 2021
…g error responses (#112634) (#112932)

* 🐛 Fix EsError not showing info

* 🐛 Record error response in the inspector

* 🏷️ Fix type issue

* 👌 Integrate feedback

* 👌 Integrated latest feedback

* 👌 i18n unknwon message

* 👌 Integrate feedback

* 🐛 Fix syntax error

* 🏷️ Fix type issue

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Vega Vega visualizations release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.16.0 v8.0.0
Projects
None yet
6 participants