Skip to content

[TSVB] In the case of 2 or more panels on the dashboard, TSVB renderComplete fires 2 times #143999

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

Merged
merged 4 commits into from
Nov 1, 2022

Conversation

alexwizp
Copy link
Contributor

@alexwizp alexwizp commented Oct 26, 2022

Closes: #143556, Closes: #144253

Root cause

TSVB uses useEfect to change the DataView. The problem is that esaggs.ts calls indexPatterns.create which updates the link to the cached DataView each time

I don't know why it was implemented that way, but it looks like we can try to get a value from the cache before creating a new one.

Screens

With that changes TSVB works fine

Screen.Recording.2022-10-26.at.13.30.50.mov

@alexwizp alexwizp self-assigned this Oct 26, 2022
@alexwizp alexwizp added v8.6.0 Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) Feature:Data Views Data Views code and UI - index patterns before 8.0 release_note:fix labels Oct 26, 2022
@alexwizp alexwizp marked this pull request as ready for review October 26, 2022 10:32
@alexwizp alexwizp requested a review from a team as a code owner October 26, 2022 10:32
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

Wow, good catch. It works correctly for most cases, but there's one more that I introduced that should be addressed. When creating annotation fetching logic, I also used indexPatterns.create so for the charts with Lens annotations we'll have the same problem (render twice):

Screenshot 2022-10-26 at 14 53 28

The solution would be to implement the same thing (cachedDataView search first) here:
https://github.com/elastic/kibana/blob/main/src/plugins/event_annotation/common/fetch_event_annotations/request_event_annotations.ts#L95

And you'll have to also update tests in src/plugins/event_annotation/public/fetch_event_annotations/fetch_event_annotations.test.ts
Let me know if you need any help with it.

@alexwizp
Copy link
Contributor Author

Good point @mbondyra , I think due to the fact of usage of that wrong pattern from the different places we should fix that in a different way. @elastic/kibana-app-services maybe we should introduce new method e.g. getBySpec and reuse it from all places?

@alexwizp alexwizp marked this pull request as draft October 27, 2022 11:02
@alexwizp alexwizp marked this pull request as ready for review October 27, 2022 12:19
@elastic elastic deleted a comment from kibana-ci Oct 27, 2022
@mattkime
Copy link
Contributor

I think I'd go in another direction, perhaps you can tell me why I'm wrong. getBySpec would be more accurately called getByIdOrCreate. The create method was being called because we were unsure if we had a persisted data view. Unfortunately the create method sets the cache but it doesn't check it. I think it might be simpler to add a cache check similar to the dataViews.get method.

Part of me would like to see these methods named a bit better but I guess continuing with the current names is okay.

@alexwizp
Copy link
Contributor Author

alexwizp commented Oct 27, 2022

@mattkime Renaming to getByIdOrCreate looks ok to me.

About checking cache in the create method not sure that is's possible with the current implementation. I've created a draft where you can play with it. Here I added console.logs and some comments for all important places. #144110

In general, the current approach looks like:

Untitled (1)

I just wanted to show that if we interrupt the create method and return the value from the cache, in fact it will be a Promise that will never be resolved

@mattkime
Copy link
Contributor

mattkime commented Oct 28, 2022

@alexwizp I still need to take a closer look at this. "At this step, we have in the cache a promise of an uninitialized data view" shouldn't be happening. It would be nice to figure out a way to unblock further work while properly addressing this. This shouldn't take too long but I understand that other things need to be completed.

Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

As for the bug, it is fixed 👌🏼

Testing log

  • multiple tsvb vises on Dashboard with Lens visualization
  • single tsvb vis on Dashboard with Lens visualization
  • Canvas check

@alexwizp
Copy link
Contributor Author

@elasticmachine merge upstream

@alexwizp
Copy link
Contributor Author

alexwizp commented Nov 1, 2022

@elasticmachine merge upstream

@@ -929,6 +929,30 @@ export class DataViewsService {
return indexPattern;
Copy link
Contributor

@mattkime mattkime Nov 1, 2022

Choose a reason for hiding this comment

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

It would be nice if dataViewCache.set was called in create so that createFromSpec only creates the dataView and isn't concerned with the cache. Also, we want to clear the cache entry if creating the data view fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a really cool idea! thanks, updated

Copy link
Contributor

@mattkime mattkime left a comment

Choose a reason for hiding this comment

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

changes lgtm, good work!

@alexwizp alexwizp requested a review from a team as a code owner November 1, 2022 17:09
@alexwizp
Copy link
Contributor Author

alexwizp commented Nov 1, 2022

@elastic/kibana-operations please review limits

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
data 2555 2553 -2
dataViews 231 228 -3
total -5

Page load bundle

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

id before after diff
dataViews 45.3KB 45.5KB +183.0B
Unknown metric groups

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 57 63 +6
osquery 103 108 +5
securitySolution 439 443 +4
total +17

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 65 71 +6
osquery 104 110 +6
securitySolution 516 520 +4
total +18

History

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

cc @alexwizp

@alexwizp alexwizp merged commit 656e072 into elastic:main Nov 1, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Data Views Data Views code and UI - index patterns before 8.0 release_note:fix Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache ad-hoc data views to avoid repeated field list calls [TSVB] In the case of 2 or more panels on the dashboard, TSVB renderComplete fires 2 times
7 participants