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

Fix flaky histogram when an adhoc data view is being edited #194904

Closed
wants to merge 16 commits into from

Conversation

kertal
Copy link
Member

@kertal kertal commented Oct 4, 2024

Summary

This fixes the following problem: 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

It's a race condition caused by the facts that lens is treating data views a bit differently, having it's own variant of data view handling. I couldn't figure out, what causes this race condition. I therefore tried another approach. 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.

Overall this approach did the job removing the flakiness on one level, and introduced flakiness on another level (That high likely was already there). CI failed not having the right total hits number. This happend because totalHits$ occionally submits 2 complete states with different numbers (one the previous number, one the actual number), the UI is detecting state changes, to omit unnecessary updates, and therefore, since complete -> complete, no UI was updated.

Overall this PR is a bit like duct tape. but duct tape that's fixing things. If accepted, there should be a follow up issue investigating the histogram state changes a bit closer.

[✅] test/functional/apps/dashboard/group3/config.ts: 25/25 tests passed. kibana-flaky-test-suite-runner#7105

Fixes #184600

Checklist

@kertal kertal self-assigned this Oct 4, 2024
@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#7082

[❌] test/functional/apps/discover/group3/config.ts: 22/50 tests passed.

see run history

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#7083

[❌] test/functional/apps/discover/group3/config.ts: 23/50 tests passed.

see run history

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

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

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

see run history

},
[dataViews, stateContainer.actions, stateContainer.dataState]
);

const updateSavedQueryId = (newSavedQueryId: string | undefined) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

We were already having the same code in our state container, time use stateContainer.actions.onDataViewEdited instead of this code

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

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

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

see run history

@kibana-ci
Copy link
Collaborator

kibana-ci commented Oct 7, 2024

💔 Build Failed

Failed CI Steps

History

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

cc @kertal

- this deserves to be a first level function
- we can exchange underlying implementation if needed
@kertal kertal added Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. release_note:skip Skip the PR/issue when compiling release notes Feature:Discover Discover Application labels Oct 7, 2024
- this deserves to be a first level function
- we can exchange underlying implementation if needed
stateContainer.dataState.fetch();
},
[dataViews, stateContainer.actions, stateContainer.dataState]
);
Copy link
Member Author

Choose a reason for hiding this comment

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

seems we had this code already in our state container without using it

</DiscoverMainProvider>
</DiscoverCustomizationProvider>
);
}
// eslint-disable-next-line import/no-default-export
export default DiscoverMainRoute;

export function DiscoverMainLoading({
Copy link
Member Author

@kertal kertal Oct 7, 2024

Choose a reason for hiding this comment

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

since the loading state now is in the stateContainer, we need to have the state container in context so it's provided, therefore this change. This could be seen as first part of refactoring this file, which could use some love

setDataView(await services.dataViews.create(editedDataView.toSpec(), true));
} else {
await updateAdHocDataViewId();
}
loadDataViewList();
await loadDataViewList();
Copy link
Member Author

Choose a reason for hiding this comment

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

I first thought, ha! got you flaky test monster, a missing await, however it didn't help, but it should be changed anyway

@kertal kertal marked this pull request as ready for review October 7, 2024 21:02
@kertal kertal requested a review from a team as a code owner October 7, 2024 21:02
@elasticmachine
Copy link
Contributor

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

@kertal kertal changed the title Attempt to fix a flaky test Fix flaky histogram when adhoc data view are being edited Oct 7, 2024
@kertal kertal added the backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) label Oct 7, 2024
@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

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

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

see run history

@kertal kertal changed the title Fix flaky histogram when adhoc data view are being edited Fix flaky histogram when an adhoc data view is being edited Oct 8, 2024
Comment on lines 192 to 201
) {
// this is a workaround to make sure the new total hits value is displayed
// a different value without a loading state in between would lead to be ignored by useDataState
addLog(
'[UnifiedHistogram] send loading to totalHits$ to make sure the new value is displayed',
{ status, result }
);
savedSearchData$.totalHits$.next({
fetchStatus: FetchStatus.LOADING,
});
Copy link
Member Author

Choose a reason for hiding this comment

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

@dej611 this needs an issue as follow up to investigate

@kertal kertal marked this pull request as draft October 14, 2024 10:40
@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 Oct 14, 2024

/ci

@elasticmachine
Copy link
Contributor

elasticmachine commented Oct 14, 2024

💔 Build Failed

Failed CI Steps

History

cc @kertal

@kertal
Copy link
Member Author

kertal commented Oct 15, 2024

keeping this open, because i think having a general loading state in the state container could be useful, even if it's not needed now to fix the issue because of #196114

@kertal kertal closed this Nov 11, 2024
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