Skip to content

[Logs UI] <LogStream /> as a kibana embeddable#88618

Merged
afgomez merged 12 commits intoelastic:masterfrom
afgomez:84549-log-stream-embeddable
Feb 1, 2021
Merged

[Logs UI] <LogStream /> as a kibana embeddable#88618
afgomez merged 12 commits intoelastic:masterfrom
afgomez:84549-log-stream-embeddable

Conversation

@afgomez
Copy link
Copy Markdown
Contributor

@afgomez afgomez commented Jan 18, 2021

Summary

Expose the <LogStream /> component as a kibana embeddable.

Closes #84549

How to test

  1. The user needs to have the infra plugin enabled and data in any filebeat-* or logs-* index.
  2. Create an index pattern (the pattern itself doesn't matter, but it's a requirement for the next step).
  3. Create a dashboard.
  4. Click on "Add from library"

Screenshot 2021-01-21 at 21 06 51

4. Click on "Create new" and then select "Log Stream"

Screenshot 2021-01-21 at 21 06 59

5. A log stream embeddable should appear. It should update when the date range or the query changes.

Screenshots

Screenshot 2021-01-21 at 14 28 50

Notes/ToDo

  • The <LogStream /> component accepts KQL queries. I need to find a way to either translate lucene queries into KQL, or modify the component to also take lucene queries.
  • The bundle size limit of the infra plugin has been increased to accommodate the code on this PR. We want to look into the bundle on a separate issue to see where we can remove weight.

Checklist

Delete any items that are not applicable to this PR.

  • Documentation was added for features that require explanation or tutorials

@afgomez afgomez force-pushed the 84549-log-stream-embeddable branch 3 times, most recently from bcf5b6c to 6766aed Compare January 20, 2021 17:44
@afgomez afgomez force-pushed the 84549-log-stream-embeddable branch from 102370d to b487a0a Compare January 21, 2021 19:58
@afgomez afgomez marked this pull request as ready for review January 21, 2021 20:14
@afgomez afgomez requested review from a team as code owners January 21, 2021 20:14
@afgomez afgomez added Feature:Logs UI Logs UI feature release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.12.0 labels Jan 25, 2021
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui)

@afgomez
Copy link
Copy Markdown
Contributor Author

afgomez commented Jan 25, 2021

@elasticmachine merge upstream

@Kerry350 Kerry350 self-requested a review January 25, 2021 11:56
Copy link
Copy Markdown
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

Bundle limits LGTM, will be reduced in resolving #89025

Copy link
Copy Markdown
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.

Not a code review, but our earlier conversation about the bundle size provoked my curiosity to see whether anything can be done quickly.

Just wanted to persist my thoughts, feel free to ignore. 😉


public async create(initialInput: LogStreamEmbeddableInput, parent?: IContainer) {
const services = await this.getCoreServices();
return new LogStreamEmbeddable(services, initialInput, parent);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we await import() this in here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could we await import() this in here?

we can try, but given the size of the LogStreamEmbeddable module I'm not sure it will be worth it. Whatever gains we have in the bundle size will probably get lost with the overhead of the extra network request.


export class LogStreamEmbeddableFactoryDefinition
implements EmbeddableFactoryDefinition<LogStreamEmbeddableInput> {
public readonly type = LOG_STREAM_EMBEDDABLE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we duplicate the constant or put it into a separate file in combination with importing the LogStreamEmbeddable asynchronously (see below), couldn't we avoid the sync runtime import?

} from './types';
import { getLogsHasDataFetcher, getLogsOverviewDataFetcher } from './utils/logs_overview_fetchers';
import { createMetricsHasData, createMetricsFetchData } from './metrics_overview_fetchers';
import { LOG_STREAM_EMBEDDABLE } from './components/log_stream/log_stream_embeddable';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we imported the constant from a separate file here too, wouldn't that turn this into a cheaper import?

Copy link
Copy Markdown
Contributor

@Kerry350 Kerry350 left a comment

Choose a reason for hiding this comment

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

Code looks good, and works great 🎉

Screenshot 2021-01-27 at 12 26 24

Since the <LogStream /> component is so popular it might be nice to provide an example in the docs or Storybook for how solutions can use the embeddable directly outside of the dashboard context. There's an <EmbeddableRenderer /> component that cuts down a lot of the boilerplate.

import { EmbeddableRenderer } from 'src/plugins/embeddable/public'
const { embeddable: embeddablePlugin } = useKibanaContextForPlugin().services;
const factory: any = embeddablePlugin.getEmbeddableFactory(LOG_STREAM_EMBEDDABLE);

  const embeddableInput: LogStreamEmbeddableInput = useMemo(() => {
    return {
      timeRange,
      query
    }
  }, [timeRange, query]);

  return (
    <EmbeddableRenderer input={embeddableInput} factory={factory} />
  )

Feel free to ignore though, I know adoption has been absolutely fine without the embeddable 😄

return queryObj.query as string;
}

if (queryObj.language === 'lucene') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Do you want to address that in a separate followup? Do we know if there's something in the data plugin that could help there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanna tackle this today in this PR. I haven't looked into it yet, but I think what makes the most sense is to allow the <LogStream /> component to accept lucene queries, something like:

<LogStream
  query="whatever"
  queryLang="lucene"
/>

The queryLang will be optional and will default to "KQL", so we don't break anything.

Do you think it makes sense?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool, sounds good. There's a Query type provided by the data plugin, and it probably makes most sense to use that as our prop so we're following the conventions set there.

The ML anomaly swimlane embeddable uses that here: https://github.com/elastic/kibana/blob/master/x-pack/plugins/ml/public/embeddables/types.ts#L34, and the type looks like so: https://github.com/elastic/kibana/blob/master/src/plugins/data/common/query/types.ts#L12

So it's basically exactly what you've said, but it's nice to buy into the data stuff where we can.

@afgomez afgomez requested a review from Kerry350 January 28, 2021 11:45
@afgomez
Copy link
Copy Markdown
Contributor Author

afgomez commented Jan 28, 2021

@Kerry350 do you mind taking another look at the last commits? The embeddable handles lucene queries now

Copy link
Copy Markdown
Contributor

@Kerry350 Kerry350 left a comment

Choose a reason for hiding this comment

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

Lucene changes LGTM 👌

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
infra 1098 1101 +3

Async chunks

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

id before after diff
infra 2.2MB 2.2MB -9.7KB

Page load bundle

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

id before after diff
infra 161.3KB 172.3KB +11.0KB

History

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

@afgomez afgomez merged commit 53637d0 into elastic:master Feb 1, 2021
@afgomez afgomez deleted the 84549-log-stream-embeddable branch February 1, 2021 13:48
afgomez pushed a commit that referenced this pull request Feb 2, 2021
Co-authored-by: Kibana Machine <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

Feature:Logs UI Logs UI feature release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.12.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Logs] Investigate how we can make the Log Stream component available as a Kibana Embeddable

6 participants