Documentation
¶
Overview ¶
Package health provides health check functionality.
Index ¶
- func AddHealthStatus(serviceName string, status string)
- func CheckAuth() map[string]CheckResult
- func GetHealthHistory() map[string][]HistoryPoint
- func NewChecker(uc *configv1.UpstreamServiceConfig) health.Checker
- func SetGlobalAlertConfig(cfg *configv1.AlertConfig)
- type CheckFunc
- type CheckResult
- type Doctor
- type DoctorReport
- type HTTPServiceWithHealthCheck
- type HistoryPoint
- type ServiceHealthHistory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHealthStatus ¶
AddHealthStatus adds a status point to the history.
Summary: Records a new health status point for a service.
Parameters:
- serviceName: string. The name of the service.
- status: string. The health status (e.g., "healthy", "unhealthy").
Side Effects:
- Updates the global historyStore.
- Prunes history if it exceeds 1000 points.
func CheckAuth ¶
func CheckAuth() map[string]CheckResult
CheckAuth performs health checks for authentication configuration.
Summary: Validates the presence of critical API keys and OAuth configuration.
Returns:
- map[string]CheckResult: A map of check names to their results.
Side Effects:
- Reads environment variables.
func GetHealthHistory ¶
func GetHealthHistory() map[string][]HistoryPoint
GetHealthHistory returns the history for all services.
Summary: Retrieves the complete health history map.
Returns:
- map[string][]HistoryPoint: A map of service names to their health history points.
Side Effects:
- Acquires a read lock on the history store.
func NewChecker ¶
func NewChecker(uc *configv1.UpstreamServiceConfig) health.Checker
NewChecker creates a new health checker for the given upstream service.
It determines the type of service (HTTP, gRPC, etc.) and creates an appropriate health check strategy wrapped with latency metrics and status change listeners.
Parameters:
- uc: *configv1.UpstreamServiceConfig. The configuration of the upstream service to check.
Returns:
- health.Checker: A configured health checker instance. Returns nil if the configuration is nil or invalid.
Side Effects:
- Registers metrics for the health check.
Summary: Initializes NewChecker operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func SetGlobalAlertConfig ¶
func SetGlobalAlertConfig(cfg *configv1.AlertConfig)
SetGlobalAlertConfig sets the global alert configuration.
It updates the thread-safe global configuration used for sending alerts on health status changes.
Parameters:
- cfg: *configv1.AlertConfig. The new alert configuration.
Returns:
None.
Side Effects:
- Updates a global variable protected by a mutex.
Summary: Updates SetGlobalAlertConfig operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
Types ¶
type CheckFunc ¶
type CheckFunc func(context.Context) CheckResult
CheckFunc is a function that performs a health check.
Summary: Function signature for a health check execution logic.
type CheckResult ¶
type CheckResult struct {
Status string `json:"status"`
Message string `json:"message,omitempty"`
Latency string `json:"latency,omitempty"`
Diff string `json:"diff,omitempty"`
}
CheckResult represents a single check result.
Summary: The outcome of a single health check execution.
type Doctor ¶
type Doctor struct {
// contains filtered or unexported fields
}
Doctor is the health check handler.
Summary: Registry and handler for system health checks (Doctor).
func NewDoctor ¶
func NewDoctor() *Doctor
NewDoctor creates a new Doctor.
Summary: Initializes a new Doctor instance.
Returns:
- *Doctor: The initialized doctor registry.
Side Effects:
- Initializes internal maps and HTTP client.
func (*Doctor) AddCheck ¶
AddCheck adds a named health check.
Summary: Registers a custom health check function.
Parameters:
- name: string. The unique name of the check.
- check: CheckFunc. The function to execute.
Side Effects:
- Updates the internal checks map.
func (*Doctor) Handler ¶
func (d *Doctor) Handler() http.HandlerFunc
Handler returns the http handler.
Summary: Returns an HTTP handler that runs all checks and returns a JSON report.
Returns:
- http.HandlerFunc: The HTTP handler.
Side Effects:
- Executes all registered health checks.
- Makes an external network call to google.com (connectivity check).
- Reads environment variables (Auth checks).
- Writes JSON response to the client.
type DoctorReport ¶
type DoctorReport struct {
Status string `json:"status"`
Timestamp time.Time `json:"timestamp"`
Checks map[string]CheckResult `json:"checks"`
}
DoctorReport represents the full doctor report.
Summary: Aggregated health report containing all check results.
type HTTPServiceWithHealthCheck ¶
type HTTPServiceWithHealthCheck interface {
// GetAddress returns the address of the service.
//
// Returns:
// - string: The network address of the service.
GetAddress() string
// GetHealthCheck returns the HTTP health check configuration for the service.
//
// Returns:
// - *configv1.HttpHealthCheck: The health check configuration.
GetHealthCheck() *configv1.HttpHealthCheck
}
HTTPServiceWithHealthCheck is an interface for services that have an address and an HTTP health check.
Summary: Represents a HTTPServiceWithHealthCheck.
type HistoryPoint ¶
type HistoryPoint struct {
Timestamp int64 `json:"timestamp"` // Unix millis
Status string `json:"status"`
}
HistoryPoint represents a single point in time for a service's health.
Summary: A data point representing service health status at a specific time.
type ServiceHealthHistory ¶
type ServiceHealthHistory struct {
Points []HistoryPoint
}
ServiceHealthHistory stores the history for a service.
Summary: Collection of historical health data points for a service.