feat(cli): add elastic status command to verify connectivity and auth#362
Merged
Conversation
Adds `elastic status`: a top-level command that pings each configured
service in the active context (elasticsearch, kibana, cloud) in parallel
and reports per-service health. Output matches the issue mock — aligned
columns with check/cross glyphs by default, `{ context, services }`
under `--json`.
The handler loads the config itself (bypassing the preAction hook) so a
partially broken context is reported as a structured `config_error`
envelope instead of crashing before any probe runs. Exit code is 1 if
any configured service fails, 0 if all succeed; services missing from
the context are omitted rather than shown as errors. `--use-context`
plumbs through so a non-default context can be checked without
switching.
Closes #317
Other changes:
- `LoadConfigOk` now exposes the resolved `contextName` so handlers can
report which context they probed.
- Auth-header construction (`api_key` / basic) extracted to a new
`src/lib/auth.ts` helper, replacing duplicated logic in `EsClient`,
`KibanaClient`, and the new status probes.
Contributor
✅MegaLinter analysis: Success
Notices📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining See detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
Bun initialises `process.exitCode` to `0`, whereas Node leaves it
`undefined` until something sets it. Asserting `exitCode === undefined`
for the "no failure" case passed on Node but failed on Bun.
Compare against the failure value (`!== 1`) instead, which matches the
semantic intent ("the handler did not flag failure") and works on both
runtimes.
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
Adds
elastic status, a top-level command that pings each configured service in the active context (elasticsearch,kibana,cloud) concurrently and reports per-service connectivity and auth. Closes #317.Under
--jsonit emits{ context, services: { elasticsearch?, kibana?, cloud? } }matching the shape in the issue. Exit code is1if any configured service fails,0if all succeed. Services missing from the context are omitted (not shown as errors).--use-context <name>plumbs through so a non-default context can be checked without switching.Why this shape
loadConfigand thepreActionhook is bypassed forstatus(seesrc/cli.ts) so a partially broken config is reported as a structuredconfig_errorenvelope rather than crashing before any probe runs. The issue explicitly calls this out as the reason a user reaches forstatusin the first place.Promise.allSettledand each returns a structured{ ok, ... }result; one failure cannot block another.fetchrather than the existingEsClient/KibanaClient/CloudClientclasses because those throw on non-2xx, andstatusneeds to classify HTTP failures (401/403 →auth failed, other non-2xx →request failed, fetch throws →network error) into per-row UX rather than propagating exceptions.Other changes
LoadConfigOknow exposes the resolvedcontextNameso handlers can report which context they probed (used by the status handler when forming the output header).api_key→ApiKey ..., username+password →Basic ...) extracted to a newsrc/lib/auth.tshelper. Replaces duplicated logic inEsClient,KibanaClient, and the new status probes. Cloud client unchanged (api-key only).Test plan
npm run buildcleannpm test— 1257 unit tests pass (was 1258 before; one contrived edge-case test removed alongside the duplicate auth-header code it covered)npm run test:lintclean./scripts/check-spdxclean on all new filessrc/lib/auth.ts100/100/100;src/status/checks.ts100/97.87/100;src/status/format.ts100/95.45/100;src/status/register.ts98.44/86.21/91.67 — all above the repo's 90% barelastic statusreportsnetwork error: fetch failedper row and exits1--jsonand--use-context nonexistent:{"error":{"code":"config_error","message":"Context \"nonexistent\" not found. ..."}}and exits1--dry-run: factory's generic dry-run path fires, exits0, no HTTP callsOut of scope
Latency reporting, TLS / cert diagnostics, and "did you mean…?" suggestions are all reasonable follow-ups but not in the issue's acceptance criteria.