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

chore(NA): add async import into infra plugin to reduce apm bundle size #63292

Merged
merged 15 commits into from
Apr 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions x-pack/plugins/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/p
import { DataEnhancedSetup, DataEnhancedStart } from '../../data_enhanced/public';

import { TriggersAndActionsUIPublicPluginSetup } from '../../../plugins/triggers_actions_ui/public';
import { getAlertType as getMetricsAlertType } from './components/alerting/metrics/metric_threshold_alert_type';
import { getAlertType as getLogsAlertType } from './components/alerting/logs/log_threshold_alert_type';

export type ClientSetup = void;
export type ClientStart = void;
Expand Down Expand Up @@ -53,9 +51,6 @@ export class Plugin
setup(core: CoreSetup, pluginsSetup: ClientPluginsSetup) {
registerFeatures(pluginsSetup.home);

pluginsSetup.triggers_actions_ui.alertTypeRegistry.register(getMetricsAlertType());
pluginsSetup.triggers_actions_ui.alertTypeRegistry.register(getLogsAlertType());

core.application.register({
id: 'logs',
title: i18n.translate('xpack.infra.logs.pluginTitle', {
Expand All @@ -70,6 +65,8 @@ export class Plugin
const plugins = getMergedPlugins(pluginsSetup, pluginsStart as ClientPluginsStart);
const { startApp, composeLibs, LogsRouter } = await this.downloadAssets();

await this.registerLogsAlertType(pluginsSetup);

return startApp(
composeLibs(coreStart),
coreStart,
Expand All @@ -95,6 +92,8 @@ export class Plugin
const plugins = getMergedPlugins(pluginsSetup, pluginsStart as ClientPluginsStart);
const { startApp, composeLibs, MetricsRouter } = await this.downloadAssets();

await this.registerMetricsAlertType(pluginsSetup);

return startApp(
composeLibs(coreStart),
coreStart,
Expand Down Expand Up @@ -138,4 +137,24 @@ export class Plugin
MetricsRouter,
};
}

// NOTE: apm is importing from `infra/public` and async importing that
// allow us to reduce the apm bundle size
private async registerLogsAlertType(pluginsSetup: ClientPluginsSetup) {
const { getAlertType } = await import('./components/alerting/logs/log_threshold_alert_type');

if (!pluginsSetup.triggers_actions_ui.alertTypeRegistry.has(getAlertType().id)) {
pluginsSetup.triggers_actions_ui.alertTypeRegistry.register(getAlertType());
}
}

private async registerMetricsAlertType(pluginsSetup: ClientPluginsSetup) {
const { getAlertType } = await import(
'./components/alerting/metrics/metric_threshold_alert_type'
);

if (!pluginsSetup.triggers_actions_ui.alertTypeRegistry.has(getAlertType().id)) {
pluginsSetup.triggers_actions_ui.alertTypeRegistry.register(getAlertType());
}
}
}