Skip to content

Commit 29dbe1d

Browse files
authored
chore: lazy-load server plugin modules (kibana-security) (elastic#266614)
## Summary Lazy-load server plugin implementations via `await import('./plugin')` (and related entrypoint adjustments) from `server/index.ts`, consistent with elastic#170856. The migration in elastic#170856 reduced **startup time by ~4 seconds** in measured scenarios. **Memory savings were not quantified but are expected.** ## CODEOWNERS - `examples/eso_model_version_example` → @elastic/kibana-security - `packages/kbn-mock-idp-plugin` → @elastic/kibana-security ## Follow-up - elastic#171080 — add an ESLint rule so new plugins follow this pattern. --- **Disclaimer:** This PR was prepared with AI assistance (Cursor / Claude); please review thoroughly.
1 parent a1a05fc commit 29dbe1d

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

examples/eso_model_version_example/server/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99

1010
import type { PluginInitializer } from '@kbn/core/server';
11-
import { EsoModelVersionExample } from './plugin';
1211

13-
export const plugin: PluginInitializer<void, void> = async () => new EsoModelVersionExample();
12+
export const plugin: PluginInitializer<void, void> = async () => {
13+
const { EsoModelVersionExample } = await import('./plugin');
14+
return new EsoModelVersionExample();
15+
};

packages/kbn-mock-idp-plugin/moon.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependsOn:
3636
- '@kbn/core-http-server'
3737
- '@kbn/core-http-server-utils'
3838
- '@kbn/i18n'
39+
- '@kbn/core'
3940
tags:
4041
- plugin
4142
- dev

packages/kbn-mock-idp-plugin/server/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10+
import type { PluginInitializerContext } from '@kbn/core/server';
11+
1012
import { ConfigSchema } from './config';
1113

1214
export type { CreateSAMLResponseParams } from './plugin';
13-
export { plugin } from './plugin';
15+
16+
export const plugin = async (initializerContext: PluginInitializerContext) => {
17+
const { plugin: initPlugin } = await import('./plugin');
18+
return initPlugin(initializerContext);
19+
};
1420

1521
export const config = {
1622
schema: ConfigSchema,

packages/kbn-mock-idp-plugin/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
"@kbn/core-http-server",
2626
"@kbn/core-http-server-utils",
2727
"@kbn/i18n",
28+
"@kbn/core",
2829
]
2930
}

0 commit comments

Comments
 (0)