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

[Search Sessions] Improve session restoration back button #87635

Merged

Conversation

Dosant
Copy link
Contributor

@Dosant Dosant commented Jan 7, 2021

Summary

Closes #82419

Improves back button behavior for search session restoration state
Discover and dashboard because this is only apps we have session restoration flow for now

How to test

Full flow will be testable after #81707 is merged, but for now:

  1. Add a fake searchSessionId to discover or dashboard URL. Load it. The session should fail to restore in this case. (you can also use a real seaerchSessionId using inspector)
  2. Change the state that would trigger a new search. e.g. change time
  3. Press back -> should return you in the previous state with searchSessionId in the URL
demo-back-button.mov

Both for Discover and Dashboard there are different main cases with this navigation that are different from one another and expected to work:

  1. In case navigating away from a restored session together with another state change, like changing time
  2. In case navigating away from a restored session without another state change, like when hitting "refresh"
  3. another case that should work: directly changing the searchSessionId in the browser address bar

Discover has a very specific code path when changing index patterns. This is another code path that is worth testing and it should work.

Implemintation

I fully exposed underlying kbnUrlControls on kbnUrlStorage. Dashboard needs them to remove searchSessionId during pending state sync update.

There is a known edge case that if you open a Discover or Dashboard URL and then change only searchSessionId then nothing would happen.
That is because there is no listener that listens specifically to that query param. Such change is happening in a real-world scenario in case the "refresh" button was hit.

  • @Dosant: Todo: try fixing this, see how difficult this is... This if fixed but made implementation more complicated :(

In Dashboard I had to add a denounce on updating dashboard container input to cover the following edge case:

  1. Restoring a session -> navigating away with other state change, for example, with time range change
  2. time is changed in the URL. searchSessionId is removed from the URL.
  3. Hit back
  4. both connectToGlobalQueryState (time) and searchSessionIdQuery$ will ask for dashboard container update. to avoid double fetch in this cases I added debounce.

Notes

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@Dosant
Copy link
Contributor Author

Dosant commented Jan 11, 2021

@elasticmachine merge upstream

@Dosant Dosant added Feature:Dashboard Dashboard related features Feature:Discover Discover Application Feature:Search Querying infrastructure in Kibana Feature:StateManagement Team:AppSearch v7.12.0 v8.0.0 release_note:skip Skip the PR/issue when compiling release notes labels Jan 11, 2021
@Dosant Dosant marked this pull request as ready for review January 11, 2021 09:27
@Dosant Dosant requested a review from a team January 11, 2021 09:27
@Dosant Dosant requested review from a team as code owners January 11, 2021 09:27
@elasticmachine
Copy link
Contributor

Pinging @elastic/app-search-frontend (Team:AppSearch)

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

@Dosant
Copy link
Contributor Author

Dosant commented Jan 11, 2021

Pinging elastic/app-search-frontend (Team:AppSearch)

Sorry for the ping 😢 confused Team:AppSearch and Team:AppServices

@@ -577,18 +575,21 @@ function discoverController($element, $route, $scope, $timeout, Promise, uiCapab
abortController = new AbortController();

const searchSessionId = (() => {
const searchSessionIdFromURL = getSearchSessionIdFromURL(history);
let searchSessionIdFromURL = getSearchSessionIdFromURL(history);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a huge fan of this entire block being duplicated.

What do you say we add a function called restoreFromUrl(urlHistory) to the session service?
The function will extract the searchSessionId from the URL and then apply the logic below.

Copy link
Contributor Author

@Dosant Dosant Jan 12, 2021

Choose a reason for hiding this comment

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

What do you say we add a function called restoreFromUrl(urlHistory) to the session service?

This part is app-specific. It just happens that Discover and Dashboard do this similar:

It is up to the apps how they restore search sessions. Discover and Dashboard URLs structure are similar (both use searchSessionId query param inside hash part of the URL.)

  • But not every app has a hash in the URL, so they might store searchSessionId as a query param in a pathname (before the hash).
  • They also might have a param named differently or be serialized in rison/json or other structures.
  • We will support restoring session without the URL all together: [Search Session] Use new URL Service for session restoration #85126

I'd extract to common place if we'd have a shared place for Discover/Dashboard/Visualize, but as we don't, I think it is fine to leave it as is

@lizozom
Copy link
Contributor

lizozom commented Jan 12, 2021

I tested the PR
It works as expected in dashboard, but not in discover.
See video

Discover.-.Elastic.3.mp4

@Dosant
Copy link
Contributor Author

Dosant commented Jan 12, 2021

@lizozom: It works as expected in the dashboard, but not in discover.

Discussed with @lizozom that this is not actually a problem:

The back button triggers the previous search which is expected, but Discover doesn't remove old results from the screen in this case, but the Dashboard does. This is not what we want to address in this pr, this is just how Discover / Dashboard error handling works in case of failed requests.

Instead, we should focus on is that back button triggers the previous search and on a real-world scenario where the session restoration is successful and we see the new results

@Dosant Dosant requested a review from lizozom January 12, 2021 16:44
@Dosant Dosant marked this pull request as ready for review January 19, 2021 12:13
@kertal
Copy link
Member

kertal commented Jan 19, 2021

ACK, aye, aye, will review

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Presentation team changes LGTM. Was able to test this locally and confirm that the back button restored the invalid search session.

@@ -59,7 +59,7 @@ export function DashboardApp({
indexPatterns: indexPatternService,
} = useKibana<DashboardAppServices>().services;

const [lastReloadTime, setLastReloadTime] = useState(0);
const triggerRefresh$ = useMemo(() => new Subject<{ force?: boolean }>(), []);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nice improvement. Much better than using a lastReloadTime to trigger forced resets.

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.

Kibana App owned code LGTM, tested locally in Chrome, worked correctly. Every time I look at the change index pattern behavior, it gives me headache. Aspirine will be further deangularization.

…store-search-session-back-button

# Conflicts:
#	x-pack/test/send_search_to_background_integration/tests/apps/dashboard/async_search/send_to_background.ts
@Dosant
Copy link
Contributor Author

Dosant commented Jan 25, 2021

@elasticmachine merge upstream

@Dosant
Copy link
Contributor Author

Dosant commented Jan 26, 2021

@elasticmachine merge upstream

Copy link
Contributor

@lizozom lizozom 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 OSS back behavior
  • Tested searchSessionId change in URL is picked up without having to refresh the whole page
  • Navigating back to a restored session works
  • Navigating back and forth between two restored sessions works
  • Refresh button properly cleans the searchSessionId
  • Same tests work on Discover and Dashboard 👍

@@ -0,0 +1,60 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add unit tests for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Dosant
Copy link
Contributor Author

Dosant commented Jan 28, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 336 337 +1
kibanaUtils 191 192 +1
total +2

Async chunks

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

id before after diff
dashboard 158.6KB 159.9KB +1.3KB
discover 411.3KB 412.8KB +1.5KB
maps 2.6MB 2.6MB +5.0B
total +2.8KB

Page load bundle

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

id before after diff
dashboard 295.5KB 295.3KB -138.0B
kibanaUtils 140.8KB 142.1KB +1.3KB
total +1.2KB

History

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

@Dosant Dosant merged commit 07b210e into elastic:master Jan 28, 2021
Dosant added a commit to Dosant/kibana that referenced this pull request Jan 28, 2021
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jan 28, 2021
…y-tests

* 'master' of github.com:elastic/kibana: (31 commits)
  [Discover] Add grid flyout jest test (elastic#89088)
  [Search Sessions] Improve session restoration back button (elastic#87635)
  [TSVB] Remove vis_type_timeseries_enhanced plugin (elastic#89274)
  [Security Solution] Init Osquery plugin (elastic#87109)
  [Fleet] Do not defined aliases inside datastream template (elastic#89512)
  skip flaky suite (elastic#86950)
  chore(NA): bazel machinery installation on kbn bootstrap (elastic#89469)
  [build/docker] Add support for centos ARM builds (elastic#84831)
  Convert default_watch.json to a JS object in order to avoid TS complaints (elastic#89488)
  [CI] Decrease number of Jest workers (elastic#89504)
  [Maps] remove maps_oss TS project (elastic#89502)
  Adds migration settings to Docker (elastic#89501)
  [Lens] Fix crash in transition from unique count to last value (elastic#88916)
  [kbn-es] Always use bundled JDK when starting Elasticsearch (elastic#89437)
  unskip getting_started/shakespeare test elasticsearch 64016 (elastic#89346)
  [Maps] migrate maps, maps_file_upload, and maps_legacy_licensing to TS projects (elastic#89439)
  skip flaky suite (elastic#89478)
  skip flaky suite (elastic#89476)
  skip flaky suite (elastic#89477)
  skip flaky suite (elastic#89475)
  ...

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/cold_phase/cold_phase.tsx
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jan 28, 2021
…updates-and-timeline-cleanup

* 'master' of github.com:elastic/kibana: (44 commits)
  [Discover] Add grid flyout jest test (elastic#89088)
  [Search Sessions] Improve session restoration back button (elastic#87635)
  [TSVB] Remove vis_type_timeseries_enhanced plugin (elastic#89274)
  [Security Solution] Init Osquery plugin (elastic#87109)
  [Fleet] Do not defined aliases inside datastream template (elastic#89512)
  skip flaky suite (elastic#86950)
  chore(NA): bazel machinery installation on kbn bootstrap (elastic#89469)
  [build/docker] Add support for centos ARM builds (elastic#84831)
  Convert default_watch.json to a JS object in order to avoid TS complaints (elastic#89488)
  [CI] Decrease number of Jest workers (elastic#89504)
  [Maps] remove maps_oss TS project (elastic#89502)
  Adds migration settings to Docker (elastic#89501)
  [Lens] Fix crash in transition from unique count to last value (elastic#88916)
  [kbn-es] Always use bundled JDK when starting Elasticsearch (elastic#89437)
  unskip getting_started/shakespeare test elasticsearch 64016 (elastic#89346)
  [Maps] migrate maps, maps_file_upload, and maps_legacy_licensing to TS projects (elastic#89439)
  skip flaky suite (elastic#89478)
  skip flaky suite (elastic#89476)
  skip flaky suite (elastic#89477)
  skip flaky suite (elastic#89475)
  ...

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/hot_phase/hot_phase.tsx
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Dashboard Dashboard related features Feature:Discover Discover Application Feature:Search Querying infrastructure in Kibana Feature:StateManagement release_note:skip Skip the PR/issue when compiling release notes v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Search][State Management] Restoring background session and back button
6 participants