feat(cli): add --health probe and Docker HEALTHCHECK#404
Conversation
Add a `--health` CLI flag that probes the local /health endpoint and exits non-zero on failure, plus a `--health-timeout` to bound the request. Wire it into the Dockerfile as a HEALTHCHECK so container orchestrators can detect an unhealthy gateway without bundling curl/wget into the image. CLI parsing moves to a testable FlagSet (parseCLI) that accepts both single- and double-dash flags and reports parse errors via exit code instead of os.Exit. The probe reuses config.Load so it honors the configured PORT and BASE_PATH. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds ChangesHealth probe CLI feature
Sequence Diagram(s)sequenceDiagram
participant CLI as gomodel binary
participant parseCLI as parseCLI
participant runHealthProbe as runHealthProbe
participant configLoad as config.Load()
participant checkHealthEndpoint as checkHealthEndpoint
participant Server as HTTP /health
CLI->>parseCLI: os.Args[1:], os.Stderr
parseCLI-->>CLI: cliOptions{Health:true, HealthTimeout}
CLI->>runHealthProbe: HealthTimeout
runHealthProbe->>configLoad: Load()
configLoad-->>runHealthProbe: port, base path
runHealthProbe->>checkHealthEndpoint: ctx, http.Client, 127.0.0.1:{port}/{base}/health
checkHealthEndpoint->>Server: GET /health
Server-->>checkHealthEndpoint: 200 OK {"status":"ok"}
checkHealthEndpoint-->>runHealthProbe: nil
runHealthProbe-->>CLI: nil (exit 0)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
Greptile SummaryThis PR adds a built-in container health probe for GoModel. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "feat(cli): add --health probe and Docker..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/gomodel/flags.go`:
- Around line 18-26: The parseCLI function currently ignores unexpected
positional arguments by returning the result of flags.Parse directly without
validation. After calling flags.Parse(args) in the parseCLI function, add a
check to verify that flags.NArg() is zero. If there are unexpected positional
arguments (when NArg() is greater than 0), return an error with a clear message
instead of silently returning success. This prevents typos and extra arguments
from being silently accepted.
In `@README.md`:
- Around line 279-287: The CLI Operations section in the README.md documentation
is missing documentation for the `--health-timeout` flag. Add a new example line
in the bash code block that demonstrates the `--health-timeout` flag usage with
a timeout value (such as 5s) to make this configuration option discoverable and
show users how to tune the runtime probe timeout behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1a097b2e-d1e8-4413-9287-329166555843
📒 Files selected for processing (8)
DockerfileREADME.mdcmd/gomodel/flags.gocmd/gomodel/flags_test.gocmd/gomodel/health.gocmd/gomodel/health_test.gocmd/gomodel/main.godocs/dev/api-examples.md
| ### CLI Operations | ||
|
|
||
| GoModel accepts both single-dash and double-dash CLI flags. Examples use the | ||
| long form: | ||
|
|
||
| ```bash | ||
| gomodel --version | ||
| gomodel --health | ||
| ``` |
There was a problem hiding this comment.
Document --health-timeout in the CLI section.
The new CLI docs list --version and --health, but omit --health-timeout (including default behavior). Please add it so runtime probe tuning is discoverable.
Suggested patch
GoModel accepts both single-dash and double-dash CLI flags. Examples use the
long form:
```bash
gomodel --version
gomodel --health
+gomodel --health --health-timeout=5s</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
```suggestion
### CLI Operations
GoModel accepts both single-dash and double-dash CLI flags. Examples use the
long form:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@README.md` around lines 279 - 287, The CLI Operations section in the
README.md documentation is missing documentation for the `--health-timeout`
flag. Add a new example line in the bash code block that demonstrates the
`--health-timeout` flag usage with a timeout value (such as 5s) to make this
configuration option discoverable and show users how to tune the runtime probe
timeout behavior.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Add a dedicated Advanced > CLI Operations page documenting --version, --health, --health-timeout, and the Docker HEALTHCHECK usage, and register it in the docs navigation. Drop the brief CLI Operations section from the README so the docs site is the single source of truth. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/advanced/cli.mdx`:
- Around line 40-42: The health probe description in docs/advanced/cli.mdx
(lines 40-42) currently states that the probe "targets the same address the
server listens on," which is misleading because the implementation always
targets loopback (127.0.0.1) and only derives PORT and BASE_PATH from the
configuration, not the host. Revise the sentence to clarify that only the PORT
and BASE_PATH are honored from the server configuration, while the health probe
always targets the loopback interface, making clear that it does not reuse the
full configured listen address.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: a55503c8-d373-435f-a0f5-c40be3139dcb
📒 Files selected for processing (2)
docs/advanced/cli.mdxdocs/docs.json
Address review feedback: - parseCLI now errors on leftover positional arguments so typoed invocations like `gomodel --health extra` fail loudly instead of silently succeeding. - Clarify in the docs that the health probe always targets loopback (127.0.0.1) and only derives PORT/BASE_PATH from config. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/gomodel/flags_test.go`:
- Around line 40-44: The test TestParseCLI_RejectsPositionalArgs only verifies
that an error is returned for positional arguments, but it doesn't verify that
the error maps to the expected exit code 2 (cliParseExitCode). Add an assertion
to check that the returned error from the parseCLI call equals cliParseExitCode,
ensuring the test covers the full contract for parse failures and validates the
non-help branch exit code mapping.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3e1e6ab2-783a-464d-bf78-0de0484bbe6d
📒 Files selected for processing (3)
cmd/gomodel/flags.gocmd/gomodel/flags_test.godocs/advanced/cli.mdx
| func TestParseCLI_RejectsPositionalArgs(t *testing.T) { | ||
| if _, err := parseCLI([]string{"--health", "extra"}, io.Discard); err == nil { | ||
| t.Fatal("parseCLI(--health extra) error = nil, want error") | ||
| } | ||
| } |
There was a problem hiding this comment.
Assert exit-code mapping for positional-argument parse failures.
Line 41 verifies parse failure, but it doesn’t verify that this failure maps to exit code 2 in the main path (cliParseExitCode). Add an assertion on the returned error to cover that contract and the remaining non-help branch in cmd/gomodel/flags.go.
Suggested patch
func TestParseCLI_RejectsPositionalArgs(t *testing.T) {
- if _, err := parseCLI([]string{"--health", "extra"}, io.Discard); err == nil {
+ _, err := parseCLI([]string{"--health", "extra"}, io.Discard)
+ if err == nil {
t.Fatal("parseCLI(--health extra) error = nil, want error")
}
+ if got := cliParseExitCode(err); got != 2 {
+ t.Fatalf("cliParseExitCode(positional args) = %d, want 2", got)
+ }
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cmd/gomodel/flags_test.go` around lines 40 - 44, The test
TestParseCLI_RejectsPositionalArgs only verifies that an error is returned for
positional arguments, but it doesn't verify that the error maps to the expected
exit code 2 (cliParseExitCode). Add an assertion to check that the returned
error from the parseCLI call equals cliParseExitCode, ensuring the test covers
the full contract for parse failures and validates the non-help branch exit code
mapping.
Summary
Adds a
--healthCLI flag and wires it into the Docker image as aHEALTHCHECK, so orchestrators (Docker, Compose, Kubernetes) can detect an unhealthy gateway without bundlingcurl/wgetinto the runtime image.gomodel --healthprobes the local/healthendpoint and exits0when status isok, non-zero otherwise.gomodel --health-timeout <dur>bounds the probe request (default2s).config.Load, so it honors the configuredPORTandBASE_PATHrather than hardcoding an address.FlagSet(parseCLI) that accepts both single- and double-dash flags and reports parse errors via exit code instead ofos.Exit.User-visible impact
--health/--health-timeoutflags (documented in README anddocs/dev/api-examples.md).Tests
parseCLI: single/double-dash flags, unknown-flag rejection, exit-code mapping.healthProbeURL: port/base-path composition incl. default-port fallback.checkHealthEndpoint: healthy, bad status code, bad body, unhealthy status.runHealthProbe: end-to-end against an httptest server on the configured port/base path.All pre-commit hooks pass (
make test-race,make lint).🤖 Generated with Claude Code
Summary by CodeRabbit
gomodel --healthfor runtime health probing (expects HTTP 200 with{"status":"ok"}) andgomodel --version.--health-timeoutto control probe timeout.HEALTHCHECKthat runs"/gomodel", "--health"in the runtime image.