Skip to content

fix: load cluster stats schema - #841

Open
margaretjgu wants to merge 3 commits into
fix/cat-column-listsfrom
fix/cluster-stats-input
Open

margaretjgu wants to merge 3 commits into
fix/cat-column-listsfrom
fix/cluster-stats-input

Conversation

@margaretjgu

Copy link
Copy Markdown
Member

Load the cluster stats request schema when the tool definition has no input. Relates to #839.

@margaretjgu margaretjgu added the auto-loop Opt this PR into the CI and review repair loop label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

👋 This PR can use the first-failure repair loop on GitHub Actions and Buildkite.

Labels

  • auto-loop: triage the first CI or Buildkite failure and commit in-repo fixes (also AI review and CodeQL)
  • skip-ai-review: silences the review bot
  • skip-auto-loop: halt the repair loop (also added when you comment /stop)

Comments

  • /stop: halt the repair loop
  • /bad on a finding: the bot writes a short do not re-flag line from the finding and your note into .github/skills/ai-review-memory.md. A reason is optional.
    • Example: /bad false positive. This path is already encoded.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What failed: The test 'uses the request schema when the tool definition has no input' fails because attachMissingRequestSchema silently skips attaching the request schema when the loaded JSON does not have a top-level properties key. The guard input['properties'] == null is too strict and causes the function to return the original def unchanged when the schema uses allOf or other composition keywords without top-level properties.

Resolution: change src/es/apis.ts to remove the input['properties'] == null check, only rejecting the loaded module if it is not a plain non-array object.

Build: https://buildkite.com/elastic/elastic-cli/builds/2495

@margaretjgu margaretjgu removed the auto-loop Opt this PR into the CI and review repair loop label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

✅MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 0.71s
✅ REPOSITORY gitleaks yes no no 62.11s
✅ REPOSITORY git_diff yes no no 0.17s
✅ REPOSITORY secretlint yes no no 17.88s
✅ REPOSITORY trivy yes no no 29.54s
✅ TYPESCRIPT eslint 6 0 0 5.31s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Startup perf: PR vs merge-base ✅

command PR base delta
elastic 44.2 ms 43.5 ms +1.7%
elastic --help 44.9 ms 44.3 ms +1.2%
elastic es --help 85.6 ms 85.7 ms -0.2%
elastic es 88.0 ms 85.4 ms +3.1%
elastic cloud --help 46.6 ms 46.8 ms -0.3%
elastic cloud 46.3 ms 47.0 ms -1.5%
elastic kb --help 91.6 ms 87.5 ms +4.7%
elastic kb 88.3 ms 87.0 ms +1.5%
elastic es indices --help 79.2 ms 78.9 ms +0.5%
elastic es indices update-aliases --help 150.5 ms 147.3 ms +2.2%

Comment thread src/es/apis.ts
`@elastic/schemas/es/json/${namespaceFile}.request.json`,
)
if (input == null || typeof input !== 'object' || Array.isArray(input) || input['properties'] == null) return def
return { ...def, input }

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.

This attaches cluster.stats.request.json as-is, which marks node_id as x-found-in: "body" even though it is really a path param in /_cluster/stats/nodes/{node_id}. The resulting --node-id flag builds a broken request.

So the node filter is silently dropped from the URL and sent as a GET body instead, while --dry-run reports the inputs as valid.

Comment thread src/es/apis.ts
Comment on lines +69 to +88
/**
* The tool definition for `cluster.stats` ships without `input` because an
* optional path param is not on the selected URL. The request schema is still
* published next to it, and that schema has the query params (`filter_path`,
* `human`, `timeout`).
*/
async function attachMissingRequestSchema (namespaceFile: string, def: EsApiDefinition): Promise<EsApiDefinition> {
if (def.input != null) return def
try {
const input = await requireSchemaModule<Record<string, unknown>>(
`@elastic/schemas/es/json/${namespaceFile}.request.json`,
)
if (input == null || typeof input !== 'object' || Array.isArray(input) || input['properties'] == null) return def
return { ...def, input }
} catch (err) {
const code = (err as NodeJS.ErrnoException).code
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') return def
throw err
}
}

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.

The root cause is upstream: the schemas-js generator emits cluster_stats_definitions without input, and the request schema it would use has the wrong x-found-in for node_id.

Instead of patching this here, we should fix the code generator or ES spec so all schemas-js consumers get the fix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants