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

[Log Explorer] Restore dataset selector state from URL #160425

Closed
weltenwort opened this issue Jun 23, 2023 · 3 comments · Fixed by #161144
Closed

[Log Explorer] Restore dataset selector state from URL #160425

weltenwort opened this issue Jun 23, 2023 · 3 comments · Fixed by #161144
Assignees
Labels
Feature:LogsExplorer Logs Explorer feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services

Comments

@weltenwort
Copy link
Member

weltenwort commented Jun 23, 2023

📓 Summary

The dataset selector creates ad-hoc dataviews with random uuids for the selected dataset. Since Discover only persists the dataview id in the URL but not the content, reloading or sharing the page fails since Discover can't reconstruct the dataview. Similarly, the dataset selector can't reconstruct its selection state. To fix that we want to encode the selection state in the dataview id and reconstruct the dataview from it.

✔️ Acceptance criteria

  • Should restore the selection to "All logs" when loading the Discover log-explorer profile without a dataview ID in the URL.
  • When reloading the Discover log-explorer profile with a dataview ID in the URL...
    • the Dataset selector customization should parse the encoded dataview ID and extract the selection state information.
    • should intercept the dataview resolution step to create an ad-hoc dataview from the parsed state, storing the new dataview into the adHoc views list in the stateContainer.
    • should restore the dataset selection and any other relevant details associated with the dataview, verifying the internal Discover logic correctly resolves the ad-hoc dataview.
    • should initialize the Dataser selector component with the decoded selection state using the associated mode.
  • When the dataset selector has a new dataset(s) selection...
    • should store the selection in the DatasetSelector state machine based on the current mode (single, multi, all).
    • should compress/encode the selection data structure into a unique string (the shortest as possible), and use it as the new ad-hoc dataview to create.
    • should store the newly created dataview id in a URL query parameter.
  • When there is a failure in parsing the dataview id...
    • should notify the user with a notification.
    • should fall back to the "All logs" selection and store the selection in the URL query parameter.

🎨 Mock-ups

💡 Implementation hints

  • The Discover plugin registers the customizations during the start lifecycle hook execution, but it mounts the customized components later when necessary.
    To correctly create and restore the ad-hoc data view, this step needs to be done when creating the log explorer profile customization, during the plugin initialization.
  • The different state modes data structures could be something like this:
// Single selection
{
  selectionType: 'single',
  selection: {
    name: 'elasticsearch',
    dataset: {
      title: 'gc',
      name: 'logs-elasticsearch.gc-*'
    }
  }
}

// Many datasets
{
  selectionType: 'multi',
  selection: [
    {
      name: 'uncategorized',
      datasets: []
    },
    {
      name: 'elastic_agent',
      datasets: []
    },
    {
      name: 'elasticsearch',
      datasets: [
        {
          title: 'gc',
          name: 'logs-elasticsearch.gc-*'
        },
      ]
    },
    {
      name: 'system',
      datasets: []
    }
  ]
}

// All datasets
{
  selectionType: 'all'
}

Open questions

  • What should be the human-readable name for the synthesized ad-hoc dataview in case of multiple datasets?
    • <count> datasets ?
    • Same as the concatenated index?
@botelastic botelastic bot added the needs-team Issues missing a team label label Jun 23, 2023
@weltenwort weltenwort added Feature:Logs UI Logs UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services labels Jun 23, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/infra-monitoring-ui (Team:Infra Monitoring UI)

@weltenwort
Copy link
Member Author

@tonyghiani, thanks for filling out the ACs.

replace the URL index query parameter with the newly create ad-hoc dataview id.

If we successfully parse and restore the dataview, we don't need to change the index param, because it already contains the correct id, doesn't it?

@tonyghiani
Copy link
Contributor

@tonyghiani, thanks for filling out the ACs.

replace the URL index query parameter with the newly create ad-hoc dataview id.

If we successfully parse and restore the dataview, we don't need to change the index param, because it already contains the correct id, doesn't it?

Correct, we have two possible cases:

  • Read the id ➡️ Valid selection state ➡️ Create dataview ➡️ Discover restore from the index params (no URL replace)
  • Read the id ➡️ Invalid selection state or missing ➡️ Create dataview from default (all) ➡️ Store the new index in the URL state ➡️ Discover restore from the index param

tonyghiani added a commit that referenced this issue Jul 4, 2023
## 📓 Summary

Closes #160146 

This PR adds the entry to allow users to select a dataset that creates a
`logs-*-*` dataview.

Although the presentational and UX changes are minimal for the user,
this work lays the foundation for [restoring the dataset selection from
the URL](#160425) and for the
[dataset multi-selection
feature](https://github.com/elastic/observability-dev/issues/2744).

The core changes for this implementation consist of:
- Update DatasetSelector state machine to manage two parallel states: a
`popover` one to manage the navigation on the selector and a `selection`
state that handles the selection modes (currently only `all` and
`single`, but ready to also implement `multi`)
<img width="1522" alt="state-machine"
src="https://github.com/elastic/kibana/assets/34506779/c240e5d5-6a38-4d08-b893-117132477896">

- DatasetSelector is now a controlled component regarding the selection
value: it will react to the injected `datasetSelection` property, and
notify the parent component of any change with the `onSelectionChange`
event handler.
This will allow us to always reinitialize the DatasetSelector state
machine from the URL state and fall back to the chosen selection in case
there is no one to restore.


https://github.com/elastic/kibana/assets/34506779/4887b1d4-63ba-476b-a74f-5b4a9504f939

## Architectural choices

- The state machine will handle the two states in parallel such that we
can switch to available selection modes depending on the interactions
without clashing with the independent selector navigation.
- The `DatasetSelection` data structure is now what represents the state
selection in different modes.
The three available modes (counting also `multi`, but not implemented
yet), differs in mostly any aspect:
  - Internal data structure shape
  - DataViewSpecs composition
  - Payload to encode into a URL state
- Extraction of the presentational values (title, icons, and with
`multi` also the datasets which are currently selected)

With all these differences but the same final purposes of creating an
ad-hoc DataView and storing encoding a URL state to store, applying the
concepts for the Strategy pattern seemed the most sensed option to me.
This allows us to scale and add new selection modes (`multi`) respecting
the existing strategies contract and encapsulating all the concerned
transformations and parsing.

Encoding and decoding of the Dataview id that will be used for restoring
from the URL are already created and will be handy for the upcoming
tasks.

---------

Co-authored-by: Marco Antonio Ghiani <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
tonyghiani added a commit that referenced this issue Jul 20, 2023
## 📓  Summary

Closes #160425 

After the [first implementation of the log-explorer
profile](#159907), we wanted to
restore the selection of the dataset for a user when landing on the
Discover log-explorer profile.

Since we create an ad-hoc data view for Discover starting from the
dataset details, we needed to develop a system for intercepting the
`index` query parameter (which is used by Discover as the source of
truth for restoring a data view), create our ad-hoc data view and store
in the URL an encoded ID with the required details to restore the
selection.

The following video shows the user journey for:
- Landing on the log-explorer profile with no index param, nothing to
restore and fallback to All log datasets.
- Landing on the log-explorer profile invalid index param, notify about
failure and fallback to All log datasets.
- Select a different dataset, applies the new data view and update the
URL. When the URL is accessed directly, restore and initialize the data
view for the selection.
- Navigate back and forth in the browser history, restoring the
selection and data view on `index` param changes.


https://github.com/elastic/kibana/assets/34506779/37a212ee-08e4-4e54-8e42-1d739c38f164

## 💡 Reviewer hints

To have better control over the page selection and the restore process,
we prepared the DatasetSelector component for [being controlled by the
parent component](#160971).
Having that ready, we now implemented a new top-level state machine with
the following responsibilities:
- Re-initialize (decompress/decode) the dataset selection from the
`index` query params.
- Derive and set into Discover state a new ad-hoc data view.
- Keep track of new dataset selection changes and update the URL state
and the current data view.

<img width="1224" alt="log-explorer-machine"
src="https://github.com/elastic/kibana/assets/34506779/67e3ff17-dc3f-4dcf-b6c0-f40dbbea2d44">

We found a race condition between the Discover URL initialization + data
view initialization against the log-explorer profile customizations
being applied.
To guarantee we correctly initialize the state machine and restore the
selection before Discover goes through its initialization steps, we need
to wait for the customization service to exist in Discover so that also
the customization callbacks are successfully invoked.

---------

Co-authored-by: Marco Antonio Ghiani <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
ThomThomson pushed a commit to ThomThomson/kibana that referenced this issue Aug 1, 2023
## 📓  Summary

Closes elastic#160425 

After the [first implementation of the log-explorer
profile](elastic#159907), we wanted to
restore the selection of the dataset for a user when landing on the
Discover log-explorer profile.

Since we create an ad-hoc data view for Discover starting from the
dataset details, we needed to develop a system for intercepting the
`index` query parameter (which is used by Discover as the source of
truth for restoring a data view), create our ad-hoc data view and store
in the URL an encoded ID with the required details to restore the
selection.

The following video shows the user journey for:
- Landing on the log-explorer profile with no index param, nothing to
restore and fallback to All log datasets.
- Landing on the log-explorer profile invalid index param, notify about
failure and fallback to All log datasets.
- Select a different dataset, applies the new data view and update the
URL. When the URL is accessed directly, restore and initialize the data
view for the selection.
- Navigate back and forth in the browser history, restoring the
selection and data view on `index` param changes.


https://github.com/elastic/kibana/assets/34506779/37a212ee-08e4-4e54-8e42-1d739c38f164

## 💡 Reviewer hints

To have better control over the page selection and the restore process,
we prepared the DatasetSelector component for [being controlled by the
parent component](elastic#160971).
Having that ready, we now implemented a new top-level state machine with
the following responsibilities:
- Re-initialize (decompress/decode) the dataset selection from the
`index` query params.
- Derive and set into Discover state a new ad-hoc data view.
- Keep track of new dataset selection changes and update the URL state
and the current data view.

<img width="1224" alt="log-explorer-machine"
src="https://github.com/elastic/kibana/assets/34506779/67e3ff17-dc3f-4dcf-b6c0-f40dbbea2d44">

We found a race condition between the Discover URL initialization + data
view initialization against the log-explorer profile customizations
being applied.
To guarantee we correctly initialize the state machine and restore the
selection before Discover goes through its initialization steps, we need
to wait for the customization service to exist in Discover so that also
the customization callbacks are successfully invoked.

---------

Co-authored-by: Marco Antonio Ghiani <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
@gbamparop gbamparop added Feature:LogsExplorer Logs Explorer feature and removed Feature:Logs UI Logs UI feature labels Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:LogsExplorer Logs Explorer feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants