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

[Logs Explorer] Support logs data views #176078

Merged
merged 42 commits into from
Feb 13, 2024

Conversation

tonyghiani
Copy link
Contributor

@tonyghiani tonyghiani commented Feb 1, 2024

📓 Summary

Closes #175767

🧪 You can access a live deployment of this PR here.

There has been a lot of talking around supporting selection for data views and staying on the Logs Explorer for those concerning logs data streams.

This work supports selecting and exploring Discover data views on Logs Explorer. This is currently limited to logs data views.

Screen.Recording.2024-02-01.at.16.19.03.mov

Next steps

We had already an offline conversation with the team about how naming the selector, selection modes and related entities is becoming inconsistent and more difficult to maintain.
To keep this PR narrowed to the data views support, an upcoming PR will focus on renaming according to the new selector's responsibilities.

Core changes

DataViewDescriptor

The DataViewDescriptor instance is a way to describe a data view in the context of Logs Explorer. This does not represent a DataView object complete of fields and all the details provided with a DataView instance, but it instead encapsulates the logic around identifying what data type a data view is about, as well as defining the logic to use it with the new dataView selection mode.

It creates a new instance starting from a DataViewListItem object, which is a minimal object provided by the dataViews service to list existing data views.

LogExplorerController

The LogExplorerController state machine now handles the selected entry depending on its type, triggering different flows. There are 3 different journeys depending on the selected entry:

  • For a data view entry which is not about logs, the page redirects to Discover with the data view selected
  • For a data view entry about logs, the data loads in the Logs Explorer, switching to the persisted DataView.
  • For a dataset entry, an ad-hoc data view loads in the Logs Explorer.

To avoid updating twice the data view (once during initialization, and immediately after during selection validation), the validation flow has been anticipated and restructured to follow different flows, depending on the selection type.

Screenshot 2024-02-09 at 12 02 10

Dataset selector

The selector state machine unifies the selection handler and expands the selection modes, adding a new dataView mode which handles logs data view selections.

Screenshot 2024-02-05 at 16 24 31

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@tonyghiani tonyghiani changed the title support data views [Logs Explorer] Support logs data views Feb 1, 2024
@tonyghiani tonyghiani force-pushed the 175767-support-data-views branch from 874d168 to 524d93d Compare February 5, 2024 11:00

export class DataViewDescriptor {
id: DataViewDescriptorType['id'];
dataType: DataViewDescriptorType['dataType'];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: this property will be useful to differentiate between different data views and group them by its value.

* 2.0.
*/

export const buildIndexPatternRegExp = (basePatterns: string[]) => {
Copy link
Contributor Author

@tonyghiani tonyghiani Feb 5, 2024

Choose a reason for hiding this comment

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

note: Starting from a single base pattern such as logs, metrics, etc.., this function allows to create a regular expression to test an index pattern for:

  • word boundaries and subsequent paths (logs-, logs-system.syslog-default, etc...)
  • local and remote clusters (logs-, remote_cluster:logs-*, etc...)
  • multiple patterns, supporting above features (logs-*,remote_cluster:logs-*, etc...)

if (!('discoverStateContainer' in context)) return;
const { discoverStateContainer } = context;

return discoverStateContainer.actions.onChangeDataView(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: this action fetches and sets the complete data view object by its ID using the Discover pre-existing logic.

@tonyghiani
Copy link
Contributor Author

/oblt-deploy

@weltenwort weltenwort self-requested a review February 12, 2024 12:45
Copy link
Member

@weltenwort weltenwort left a comment

Choose a reason for hiding this comment

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

Very solid work overall, I had a good time reading it! 👏 The changes to the state machines make them more consistent. It's also good to see how the discover plugin was removed as a dependency throughout the selector hierarchy. This will make its re-use in other locations easier.

I left just a few questions and suggestions below.

And thanks for updating the storybook, which was very helpful in testing the loading and error states.

): ActionFunction<LogsExplorerControllerContext, LogsExplorerControllerEvent> =>
(context, event) => {
if (event.type === 'UPDATE_DATASET_SELECTION' && isDataViewSelection(event.data)) {
return redirectToDiscover({ context, datasetSelection: event.data, discover });
Copy link
Member

Choose a reason for hiding this comment

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

The way the action is implemented (and how the selector acted before) would cause the page-wide side-effect of navigating to a different URL. Is that desirable when the logs explorer is used in an embedded fashion? Should we delegate that to the consumer?

If so, how do we do that? 🤔 Two options come to mind:

  • a customization that customizes the action that happens here (like the one used for the ai assistant)
  • emitting an event on the (yet unused) event$ observable that the consumer can react to

What do you think?

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 see your point here and both the proposed solutions LGTM.
On the other hand, what do you think should be the fallback behaviour when the consumer doesn't apply the customization or doesn't react to the event?

My concern is we might end up with a broken UX when the user clicks on a non-logs data view if the consumer embedding the LogsExplorer doesn't react to the emitted event in $event (assuming we go with the second option).

One option to keep the default behaviour without forcing the user to react to the emitted event, but still provide the flexibility to perform custom logic and prevent the default behaviour if necessary could be to provide something like a preventDefault() method as part of the emitted event, in a browser-fashion way.

What I mean is, in case we'll extend the set of events emitted by the controller, to have something like this:

export type LogsExplorerPublicEvent =
  | {
      type: 'REDIRECT_TO_DISCOVER';
      data: { context, eventPayload };
      preventDefault: () => void;
    }
  | {
      type: 'ANOTHER_EVENT';
      data: { ... };
      preventDefault: () => void;
    }
  | ...

This is just one possible approach, but it might be more convoluted than other options, what do you think?
Or did I misunderstand your suggestion and you meant something different? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mmm I've been thinking more about the approach I proposed for preventing the default behaviour as we might have more subscribers on the same emitted event, which makes it impractical to decide whether the default behaviour should be skipped or not...
Adding a customization point would work, but it still leaves the discussion open about what happens if the consumer doesn't register the customization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on a offline conversation with Felix, we'll implement a customization point to delegate the redirect to the consumer in a shorted upcoming pull request.

isDataViewSelection(context.datasetSelection) &&
context.datasetSelection.selection.dataView.isUnknownDataType()
) {
return redirectToDiscover({ context, datasetSelection: context.datasetSelection, discover });
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, should this side-effect happen here? Or should it be delegated to the consumer too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same work mentioned here will apply to this part.

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Integration Tests #6 / fake elasticsearch should fail to start Kibana because of the Product Check Error
  • [job] [logs] Jest Integration Tests #6 / fake elasticsearch should return unknown product when it cannot perform the Product check (503 response)

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
logsExplorer 672 677 +5

Async chunks

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

id before after diff
logsExplorer 1002.9KB 1005.8KB +2.9KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
logsExplorer 19 20 +1

Page load bundle

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

id before after diff
logsExplorer 49.0KB 51.8KB +2.8KB

History

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

@tonyghiani tonyghiani merged commit dd06f81 into elastic:main Feb 13, 2024
19 checks passed
@tonyghiani tonyghiani deleted the 175767-support-data-views branch February 13, 2024 12:17
@kibanamachine kibanamachine added v8.13.0 backport:skip This commit does not require backporting labels Feb 13, 2024
// Apply base patterns union for local and remote clusters
const localAndRemotePatternGroup = `((${basePatternGroup})|([^:,\\s]+:${basePatternGroup}))`;
// Handle trailing comma and multiple pattern concatenation
return new RegExp(`^${localAndRemotePatternGroup}(,${localAndRemotePatternGroup})*(,$|$)`, 'i');
Copy link
Contributor

Choose a reason for hiding this comment

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

Really loved the explanatory way of creating the regex 💯

CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
## 📓 Summary

Closes elastic#175767 

🧪 You can access a live deployment of this PR
[here](https://issue-deploy-kibana-pr176078.kb.us-west2.gcp.elastic-cloud.com/app/observability-logs-explorer/).

There has been a lot of talking around supporting selection for data
views and staying on the Logs Explorer for those concerning logs data
streams.

This work supports selecting and exploring Discover data views on Logs
Explorer. This is currently limited to logs data views.


https://github.com/elastic/kibana/assets/34506779/cccd6863-e1c1-4fa6-a530-9aed5d8d97c1

## Next steps

We had already an offline conversation with the team about how naming
the selector, selection modes and related entities is becoming
inconsistent and more difficult to maintain.
To keep this PR narrowed to the data views support, an upcoming PR will
focus on renaming according to the new selector's responsibilities.

## Core changes

### DataViewDescriptor
The `DataViewDescriptor` instance is a way to describe a data view in
the context of Logs Explorer. This does not represent a DataView object
complete of fields and all the details provided with a DataView
instance, but it instead encapsulates the logic around identifying what
data type a data view is about, as well as defining the logic to use it
with the new `dataView` selection mode.

It creates a new instance starting from a `DataViewListItem` object,
which is a minimal object provided by the dataViews service to list
existing data views.

### LogExplorerController
The `LogExplorerController` state machine now handles the selected entry
depending on its type, triggering different flows. There are 3 different
journeys depending on the selected entry:
- For a data view entry which is not about logs, the page redirects to
Discover with the data view selected
- For a data view entry about logs, the data loads in the Logs Explorer,
switching to the persisted DataView.
- For a dataset entry, an ad-hoc data view loads in the Logs Explorer.

To avoid updating twice the data view (once during initialization, and
immediately after during selection validation), the validation flow has
been anticipated and restructured to follow different flows, depending
on the selection type.

<img width="1953" alt="Screenshot 2024-02-09 at 12 02 10"
src="https://github.com/elastic/kibana/assets/34506779/a63201f5-67b2-4890-8823-6ffd6691e249">

### Dataset selector
The selector state machine unifies the selection handler and expands the
selection modes, adding a new `dataView` mode which handles logs data
view selections.

<img width="1281" alt="Screenshot 2024-02-05 at 16 24 31"
src="https://github.com/elastic/kibana/assets/34506779/80e04331-7b93-40fc-af1d-32ef4ef705f5">

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
tonyghiani added a commit that referenced this pull request Feb 15, 2024
## 📓 Summary

This work is a follow-up of the newly introduced [support to logs backed
data views](#176078) in Logs
Explorer.

In [a
comment](#176078 (comment))
from the PR mentioned above, we discussed delegating to the consumers
<LogsExplorer /> the responsibility to redirect to discover when
selecting a non-logs data view, to prevent hard-coding a page-wide
side-effect of navigating to a different URL.

This introduces a new customization interface for the LogsExplorer that
controls specific actions, starting from the first added event
`onUknownDataViewSelection`.

In case the consumers of this component do not provide the event
handler, the data view entry in the data source selector will appear
disabled and will not be clickable.

<img width="412" alt="Screenshot 2024-02-13 at 15 45 30"
src="https://github.com/elastic/kibana/assets/34506779/7933007d-75a0-4094-bf55-a3361637f4d1">

## Example

When creating the controller to pass into the LogsExplorer component, we
can specify the event for handling the discover navigation as follow:

```ts
createLogsExplorerController({
  customizations: {
    events: {
      onUknownDataViewSelection: (context) => { /* ... */ },
    },
  },
});
```

A use case for such usage is, for instance, that some consumers might
want to prompt the user somehow before performing the navigation, or
simply they don't want to do any navigation.

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
## 📓 Summary

Closes elastic#175767 

🧪 You can access a live deployment of this PR
[here](https://issue-deploy-kibana-pr176078.kb.us-west2.gcp.elastic-cloud.com/app/observability-logs-explorer/).

There has been a lot of talking around supporting selection for data
views and staying on the Logs Explorer for those concerning logs data
streams.

This work supports selecting and exploring Discover data views on Logs
Explorer. This is currently limited to logs data views.


https://github.com/elastic/kibana/assets/34506779/cccd6863-e1c1-4fa6-a530-9aed5d8d97c1

## Next steps

We had already an offline conversation with the team about how naming
the selector, selection modes and related entities is becoming
inconsistent and more difficult to maintain.
To keep this PR narrowed to the data views support, an upcoming PR will
focus on renaming according to the new selector's responsibilities.

## Core changes

### DataViewDescriptor
The `DataViewDescriptor` instance is a way to describe a data view in
the context of Logs Explorer. This does not represent a DataView object
complete of fields and all the details provided with a DataView
instance, but it instead encapsulates the logic around identifying what
data type a data view is about, as well as defining the logic to use it
with the new `dataView` selection mode.

It creates a new instance starting from a `DataViewListItem` object,
which is a minimal object provided by the dataViews service to list
existing data views.

### LogExplorerController
The `LogExplorerController` state machine now handles the selected entry
depending on its type, triggering different flows. There are 3 different
journeys depending on the selected entry:
- For a data view entry which is not about logs, the page redirects to
Discover with the data view selected
- For a data view entry about logs, the data loads in the Logs Explorer,
switching to the persisted DataView.
- For a dataset entry, an ad-hoc data view loads in the Logs Explorer.

To avoid updating twice the data view (once during initialization, and
immediately after during selection validation), the validation flow has
been anticipated and restructured to follow different flows, depending
on the selection type.

<img width="1953" alt="Screenshot 2024-02-09 at 12 02 10"
src="https://github.com/elastic/kibana/assets/34506779/a63201f5-67b2-4890-8823-6ffd6691e249">

### Dataset selector
The selector state machine unifies the selection handler and expands the
selection modes, adding a new `dataView` mode which handles logs data
view selections.

<img width="1281" alt="Screenshot 2024-02-05 at 16 24 31"
src="https://github.com/elastic/kibana/assets/34506779/80e04331-7b93-40fc-af1d-32ef4ef705f5">

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
## 📓 Summary

This work is a follow-up of the newly introduced [support to logs backed
data views](elastic#176078) in Logs
Explorer.

In [a
comment](elastic#176078 (comment))
from the PR mentioned above, we discussed delegating to the consumers
<LogsExplorer /> the responsibility to redirect to discover when
selecting a non-logs data view, to prevent hard-coding a page-wide
side-effect of navigating to a different URL.

This introduces a new customization interface for the LogsExplorer that
controls specific actions, starting from the first added event
`onUknownDataViewSelection`.

In case the consumers of this component do not provide the event
handler, the data view entry in the data source selector will appear
disabled and will not be clickable.

<img width="412" alt="Screenshot 2024-02-13 at 15 45 30"
src="https://github.com/elastic/kibana/assets/34506779/7933007d-75a0-4094-bf55-a3361637f4d1">

## Example

When creating the controller to pass into the LogsExplorer component, we
can specify the event for handling the discover navigation as follow:

```ts
createLogsExplorerController({
  customizations: {
    events: {
      onUknownDataViewSelection: (context) => { /* ... */ },
    },
  },
});
```

A use case for such usage is, for instance, that some consumers might
want to prompt the user somehow before performing the navigation, or
simply they don't want to do any navigation.

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
tonyghiani added a commit that referenced this pull request Mar 20, 2024
## 📓 Summary

Closes #177703

This work supports a new Logs Explorer UI setting to customize the data
view patterns which allow to browse data views directly in Logs
Explorer. It's a follow-up work of
#176078, where we introduced a way
to recognise logs-backed data views and explore their entires without
redirecting to Discover.

The previously hard-coded list of allowed patterns (`logs, auditbeat,
filebeat, winbeat`) is now used as the default value for the UI setting
"**Logs Explorer allowed data views**", where is possible to add more
base patterns or full indices that should be available for exploration
in Logs Explorer.

## 🎥 Demo


https://github.com/elastic/kibana/assets/34506779/b2d43c2d-e0a3-4315-9d4c-be512a01245f

## 👣 Next steps
- Create a dashboard to track the updates on this setting and link it to
the team docs.

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:LogsExplorer Logs Explorer feature release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-logs Observability Logs User Experience Team v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Logs Explorer] Add logs backed data views support
7 participants