-
Notifications
You must be signed in to change notification settings - Fork 975
feat: add HTTP health check API for Kubernetes integration #3047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
feat: add HTTP health check API for Kubernetes integration #3047
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive HTTP health check API support for Kubernetes integration, enabling liveness and readiness probes for container orchestration. The implementation provides a configurable, extensible health check system that integrates seamlessly with dubbo-go's existing architecture.
Key changes:
- Implements configurable HTTP health endpoints (/health/live and /health/ready) for Kubernetes probes
- Provides extensible HealthChecker interface allowing custom health logic implementation
- Adds built-in health checkers for common scenarios (Dubbo services, graceful shutdown, timeout protection)
Reviewed Changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| server/health_checker.go | Core health checker interfaces and composite implementation |
| server/health.go | HTTP server implementation with JSON response handling |
| server/builtin_health_checkers.go | Built-in health checker implementations for common use cases |
| metrics/health/health_registry.go | Integration with metrics system for automatic server lifecycle |
| imports/imports.go | Import registration for health metrics collector |
| config/metric_config.go | Configuration structure for health check settings |
| common/constant/key.go | Configuration keys for health check parameters |
| common/constant/default.go | Default values for health check configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| result.Details["services"] = "none_exported" | ||
| } else { | ||
| result.Details["services"] = "exported" | ||
| result.Details["service_count"] = string(rune(serviceCount)) |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting integer to string via rune cast is incorrect and will produce unexpected results. Use strconv.Itoa(serviceCount) instead.
| handler := h.handler | ||
| h.mu.RUnlock() | ||
|
|
||
| ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 5-second timeout is hardcoded in multiple places. Consider extracting this as a configurable constant or deriving it from the health check timeout configuration.
| handler := h.handler | ||
| h.mu.RUnlock() | ||
|
|
||
| ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 5-second timeout is hardcoded in multiple places. Consider extracting this as a configurable constant or deriving it from the health check timeout configuration.
| type DefaultHealthCheckHandler struct{} | ||
|
|
||
| func (d *DefaultHealthCheckHandler) HandleLivenessCheck(w http.ResponseWriter, r *http.Request, result *HealthCheckResult) { | ||
| status := "UP" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to const, same with 'DOWN'
| timeoutStr := h.url.GetParam(constant.HealthCheckTimeoutKey, constant.HealthCheckDefaultTimeout) | ||
| timeout, err := time.ParseDuration(timeoutStr) | ||
| if err != nil { | ||
| timeout = 10 * time.Second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to return an error directly so that users can know that their configuration is wrong
| func (d *DefaultHealthChecker) CheckReadiness(ctx context.Context) bool { | ||
| // Basic readiness: assume ready | ||
| return true | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default checker's survival check returns true by default, which is fine. The readiness check can do a little more, such as checking the current service registration status. you can refer https://www.bookstack.cn/read/dubbo-3.1-zh/3b6bb5d2b90f4b85.md
| handler := h.handler | ||
| h.mu.RUnlock() | ||
|
|
||
| ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why hard-code 5 seconds
|
plz add unit test |
|
pls fix ci fail |



feat: add HTTP health check API for Kubernetes integration
Add comprehensive HTTP health check support for liveness and readiness probes to enable
seamless Kubernetes deployment and container orchestration.
Background
Kubernetes requires HTTP endpoints for health probes to determine container lifecycle:
This implementation provides a robust, extensible health check system that integrates
with dubbo-go's existing architecture while allowing users to define custom health logic.
Implementation
Core Components
Key Features
Changes Made
Usage
Configuration
Custom Health Checker
Kubernetes Deployment
API Responses
Healthy Response (200 OK)
{ "status": "UP", "timestamp": 1640995200000, "details": { "check": "readiness", "database": "connected", "services": "exported" } }Unhealthy Response (503 Service Unavailable)
{ "status": "DOWN", "timestamp": 1640995200000, "message": "Database connection failed", "details": { "check": "readiness", "database": "unavailable", "reason": "connection_timeout" } }Benefits
Testing
Health check endpoints can be tested using:
Fixes: #2039
Enables: Kubernetes-native health monitoring and container lifecycle management