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

[Discover] Add internalState loading function preventing data view id change related race conditions #199419

Closed
wants to merge 12 commits into from

Conversation

kertal
Copy link
Member

@kertal kertal commented Nov 8, 2024

Summary

There's an occasional race condition, when an adhoc data view is changed, its id is also regenerated, technically we create a new data replacing the previous one. Therefore we guarantee each ad hoc data view id is uniqe when its spec changed. Otherwise we can't prevent duplicates. Lens, being used by the UnifiedHistogram, occasionally didn't know about the new id, having a list of data views with just the old id, and this led to the following error:

Bildschirmfoto 2024-10-07 um 19 32 34

This is caused by a race condition I assumed it would be fixed in #196114. But it started to fail again. So this PR makes should make sure, it can't fail again.

It's introducing a new variable isLoading on Discover's internal state, replacing the isLoading on discover_main_route. While the previous implementation was just available in discover_main_route, now other parts of Discover main can set Discover to it's loading state on the main route level. This cleans up any local UI state, so Discover is loaded in a fresh state which is beneficial for complex operation like the described id change of an underlying data structure like the data view.

Ideally we should aim to fix the race condition, but this area of code should be focused to be refacored soon, and having a way to switch Discover to its intial loading state can for sure be useful for other complex changes, that's why I considered to move forward here

Fixes #184600

Checklist

kertal added 7 commits October 4, 2024 09:21
- this deserves to be a first level function
- we can exchange underlying implementation if needed
- this deserves to be a first level function
- we can exchange underlying implementation if needed
@kertal
Copy link
Member Author

kertal commented Nov 8, 2024

/ci

@kertal kertal self-assigned this Nov 8, 2024
@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🎉 All tests passed! - kibana-flaky-test-suite-runner#7353

[✅] test/functional/apps/discover/group3/config.ts: 25/25 tests passed.

see run history

@kertal kertal added Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. labels Nov 8, 2024
@kertal kertal changed the title [Discover] Add internalState loading function [Discover] Add internalState loading function preventing data view id change related race conditions Nov 8, 2024
@kertal kertal added the backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) label Nov 8, 2024
@kertal kertal marked this pull request as ready for review November 11, 2024 09:04
@kertal kertal requested a review from a team as a code owner November 11, 2024 09:04
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

stateContainer={stateContainer}
hideNavMenuItems={showNoDataPage || loading}
/>
{loading && !showNoDataPage ? <LoadingIndicator /> : mainContent}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not we continue using loadingIndicator instead of <LoadingIndicator />?

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, this makes sense, it appears there were more changes, than I noticed since I started to fix this in another PR 👍

const onDataViewEdited = async (editedDataView: DataView) => {
setIsLoading(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if isDataViewLoading should be toggled too.

Copy link
Member Author

Choose a reason for hiding this comment

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

For me it appears we just use isDataViewLoading in

useInternalStateSelector((state) => state.isDataViewLoading) && !isEsqlMode;

and

const [dataView, dataViewLoading] = useInternalStateSelector((state) => [
state.dataView!,
state.isDataViewLoading,
]);

We set it to true when a data view is being changes.

With the new isLoading prop those components should not be displayed. So I'd say it's not necessary ... one think I wonder, would it make sense to combing all those loading states into one prop? one that can be used to get information about general loading state, data view loading state, data loading state ... just load thinking

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I was also wondering if we could use isDataViewLoading instead of introducing a new isLoading.
Editing a data view might be considered as "loading" its new state.

Copy link
Member Author

Choose a reason for hiding this comment

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

So I splitted this work (again):
Hopefully near term solution: #199982
Experimental loading refactoring, moving to one loading state instead of isDataViewLoading and isLoading: #199956

@@ -110,8 +110,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
return seriesType;
}

// FLAKY: https://github.com/elastic/kibana/issues/184600
describe.skip('discover lens vis', function () {
describe('discover lens vis', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

I reproduced the issue on this branch too:

Screenshot 2024-11-12 at 14 54 53

Copy link
Contributor

@jughosta jughosta Nov 12, 2024

Choose a reason for hiding this comment

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

We might need to load data views right after a new one is created and before it gets replaces in the app state/URL:

Copy link
Member Author

Choose a reason for hiding this comment

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

there's some really dark magic here, that even when investigating this caused my IDE to freeze, so just before the last meeting of my day, I'm thinking that the cleanup of adhoc data views that were changed because of a spec change, should be triggered later on:

services.dataViews.clearInstanceCache(edited);

because then the previous data view would still be available, wouldn't do any harm, and be removed after the data fetching was triggered

Copy link
Member Author

Choose a reason for hiding this comment

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

clearly broken here, looking for a simpler solution, so far I couldn't this seems to resolve this issue locally, let's see what flaky test runner says: #199982

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
discover 806.2KB 806.6KB +434.0B

History

cc @kertal

@kertal kertal marked this pull request as draft November 13, 2024 07:57
@elasticmachine
Copy link
Contributor

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!

@kertal
Copy link
Member Author

kertal commented Nov 13, 2024

Closing this for a different approach

@kertal kertal closed this Nov 13, 2024
@kertal kertal deleted the discover-unskip-_lens_vis·ts branch November 13, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL.
Projects
None yet
4 participants