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

Expressions service fixes: better error and loading states handling #51183

Merged

Conversation

Dosant
Copy link
Contributor

@Dosant Dosant commented Nov 20, 2019

Summary

1. This pr fixes regression in v7.6 - #51153.

Visualisation which are using ExpressionLoader directly are swallowing render errors in 7.6, because generic error handling is happening only on expression_renderer.tsx level (react component wrapper around renderer).

Now react agnostic render code render.ts, loader.ts:

  • has it's own default error handler which is toast from notification service.
  • It also allows to pass custom error handler instead of default one

React expression renderer expression_renderer.tsx:

  • if consumer wants to render error as react component inline, then the component uses custom error handler from render.ts to wire up react component.

The pr also adds unsubscribes from ExpressionLoader observable in expression_renderer.tsx

Screenshot 2019-11-20 at 18 12 23
Screenshot 2019-11-20 at 17 16 38

2. This pr fixes issue of loader.ts where initial loading$ was not emitted

Had to change loadingSubject from Subject to BehaviorSubject to remember the last value

3. This pr fixes dependencies in effects of expression_renderer.tsx

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@elasticmachine
Copy link
Contributor

💔 Build Failed

@Dosant Dosant force-pushed the bugfix/expression-service-render-swallows-errors branch from f7730c3 to 88a753a Compare November 21, 2019 10:18
@Dosant Dosant added bug Fixes for quality problems that affect the customer experience Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Team:AppArch v7.6.0 v8.0.0 labels Nov 21, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@Dosant Dosant marked this pull request as ready for review November 21, 2019 10:22
@Dosant Dosant requested a review from a team as a code owner November 21, 2019 10:22
@Dosant Dosant added the review label Nov 21, 2019
@Dosant Dosant added the release_note:skip Skip the PR/issue when compiling release notes label Nov 21, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

prettier

remove error$ and errorRenderer, use onRenderError callback instead for both

use custom error handler only if it is provided by consumer, otherwise fallback to default handler

add comment

fix linter issues

fix
move utilities to kibana_react/util
@Dosant Dosant force-pushed the bugfix/expression-service-render-swallows-errors branch from d814bd0 to 21d8c9c Compare November 22, 2019 14:03
renderError ? (
renderError(state.error.message)
) : (
<div data-test-subj="expression-renderer-error">{state.error.message}</div>
Copy link
Contributor Author

@Dosant Dosant Nov 22, 2019

Choose a reason for hiding this comment

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

  1. Default error state now fallbacks to default of render.ts which is toast from notification service
  2. If user of this react component provided renderErrorfunction, then the component itself will handle the error and will render the error component returned from renderError()

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@Dosant Dosant changed the title fix expressions service render swallows rendering errors #51153 Expressions service fixes: better error and loading states handling Nov 22, 2019
@Dosant
Copy link
Contributor Author

Dosant commented Nov 25, 2019

@elasticmachine merge upstream

@@ -64,9 +72,14 @@ export class ExpressionLoader {
this.render(data);
});

this.render$.subscribe(() => {
this.loadingSubject.next(false);
Copy link
Member

Choose a reason for hiding this comment

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

are we emitting false now after loading has completed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I left the public observable the same,
This is done due to:

this.loading$ = this.loadingSubject.asObservable().pipe(
       filter(_ => _ === true),
       map(() => void 0)
     );

// as loading$ could emit straight away in the constructor
// and we want to notify subscribers about it, but all subscriptions will happen later
this.loading$ = this.loadingSubject.asObservable().pipe(
filter(_ => _ === true),
Copy link
Member

Choose a reason for hiding this comment

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

can you please explain why we need boolean observable, where we then filter out all the falses and map trues to void ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intention was to leave public api (loading$) unchanged in this pr and just fix the bug where expression_renderer.tsx was missing initial loading state. This was fixed by changing Subject to BehaviourSubject to remember last emitted value

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

This looks like it's changing the default behavior of the error handler when the expression fails to render. Try going to Lens and configuring only a Y axis.

expect(instance.find(EuiProgress)).toHaveLength(0);
});

it('should display an error message when the expression fails', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You've changed the behavior this test was testing- why?

Copy link
Contributor Author

@Dosant Dosant Nov 26, 2019

Choose a reason for hiding this comment

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

Default error handling of expression_renderer.tsx now fallbacks to default error handling of render.ts. This was done primarily to reduce number of code paths to support.

Pls see: https://github.com/elastic/kibana/pull/51183/files#r349611820

And that is why test was deleted as we have less code paths in this component.

This looks like it's changing the default behavior of the error handler when the expression fails to render. Try going to Lens and configuring only a Y axis.

I guess I indeed missing the change, where I had to explicitly override error handling, where previous default of expression_renderer.tsx was expected.
I found one missing place here: x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/expression_wrapper.tsx and added error override, but as I understand this is for dashboard page?
9a3282f
Any other places I am missing?

Try going to Lens and configuring only a Y axis.

I am likely doing it wrong, but I think I am getting the same behaviour as in master. Blank screen. Any suggestions?

@Dosant Dosant requested a review from a team November 26, 2019 11:19
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

…sion-service-render-swallows-errors

# Conflicts:
#	src/plugins/expressions/public/render.ts
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

I was wrong about the state of master, this is not changing the behavior. LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@Dosant
Copy link
Contributor Author

Dosant commented Nov 27, 2019

@elasticmachine merge upstream

@Dosant Dosant added the v7.7.0 label Nov 27, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@Dosant Dosant merged commit 0fd63ee into elastic:master Nov 27, 2019
@Dosant Dosant deleted the bugfix/expression-service-render-swallows-errors branch November 27, 2019 09:55
Dosant added a commit to Dosant/kibana that referenced this pull request Nov 27, 2019
…lastic#51183)

1. This pr fixes regression in v7.6 - elastic#51153.

Visualisation which are using ExpressionLoader directly are swallowing render errors in 7.6, because generic error handling is happening only on expression_renderer.tsx level (react component wrapper around renderer).

Now react agnostic render code render.ts, loader.ts:

has it's own default error handler which is toast from notification service.
It also allows to pass custom error handler instead of default one
React expression renderer expression_renderer.tsx:

if consumer wants to render error as react component inline, then the component uses custom error handler from render.ts to wire up react component.

2. This pr fixes issue of loader.ts where initial loading$ was not emitted

Had to change loadingSubject from Subject to BehaviorSubject to remember the last value

3. This pr fixes dependencies in effects of expression_renderer.tsx
# Conflicts:
#	src/plugins/expressions/public/loader.test.ts
Dosant added a commit that referenced this pull request Nov 27, 2019
…51183) (#51800)

1. This pr fixes regression in v7.6 - #51153.

Visualisation which are using ExpressionLoader directly are swallowing render errors in 7.6, because generic error handling is happening only on expression_renderer.tsx level (react component wrapper around renderer).

Now react agnostic render code render.ts, loader.ts:

has it's own default error handler which is toast from notification service.
It also allows to pass custom error handler instead of default one
React expression renderer expression_renderer.tsx:

if consumer wants to render error as react component inline, then the component uses custom error handler from render.ts to wire up react component.

2. This pr fixes issue of loader.ts where initial loading$ was not emitted

Had to change loadingSubject from Subject to BehaviorSubject to remember the last value

3. This pr fixes dependencies in effects of expression_renderer.tsx
# Conflicts:
#	src/plugins/expressions/public/loader.test.ts
jloleysens added a commit to jloleysens/kibana that referenced this pull request Nov 27, 2019
* upstream/7.x:
  Fix infinite redirect loop when multiple cookies are sent (elastic#50452) (elastic#51821)
  [Console] Proxy fallback (elastic#50185) (elastic#51814)
  Added endgame-* index and new heading 3 Elastic Endpoint SMP. (elastic#51071) (elastic#51828)
  [Maps] Added options to disable zoom, hide tool tips, widgets/overlays in embeddable maps (elastic#50663) (elastic#51811)
  Move errors and validate index pattern ⇒ NP (elastic#51805) (elastic#51831)
  [SIEM][Detection Engine] Adds ecs threat properties to rules (elastic#51782) (elastic#51827)
  [Lens] Remove client-side reference to server source code (elastic#51763) (elastic#51825)
  fixes drag and drop in tests (elastic#51806) (elastic#51813)
  [Uptime] Redesign/44541  new monitor list expanded row (elastic#46567) (elastic#51809)
  [7.x] [Telemetry] collector set to np (elastic#51618) (elastic#51787)
  [Uptime] added test for chart wrapper (elastic#50399) (elastic#51808)
  Expressions service fixes: better error and loading states handling (elastic#51183) (elastic#51800)
  Query String(Bar) Input - cleanup (elastic#51598) (elastic#51804)
  [ML] Adjust and re-enable categorization advanced wizard test (elastic#51005) (elastic#51017)
  fixes url state tests (elastic#51746) (elastic#51798)
  fixes browser field tests (elastic#51738) (elastic#51799)
  [Task Manager] Tests for the ability to run tasks of varying durations in parallel (elastic#51572) (elastic#51701)
  [ML] Fix anomaly detection test suite (elastic#51712) (elastic#51795)
  [SIEM] Fix Timeline drag and drop behavior (elastic#51558) (elastic#51793)
mbondyra added a commit to mbondyra/kibana that referenced this pull request Nov 28, 2019
…ra/kibana into IS-46410_remove-@kbn/ui-framework

* 'IS-46410_remove-@kbn/ui-framework' of github.com:mbondyra/kibana: (49 commits)
  [ML] Re-activate after method in transform test (elastic#51815)
  [SIEM] [Detection Engine] Add edit on rule creation (elastic#51670)
  De-angularize visLegend (elastic#50613)
  [SIEM][Detection Engine] Change security model to use SIEM permissions
  [Monitoring] Sass cleanup (elastic#51100)
  Move errors and validate index pattern ⇒ NP (elastic#51805)
  fixes pagination tests (elastic#51822)
  Split legacy plugin discovery, expose SavedObjects scopedClient, wrappers, repository (elastic#48882)
  [SIEM][Detection Engine] Adds ecs threat properties to rules (elastic#51782)
  [Lens] Remove client-side reference to server source code (elastic#51763)
  Fix infinite redirect loop when multiple cookies are sent (elastic#50452)
  fixes drag and drop in tests (elastic#51806)
  [Console] Proxy fallback (elastic#50185)
  Query String(Bar) Input - cleanup (elastic#51598)
  shim visualizations plugin (elastic#50624)
  Expressions service fixes: better error and loading states handling (elastic#51183)
  fixes url state tests (elastic#51746)
  fixes browser field tests (elastic#51738)
  [ML] Fix anomaly detection test suite (elastic#51712)
  [SIEM] Fix Timeline drag and drop behavior (elastic#51558)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) release_note:skip Skip the PR/issue when compiling release notes review v7.6.0 v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants