perf(kb): lazy-load KB schemas per namespace/endpoint (#251)#266
Merged
Conversation
✅MegaLinter analysis: Success
See detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
Merged
flobernd
added a commit
that referenced
this pull request
May 13, 2026
- Add `codegen:kibana` target invoking `npx tsx cli/kibana/index.ts` and copying `output/kibana/apis/*.ts` into `src/kb/apis/`. The hand-written lazy loader at `src/kb/apis.ts` is intentionally not overwritten. - Run `scripts/build-api-manifest.mjs` after ES codegen and `scripts/build-kb-manifest.mts` after Kibana codegen so the per-endpoint manifests stay in sync with the generated namespace files. - Stop copying `output/es/index.ts` over `src/es/apis.ts` (it became a hand-written lazy loader in #218). - Fix `build-kb-manifest.mts` to load definitions directly from each `src/kb/apis/*.ts` file (the previous `allKbApis` import was dead since the lazy-loader refactor in #266). Manifest regen also picks up the one endpoint that had been missing as a result. - Workflow: append the kibana step, expand diff-detection and `add-paths` to include `src/kb`, refresh the PR body to list the kibana outputs. - CONTRIBUTING: document the new target. Refs: #79
flobernd
added a commit
that referenced
this pull request
May 13, 2026
- Add `codegen:kibana` target invoking `npx tsx cli/kibana/index.ts` and copying `output/kibana/apis/*.ts` into `src/kb/apis/`. The hand-written lazy loader at `src/kb/apis.ts` is intentionally not overwritten. - Run `scripts/build-api-manifest.mjs` after ES codegen and `scripts/build-kb-manifest.mts` after Kibana codegen so the per-endpoint manifests stay in sync with the generated namespace files. - Stop copying `output/es/index.ts` over `src/es/apis.ts` (it became a hand-written lazy loader in #218). - Fix `build-kb-manifest.mts` to load definitions directly from each `src/kb/apis/*.ts` file (the previous `allKbApis` import was dead since the lazy-loader refactor in #266). Manifest regen also picks up the one endpoint that had been missing as a result. - Workflow: append the kibana step, expand diff-detection and `add-paths` to include `src/kb`, refresh the PR body to list the kibana outputs. - CONTRIBUTING: document the new target. Refs: #79
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
closes #251
elastic stack kbpreviously loaded all 48 namespace files (500 endpoint definitions) and constructed Zod schemas for all of them on every invocation, including--helpsrc/kb/api-manifest.tswith lightweight metadata for all 500 endpoints (no Zod construction)src/kb/apis.tsas a lazy-loading barrel withloadKbApi()/loadKbApisInFile()dynamic import helpersregisterKbCommandsLazy()tosrc/kb/register.ts: sniffsprocess.argvto identify the invoked endpoint, loads only that namespace file, registers everything else as lightweight stubsregisterKbCommands(definitions)for test useelastic stack kb --helpnow runs in ~0.4sTest plan
elastic stack kibana --helpandelastic kb --helpdeprecation redirectelastic stack kb alerting get-alerting-rule-id --helpshows correct flags (lazy load works)elastic stack kb --helplists all namespace groups