Skip to content

feat(natsapi): add health endpoint over NATS request-reply#269

Merged
taigrr merged 1 commit into
masterfrom
cd/nats-health-endpoint
Mar 31, 2026
Merged

feat(natsapi): add health endpoint over NATS request-reply#269
taigrr merged 1 commit into
masterfrom
cd/nats-health-endpoint

Conversation

@taigrr
Copy link
Copy Markdown
Member

@taigrr taigrr commented Mar 31, 2026

Summary

Adds a grlx.api.health NATS subject handler to the farmer, providing health status, uptime, and NATS connection readiness over the NATS bus. This is part of the NATS-only migration — moving monitoring endpoints from HTTP to NATS request-reply.

Changes

  • internal/natsapi/health.go: New handler returning HealthResponse with status (ok/degraded), uptime, uptime_ms, and nats_ready fields
  • internal/natsapi/subjects.go: MethodHealth constant and HealthCheckResponse type alias
  • internal/natsapi/router.go: Register health handler in the routes map
  • internal/natsapi/middleware.go: RBAC mapping (ActionView) and public method (no auth token required, like version)
  • internal/api/client/health.go: CLI client Health() function for NATS request
  • cmd/grlx/cmd/health.go: grlx health CLI command with text and JSON output modes

Testing

  • 3 handler tests (degraded/ok/uptime verification)
  • 5 client tests (success/degraded/error/bad JSON/no connection)
  • All existing tests pass (go test -race ./...)
  • Lint clean (staticcheck)

Context

Part of the NATS migration plan (architecture.md). The existing HTTP /health endpoint remains for unauthenticated monitoring, but this NATS endpoint gives authenticated users richer health data including NATS bus connectivity.

Add grlx.api.health NATS subject handler that returns farmer status,
uptime, and NATS connection readiness. Reports 'degraded' when the
NATS connection is down.

- internal/natsapi/health.go: handler with HealthResponse type
- internal/natsapi/subjects.go: MethodHealth constant and response type
- internal/natsapi/router.go: register health handler in routes map
- internal/natsapi/middleware.go: RBAC mapping (ActionView, public)
- internal/api/client/health.go: CLI client Health() function
- cmd/grlx/cmd/health.go: 'grlx health' CLI command (text + JSON)
- Tests for both natsapi handler and client layers
@taigrr taigrr merged commit 4fff099 into master Mar 31, 2026
6 of 7 checks passed
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.

1 participant