-
-
Notifications
You must be signed in to change notification settings - Fork 845
[server] Add health check HTTP endpoint for Relay server #4297
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: main
Are you sure you want to change the base?
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
Adds a health check HTTP endpoint for the Relay server to monitor service availability and certificate validation. The health check listens on a dedicated HTTP server (default: :9000/health
) and performs WebSocket and QUIC connectivity tests with TLS certificate verification.
- Implements health check endpoint with caching mechanism for 3 seconds
- Adds protocol-specific dial validation for WebSocket and QUIC listeners
- Refactors ALPN constant naming for consistency across the codebase
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 8 comments.
Show a summary per file
File | Description |
---|---|
shared/relay/tls/*.go | Updates ALPN constant from nbalpn to NBalpn for public visibility |
relay/protocol/protocol.go | Adds new Protocol type for listener identification |
relay/server/listener/*.go | Adds Protocol method to listeners and updates interface |
relay/server/server.go | Adds health check support methods and thread-safe listener management |
relay/healthcheck/*.go | Implements health check server with WebSocket and QUIC dial validation |
relay/cmd/root.go | Integrates health check server with proper lifecycle management |
relay/cmd/root.go
Outdated
@@ -40,6 +42,7 @@ type Config struct { | |||
AuthSecret string | |||
LogLevel string | |||
LogFile string | |||
HatcheckListenAddress string |
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 field name 'HatcheckListenAddress' appears to be a typo. It should be 'HealthcheckListenAddress' or 'HealthCheckListenAddress'.
HatcheckListenAddress string | |
HealthcheckListenAddress string |
Copilot uses AI. Check for mistakes.
relay/cmd/root.go
Outdated
@@ -87,6 +90,7 @@ func init() { | |||
rootCmd.PersistentFlags().StringVarP(&cobraConfig.AuthSecret, "auth-secret", "s", "", "auth secret") | |||
rootCmd.PersistentFlags().StringVar(&cobraConfig.LogLevel, "log-level", "info", "log level") | |||
rootCmd.PersistentFlags().StringVar(&cobraConfig.LogFile, "log-file", "console", "log file") | |||
rootCmd.PersistentFlags().StringVarP(&cobraConfig.HatcheckListenAddress, "health-listen-address", "H", ":9000", "listen address of healthcheck server") |
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 variable reference 'HatcheckListenAddress' appears to be a typo. It should be 'HealthcheckListenAddress' or 'HealthCheckListenAddress' to match the corrected field name.
rootCmd.PersistentFlags().StringVarP(&cobraConfig.HatcheckListenAddress, "health-listen-address", "H", ":9000", "listen address of healthcheck server") | |
rootCmd.PersistentFlags().StringVarP(&cobraConfig.HealthcheckListenAddress, "health-listen-address", "H", ":9000", "listen address of healthcheck server") |
Copilot uses AI. Check for mistakes.
relay/cmd/root.go
Outdated
if err := srv.Listen(srvListenerCfg); err != nil { | ||
log.Fatalf("failed to bind server: %s", err) | ||
} | ||
}() | ||
|
||
hCfg := healthcheck.Config{ | ||
ListenAddress: cobraConfig.HatcheckListenAddress, |
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 variable reference 'HatcheckListenAddress' appears to be a typo. It should be 'HealthcheckListenAddress' or 'HealthCheckListenAddress' to match the corrected field name.
ListenAddress: cobraConfig.HatcheckListenAddress, | |
ListenAddress: cobraConfig.HealthcheckListenAddress, |
Copilot uses AI. Check for mistakes.
relay/healthcheck/healthcheck.go
Outdated
|
||
const ( | ||
statusHealthy = "healthy" | ||
statusUnHealthy = "unHealthy" |
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 constant 'statusUnHealthy' should be 'statusUnhealthy' (lowercase 'h') to follow standard English spelling.
statusUnHealthy = "unHealthy" | |
statusUnhealthy = "unhealthy" |
Copilot uses AI. Check for mistakes.
relay/healthcheck/healthcheck.go
Outdated
status.Status = statusUnHealthy | ||
healthy = false | ||
} | ||
status.Listeners = listeners | ||
|
||
if ok := s.validateCertificate(ctx); !ok { | ||
status.Status = statusUnHealthy |
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 status assignment should use 'statusUnhealthy' instead of 'statusUnHealthy' to match the corrected constant name.
status.Status = statusUnHealthy | |
healthy = false | |
} | |
status.Listeners = listeners | |
if ok := s.validateCertificate(ctx); !ok { | |
status.Status = statusUnHealthy | |
status.Status = statusUnhealthy | |
healthy = false | |
} | |
status.Listeners = listeners | |
if ok := s.validateCertificate(ctx); !ok { | |
status.Status = statusUnhealthy |
Copilot uses AI. Check for mistakes.
relay/healthcheck/healthcheck.go
Outdated
status.Listeners = listeners | ||
|
||
if ok := s.validateCertificate(ctx); !ok { | ||
status.Status = statusUnHealthy |
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 status assignment should use 'statusUnhealthy' instead of 'statusUnHealthy' to match the corrected constant name.
Copilot uses AI. Check for mistakes.
relay/server/listener/ws/listener.go
Outdated
Proto protocol.Protocol = "ws" | ||
URLPath = relay.WebSocketURLPath | ||
) | ||
|
||
// URLPath is the path for the websocket connection. |
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.
This comment is now redundant since URLPath is defined as a constant above. The comment should be removed or moved to the constant definition.
// URLPath is the path for the websocket connection. |
Copilot uses AI. Check for mistakes.
defer func() { | ||
_ = resp.Body.Close() | ||
}() | ||
|
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.
[nitpick] The empty line after the anonymous function declaration creates unnecessary whitespace. Remove the blank line for cleaner code formatting.
Copilot uses AI. Check for mistakes.
|
Describe your changes
The health check endpoint listens on a dedicated HTTP server.
By default, it is available at
0.0.0.0:9000/health
. This can be configured using the--health-listen-address
flag.The results are cached for 3 seconds to avoid excessive calls.
The health check performs the following:
Issue ticket number and link
Stack
Checklist