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

[Lens] Move dataViews cache into main Lens state #137309

Merged
merged 32 commits into from
Aug 12, 2022

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Jul 27, 2022

Summary

This PR is a required step for #129299 and more future features in Lens.
The dataViews state was historically stored into the specific indexPatterns datasource, which was one of many potential datasources of the editor, but since Visualization starts to know more about it, it had to be lifted up to the editor main state to be reachable.

A new dataViews lens inner group has been created in the main Lens state, which holds refs, dataViews cache, fields existence and potential errors states.
Also the loading phase has been refactored to inspect directly the SO references to load only required dataViews (this sounds like a possible assumption as there is no hidden dataViews concept in Lens yet).

All the dataViews management method, which used to be stored into datasource are now stored within the indexPatternService, which is a tiny API around few functions that can be shared across the Lens app hierarchy.
The current state has not been stored into the indexPatternService as this is used also outside of the frame and it was easier to manage two variables rather than duplicate all the code for the TopNav + EditorFrame + Embeddable .

  • Move the dataViews state into the main root
  • IndexPatternServiceAPI
  • Make sure Embeddables work fine with that
    • Make it work in Dashboard
    • Examples
  • Open Saved Lens visualization
    • From dashboard
    • To Discover
  • Make sure Dataviews change work
    • Top Nav
    • Layer
  • Update persistable serializator
  • Migrations
  • Fix types
  • Tests
    • Broken tests
    • Checks all visualizations

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@dej611 dej611 added Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens labels Jul 27, 2022
indexPatternId: dataView.id,
setDatasourceState,
});
dispatchChangeIndexPattern(dataView.id);
Copy link
Contributor

@flash1293 flash1293 Aug 8, 2022

Choose a reason for hiding this comment

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

When a new data view is created from within Lens, the data panel crashes (seems like the new data view isn't added to the cache correctly?)

reportUnhandledError.js:10 Uncaught TypeError: Cannot read properties of undefined (reading 'fields')
    at InnerIndexPatternDataPanel (datapanel.tsx:211:1)
    at nh (react-dom.profiling.min.js:153:1)
    at ii (react-dom.profiling.min.js:175:1)
    at hi (react-dom.profiling.min.js:175:1)
    at fi (react-dom.profiling.min.js:174:1)
    at ek (react-dom.profiling.min.js:272:1)
    at dk (react-dom.profiling.min.js:248:1)
    at Xj (react-dom.profiling.min.js:247:1)
    at Ij (react-dom.profiling.min.js:240:1)
    at react-dom.profiling.min.js:122:1
InnerIndexPatternDataPanel	@	datapanel

}
) => {
const { visualizationIds, datasourceIds, layerId, indexPatternId, dataViews } = payload;
const newState: Partial<LensAppState> = { dataViews: { ...state.dataViews, ...dataViews } };
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I realized this problem - on changing the index pattern, we don't update the list of index pattern refs, but if it has been created on the spot this is necessary. At this point we could make sure that the new index pattern is listed in the refs and add it if that's not the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. I've added a loading check in the top nav change index pattern function to reload all refs in case the target id is missing in the refs cache.

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.

there's a small bug when switching data view for a layer, doesn't happen for all dimensions.

Aug-11-2022.13-26-53.mp4

@dej611
Copy link
Contributor Author

dej611 commented Aug 11, 2022

@mbondyra the layer dataViews switch bug should have been addressed in the latest version

@dej611 dej611 marked this pull request as ready for review August 11, 2022 14:30
@dej611 dej611 requested a review from a team as a code owner August 11, 2022 14:30
@elasticmachine
Copy link
Contributor

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

@dej611 dej611 added release_note:skip Skip the PR/issue when compiling release notes v8.5.0 backport:skip This commit does not require backporting labels Aug 11, 2022
@@ -126,6 +131,7 @@ export const getXyVisualization = ({
seriesType: firstUsedSeriesType || state.preferredSeriesType,
layerId,
layerType,
indexPatternId: indexPatternId ?? core.uiSettings.get('defaultIndex'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like these bits are related to query based annotations. Does it make sense to keep them here? We definitely need to extract/inject these references and as it's not happening on this PRs it's probably better to split it out of this PR.

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

In terms of the refactoring, this looks great, however it seems like there is a little leftover from the query based annotations that should probably be removed

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

LGTM, tested and didn't find any problems.

@flash1293
Copy link
Contributor

Conflicts are due to the improved error handling, shouldn't be too difficult to resolve

@dej611
Copy link
Contributor Author

dej611 commented Aug 12, 2022

Conflicts should be solved now.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
lens 903 906 +3

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
lens 530 535 +5

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1.2MB 1.2MB +7.4KB

Page load bundle

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

id before after diff
lens 34.6KB 34.6KB +60.0B
Unknown metric groups

API count

id before after diff
lens 614 621 +7

History

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

@mbondyra
Copy link
Contributor

Retested and couldn't find anything not working! Amazing work!

@stratoula stratoula merged commit 137994f into elastic:main Aug 12, 2022
Mpdreamz pushed a commit to Mpdreamz/kibana that referenced this pull request Sep 6, 2022
* Move lens dataViews state into main state

* 🔥 Remove some old cruft from the code

* 🐛 Fix dataViews layer change

* 🐛 Fix datasourceLayers refs

* 🔥 Remove more old cruft

* 🐛 Fix bug when loading SO

* 🐛 Fix initial existence flag

* 🏷️ Fix type issues

* 🏷️ Fix types and tests

* 🏷️ Fix types issues

* ✅ Fix more tests

* ✅ Fix with new dataViews structure

* ✅ Fix more test mocks

* ✅ More tests fixed

* 🔥 Removed unused prop

* ✅ Down to single broken test suite

* 🏷️ Fix type issue

* 👌 Integrate selector feedback

* ✅ Fix remaining unit tests

* 🏷️ fix type issues

* 🐛 Fix bug when creating dataview in place

* 🐛 Fix edit + remove field flow

* Update x-pack/plugins/lens/public/visualizations/xy/types.ts

* 📸 Fix snapshot

* 🐛 Fix the dataViews switch bug

* 🔥 remove old cruft

Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
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:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants