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

async-import plugins in the server side #170856

Merged
merged 16 commits into from
Nov 15, 2023
Merged

Conversation

afharo
Copy link
Member

@afharo afharo commented Nov 8, 2023

Summary

When Kibana starts, it has to import the file ${plugin}/server/index for all the plugins in order to read the config variable that it's exported from that file.

Since the index file for each plugin loads the ./plugin file, it's indirectly loading all the files of the plugin in one go. This essentially makes Kibana load all the server-side code from all the plugins, even when the plugins might be disabled. While it wasn't a big deal in the Classic offering (most plugins are enabled), on Serverless we are disabling a lot of plugins (and also adding a good amount of Serverless-specific plugins that shouldn't load on Classic).

This PR changes all the ${plugin}/server/index files to follow a pattern like:

import type { PluginConfigDescriptor, PluginInitializerContext } from '@kbn/core/server';

import { configSchema } from './config';

export const config: PluginConfigDescriptor<TypeOf<typeof configSchema>> = {
  schema: configSchema,
};

export const plugin = async (context: PluginInitializerContext) => {
  const { MyPlugin } = await import('./plugin'); // <-- The import has been moved here
  return new MyPlugin(context);
};

Checklist

  • Documentation was added for features that require explanation or tutorials
  • Change the plugin generator's template.

Risk Matrix

Risk Probability Severity Mitigation/Notes
Kibana might show logs in a different order. Low Low One of the FTRs failed because Kibana is now able to report unavailable status before it is actually serving any HTTP traffic. Commit 0404c34 fixed the FTR, but that means we might expect things to slightly change the order in which they occur when Kibana is starting. This should only affect automations that depend on specific log entries because Kibana won't report available until all plugins are correctly setup.

For maintainers

@afharo afharo marked this pull request as ready for review November 10, 2023 15:14
@afharo afharo requested review from a team as code owners November 10, 2023 15:14
@afharo afharo requested a review from a team November 10, 2023 15:14
@afharo afharo requested review from a team as code owners November 10, 2023 15:14
@afharo
Copy link
Member Author

afharo commented Nov 13, 2023

@afharo it would be nice if we could have an ES Lint rule to enforce this pattern

@opauloh, that's a great idea! I've created #171080 to tackle it since it looks to me like an effort on its own 😇

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

Response Ops changes LGTM. Code review only

Copy link
Member

@sabarasaba sabarasaba left a comment

Choose a reason for hiding this comment

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

deployment management changes lgtm!

@kc13greiner kc13greiner self-requested a review November 13, 2023 14:29
Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Thanx for your work here Alejandro! Visualizations team numerous plugins changes LGTM 😄

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

ResponseOps changes LGTM!

Copy link
Contributor

@kc13greiner kc13greiner left a comment

Choose a reason for hiding this comment

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

Kb Security changes LGTM!

Copy link
Contributor

@e40pud e40pud left a comment

Choose a reason for hiding this comment

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

DE changes LGTM!

Copy link
Member

@robbavey robbavey left a comment

Choose a reason for hiding this comment

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

Logstash changes LGTM

Copy link
Contributor

@logeekal logeekal left a comment

Choose a reason for hiding this comment

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

Desk tested security solution and timelines. Both working well. LGTM 🚀

Copy link
Contributor

@michaelolo24 michaelolo24 left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @afharo !

Copy link
Contributor

@PhilippeOberti PhilippeOberti left a comment

Choose a reason for hiding this comment

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

LGTM for Protections Experience team :)

@afharo afharo enabled auto-merge (squash) November 14, 2023 14:48
@kibana-ci
Copy link
Collaborator

kibana-ci commented Nov 14, 2023

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
mapsEms 68 60 -8
Unknown metric groups

API count

id before after diff
mapsEms 68 60 -8

History

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

cc @afharo

@afharo afharo merged commit fd09c26 into elastic:main Nov 15, 2023
40 checks passed
@afharo afharo deleted the plugins-async-import branch November 15, 2023 07:55
delanni added a commit that referenced this pull request Nov 15, 2023
…1275)

## Summary
Fixes type error coming from merge-race:

#170852 - adds a new plugin
#170856 - changes how plugins
should look
jillguyonnet pushed a commit to jillguyonnet/kibana that referenced this pull request Nov 16, 2023
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
jillguyonnet pushed a commit to jillguyonnet/kibana that referenced this pull request Nov 16, 2023
…stic#171275)

## Summary
Fixes type error coming from merge-race:

elastic#170852 - adds a new plugin
elastic#170856 - changes how plugins
should look
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:Embedding Embedding content via iFrame Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Fleet Team label for Observability Data Collection Fleet team Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.