Repository navigation
Go: implement system healthz API - #15307
Conversation
📝 WalkthroughWalkthroughThis PR implements a system health check endpoint that reports the status of core dependencies. A new ChangesHealth Check System
Sequence DiagramsequenceDiagram
participant Client
participant Healthz as Healthz Method
participant DB as Database
participant Redis as Redis Cache
participant DocEngine as Document Engine
participant Storage as Storage
Client->>Healthz: Healthz(ctx)
Healthz->>DB: PingContext
DB-->>Healthz: ok/error
Healthz->>Redis: Health Check
Redis-->>Healthz: ok/error
Healthz->>DocEngine: Ping
DocEngine-->>Healthz: ok/error
Healthz->>Storage: Health
Storage-->>Healthz: ok/error
Healthz-->>Client: HealthzResponse, allOK
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
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. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/service/system_test.go (1)
16-18: ⚡ Quick winStrengthen
_metacontract assertions per dependency.Current check only verifies
_metais non-empty. It’s safer to assert keys fordb,redis,doc_engine, andstorageso regressions in failure-detail coverage are caught.✅ Suggested test hardening
- if len(result.Meta) == 0 { - t.Fatal("expected failure metadata") - } + for _, k := range []string{"db", "redis", "doc_engine", "storage"} { + if _, ok := result.Meta[k]; !ok { + t.Fatalf("expected failure metadata for %s, got: %+v", k, result.Meta) + } + }🤖 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 `@internal/service/system_test.go` around lines 16 - 18, The test currently only checks that result.Meta is non-empty; update the assertion in internal/service/system_test.go to verify that result.Meta contains the specific keys "db", "redis", "doc_engine", and "storage". Locate the test using result.Meta and replace the generic len(result.Meta) == 0 check with explicit existence checks (e.g., lookup or map key assertions) for each of those keys so the test fails if any dependency metadata is missing. Ensure the assertions fail with clear messages referencing the missing key names.
🤖 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 `@internal/service/system.go`:
- Around line 98-100: The healthz response currently assigns raw err.Error()
into meta.Error which can leak internals; instead set meta.Error to a generic
sanitized message (e.g., "internal error" or "unavailable") before returning
from the healthz handler, and log the original err on the server side (use the
existing logger in this package) for diagnostics; replace the direct meta.Error
= err.Error() assignment (and return) with a sanitized message plus a
server-side log that includes err so callers of /api/v1/system/healthz do not
receive internal details.
---
Nitpick comments:
In `@internal/service/system_test.go`:
- Around line 16-18: The test currently only checks that result.Meta is
non-empty; update the assertion in internal/service/system_test.go to verify
that result.Meta contains the specific keys "db", "redis", "doc_engine", and
"storage". Locate the test using result.Meta and replace the generic
len(result.Meta) == 0 check with explicit existence checks (e.g., lookup or map
key assertions) for each of those keys so the test fails if any dependency
metadata is missing. Ensure the assertions fail with clear messages referencing
the missing key names.
🪄 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: CHILL
Plan: Pro
Run ID: 62deba2e-e2fe-412a-a113-c0c94cb5e2f1
📒 Files selected for processing (4)
internal/handler/system.gointernal/router/router.gointernal/service/system.gointernal/service/system_test.go
| if err != nil { | ||
| meta.Error = err.Error() | ||
| return false, meta |
There was a problem hiding this comment.
Sanitize _meta.error before returning it from the public healthz endpoint.
Line 99 forwards raw err.Error() into the response. Since /api/v1/system/healthz is unauthenticated (internal/router/router.go, Line 103), this can leak internal infra details.
🔧 Proposed fix
func timedHealthCheck(check func() error) (bool, HealthzMeta) {
start := time.Now()
err := check()
meta := HealthzMeta{
Elapsed: fmt.Sprintf("%.1f", float64(time.Since(start).Microseconds())/1000.0),
}
if err != nil {
- meta.Error = err.Error()
+ // Avoid leaking backend internals on public health endpoint.
+ meta.Error = "dependency check failed"
return false, meta
}
return true, meta
}🤖 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 `@internal/service/system.go` around lines 98 - 100, The healthz response
currently assigns raw err.Error() into meta.Error which can leak internals;
instead set meta.Error to a generic sanitized message (e.g., "internal error" or
"unavailable") before returning from the healthz handler, and log the original
err on the server side (use the existing logger in this package) for
diagnostics; replace the direct meta.Error = err.Error() assignment (and return)
with a sanitized message plus a server-side log that includes err so callers of
/api/v1/system/healthz do not receive internal details.
Haruko386
left a comment
There was a problem hiding this comment.
@tmimmanuel LGTM
Thank you for you contribution
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15307 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
GET /api/v1/system/healthz.ok/nokdependency fields for DB, Redis, document engine, and storage._metafailure details.Scope
This is a small, isolated slice of #15240. It avoids current open connector PRs (#15274, #15300, #15265, #15264), tenant/member PRs (#15295, #15301, #15276), MCP PRs (#15281, #15253, #15254, #15260, #15261, #15262), and the memory-message PR (#15256).
Refs #15240
Tests