[Discover] [Group By] Support group by fetching across tabs#251154
Conversation
c499ba2 to
20a3d07
Compare
…e dependencies on global services, which can trigger when switching tabs
20a3d07 to
c3e922f
Compare
Flaky Test Runner Stats🎉 All tests passed! - kibana-flaky-test-suite-runner#10718[✅] src/platform/test/functional/apps/discover/cascade_layout/config.ts: 25/25 tests passed. |
| const EMPTY_FILTERS: Filter[] = []; | ||
|
|
||
| export const selectTabCombinedFilters = createSelector( | ||
| [ | ||
| (tab: TabState) => tab.globalState.filters, | ||
| (tab: TabState) => tab.appState.filters, | ||
| (tab: TabState) => tab.appState.query, | ||
| ], | ||
| (globalFilters, appFilters, query) => { | ||
| if (isOfAggregateQueryType(query)) { | ||
| return EMPTY_FILTERS; | ||
| } | ||
| const allFilters = [...(globalFilters ?? []), ...(appFilters ?? [])]; | ||
| return allFilters.length ? cloneDeep(allFilters) : EMPTY_FILTERS; | ||
| } | ||
| ); |
There was a problem hiding this comment.
I encountered an issue when switching Discover tabs where an additional fetch was triggered for the expanded group because we were relying on global services for filters, which are updated during tab change transition.
Technically it was fixed by stabilizing the handlers in useDataCascadeRowExpansionHandlers, but I had already made this change and figured it would be a good idea to standardize on a non-global service approach to selecting all filters to prevent similar issues in the future. I believe I updated all areas in Discover where this is done to use the new memoized selector.
There was a problem hiding this comment.
Thanks for cleaning up the filters setup!
|
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
| dataView, | ||
| timeRange, | ||
| }: FetchCascadedDocumentsParams) { | ||
| this.cancelFetch(nodeId); |
There was a problem hiding this comment.
q1: this is because we can't have multiple cascades open at the same time so we cancel the current one?
q2: if we go back to a cascade that was already fetched this will just remove the abort controller from the map but nothing will really happen?
There was a problem hiding this comment.
this is because we can't have multiple cascades open at the same time so we cancel the current one?
Yes only one group at a time, but cancelling in-flight requests should already be handled via external cancelFetch calls. This is mainly just a safeguard against duplicate fetch attempts (shouldn't really happen though).
if we go back to a cascade that was already fetched this will just remove the abort controller from the map but nothing will really happen?
Exactly, it should be a no-op for already fetched groups. However, the abort controller is removed after the first fetch, so it would just check the map and return when it doesn't find one.
| const abortController = this.abortControllers.get(nodeId); | ||
|
|
||
| if (abortController) { | ||
| abortController.abort(); |
There was a problem hiding this comment.
Yeah unfortunately I'm not sure we can fix this on our end atm. I originally caught errors and returned an empty array, but it caused the cascade components to cache the empty results. cc @eokoneyo in case we want to consider ways to improve the "failed fetch" case.
There was a problem hiding this comment.
manually tested + code lgtm but i'm not an expert on this so you may want a second review 🙈
not related to this task but it'd be nice to keep the cascades open between tabs navigations so when i come back from another tab the one i was taking a look at is still open
| const EMPTY_FILTERS: Filter[] = []; | ||
|
|
||
| export const selectTabCombinedFilters = createSelector( | ||
| [ | ||
| (tab: TabState) => tab.globalState.filters, | ||
| (tab: TabState) => tab.appState.filters, | ||
| (tab: TabState) => tab.appState.query, | ||
| ], | ||
| (globalFilters, appFilters, query) => { | ||
| if (isOfAggregateQueryType(query)) { | ||
| return EMPTY_FILTERS; | ||
| } | ||
| const allFilters = [...(globalFilters ?? []), ...(appFilters ?? [])]; | ||
| return allFilters.length ? cloneDeep(allFilters) : EMPTY_FILTERS; | ||
| } | ||
| ); |
There was a problem hiding this comment.
Thanks for cleaning up the filters setup!
| await expectCascadeRequestTimestampToChange(baseline, false); | ||
| }); | ||
| }); | ||
| } |
There was a problem hiding this comment.
We could also extend by checking how many requests were triggered via discover.expectSearchRequestCount helper.
There was a problem hiding this comment.
For context, I went with the inspector approach here so we also have e2e coverage for the custom request adapter changes. I took a shot at making it work with expectSearchRequestCount too, but was running into flakiness due to editor requests when changing tabs. I'm gonna merge this now to get it in, but open to revisiting and exploring expectSearchRequestCount again after.
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Async chunks
Page load bundle
History
cc @davismcphee |
…251154) ## Summary This PR implements support for group by fetching across Discover tabs, by detaching the data fetching logic from the React tree and consolidating it in a new `CascadedDocumentsFetcher`. This allows for the following behaviours: - The active fetch is cancelled when a group is expanded then collapsed while the fetch is running. - The active fetch is not cancelled when switching Discover tabs while the fetch is running, allowing it to run to completion in the background. - When returning to a Discover tab and re-expanding a previously fetched group, its records are no longer re-fetched and instead served from a cache. - All fetched groups are cleared when triggering a top-level Discover fetch, ensuring we don't show stale data in groups. - All active fetches are cancelled when leaving Discover or triggering a top-level Discover fetch, ensuring they aren't accidentally left running. Group by UI state is not currently retained when switching Discover tabs, that will be handled in a followup. Resolves elastic#249455. ### Checklist - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels.
…251154) ## Summary This PR implements support for group by fetching across Discover tabs, by detaching the data fetching logic from the React tree and consolidating it in a new `CascadedDocumentsFetcher`. This allows for the following behaviours: - The active fetch is cancelled when a group is expanded then collapsed while the fetch is running. - The active fetch is not cancelled when switching Discover tabs while the fetch is running, allowing it to run to completion in the background. - When returning to a Discover tab and re-expanding a previously fetched group, its records are no longer re-fetched and instead served from a cache. - All fetched groups are cleared when triggering a top-level Discover fetch, ensuring we don't show stale data in groups. - All active fetches are cancelled when leaving Discover or triggering a top-level Discover fetch, ensuring they aren't accidentally left running. Group by UI state is not currently retained when switching Discover tabs, that will be handled in a followup. Resolves elastic#249455. ### Checklist - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels.

Summary
This PR implements support for group by fetching across Discover tabs, by detaching the data fetching logic from the React tree and consolidating it in a new
CascadedDocumentsFetcher. This allows for the following behaviours:Group by UI state is not currently retained when switching Discover tabs, that will be handled in a followup.
Resolves #249455.
Checklist
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesbackport:*labels.