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] [ES|QL] Prevent redundant requests when loading Discover sessions and toggling chart visibility #206699

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

davismcphee
Copy link
Contributor

@davismcphee davismcphee commented Jan 15, 2025

Summary

This PR prevents redundant Discover requests in ES|QL mode for the following scenarios:

  • Creating a new Discover session.
  • Saving the current Discover session.
  • Loading a saved Discover session.
  • Toggling the Unified Histogram chart visibility.

It does so by addressing several underlying state related issues that were triggering the redundant requests:

  • Skipping the initial emission of currentSuggestionContext on Unified Histogram mount, which immediately triggered a second fetch.
  • Treating the Unified Histogram table prop the same as other props which affect Lens suggestions (data view, query, columns), and deferring updates to it until result fetching completes to avoid unnecessary suggestion updates.
  • Removing all auto-fetching behaviour from Unified Histogram and instead relying solely on the consumer to control when fetching should occur (including the initial fetch).

Part of #165192.

Checklist

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests 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
  • 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.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

@davismcphee davismcphee 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. backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:ES|QL ES|QL related features in Kibana labels Jan 15, 2025
@davismcphee davismcphee self-assigned this Jan 15, 2025
Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Niiiiiiiice ❤️ !

@@ -267,18 +268,6 @@ export const useDiscoverHistogram = ({
* Data fetching
*/

const skipRefetch = useRef<boolean>();
Copy link
Member

Choose a reason for hiding this comment

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

it's great that we can remove this logic here! 🥳

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree! I've always disliked this workaround and have been wanting to remove it for a while, and now I finally had a good reason 😁

@@ -289,7 +291,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await expectSearches(type, 1, async () => {
await discover.toggleChartVisibility();
});
await expectSearches(type, 3, async () => {
await expectSearches(type, 2, async () => {
Copy link
Member

Choose a reason for hiding this comment

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

ha! 🎼 another requests bites the dust !
and in case this turns green: #206389
3 more requests will bite the dust

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I wasn't even aiming to address this one originally but it was a pleasant bonus for sure! I don't think it fully resolves #206389 yet since we should still skip the documents fetch on toggle, but it's definitely related and gets us closer to that goal 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just realized #206389 is a PR and not an issue 🤦 In that case, awesome! These enhancements combined should resolve all chart visibility related fetching issues 🤘

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

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

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

see run history

Copy link
Contributor Author

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

@kertal Thanks for looking at it! It seems like both CI and the flaky test runner are happy with these changes, so I'm going to publish this for review now 🙂

@@ -267,18 +268,6 @@ export const useDiscoverHistogram = ({
* Data fetching
*/

const skipRefetch = useRef<boolean>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree! I've always disliked this workaround and have been wanting to remove it for a while, and now I finally had a good reason 😁

@@ -289,7 +291,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await expectSearches(type, 1, async () => {
await discover.toggleChartVisibility();
});
await expectSearches(type, 3, async () => {
await expectSearches(type, 2, async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I wasn't even aiming to address this one originally but it was a pleasant bonus for sure! I don't think it fully resolves #206389 yet since we should still skip the documents fetch on toggle, but it's definitely related and gets us closer to that goal 👍

@davismcphee davismcphee marked this pull request as ready for review January 15, 2025 15:21
@davismcphee davismcphee requested a review from a team as a code owner January 15, 2025 15:21
@elasticmachine
Copy link
Contributor

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

@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 844.1KB 843.9KB -159.0B
unifiedHistogram 72.1KB 71.1KB -1008.0B
total -1.1KB

History

cc @davismcphee

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Code LGTM, great simplification of the code leading to omitting all redundant requests that were mentioned in #206699

So this PR is a release_note:fix 🥳

I've tested the reported extra fetches with #206699 using
https://kertal-pr-206699-fix-esql-fetches.kbndev.co/app/r/s/WIE7x

we now have a new request for fields triggered by the ES|QL editor, so the numbers changed

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 Feature:ES|QL ES|QL related features in Kibana 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
Development

Successfully merging this pull request may close these issues.

4 participants