Documentation
¶
Overview ¶
Package health defines the health checking subsystem including check configuration, result tracking, aggregate instance health, and the pluggable Checker interface for custom check types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckSummary ¶
type CheckSummary struct {
CheckID id.ID `json:"check_id"`
Name string `json:"name"`
Status Status `json:"status"`
Latency time.Duration `json:"latency"`
LastResult *HealthResult `json:"last_result,omitempty"`
}
CheckSummary provides a brief overview of a single check's current state.
type CheckType ¶
type CheckType string
CheckType identifies the kind of health check.
const ( // CheckHTTP performs an HTTP GET/HEAD check. CheckHTTP CheckType = "http" // CheckTCP performs a TCP dial check. CheckTCP CheckType = "tcp" // CheckGRPC uses the gRPC health check protocol. CheckGRPC CheckType = "grpc" // CheckCommand executes a command and checks the exit code. CheckCommand CheckType = "command" // CheckCustom is a user-defined check type. CheckCustom CheckType = "custom" )
type Checker ¶
type Checker interface {
// Type returns the check type this checker handles.
Type() CheckType
// Check executes the health check and returns the result.
Check(ctx context.Context, check *HealthCheck) (*HealthResult, error)
}
Checker executes a specific type of health check. Register custom checkers to extend health checking beyond the built-in types.
type CommandChecker ¶
type CommandChecker struct{}
CommandChecker executes a command and checks the exit code.
func NewCommandChecker ¶
func NewCommandChecker() *CommandChecker
NewCommandChecker creates a new command health checker.
func (*CommandChecker) Check ¶
func (c *CommandChecker) Check(ctx context.Context, check *HealthCheck) (*HealthResult, error)
Check executes the command specified in the health check target and returns the result.
func (*CommandChecker) Type ¶
func (c *CommandChecker) Type() CheckType
Type returns the check type this checker handles.
type ConfigureRequest ¶
type ConfigureRequest struct {
InstanceID id.ID `json:"instance_id" validate:"required"`
Name string `json:"name" validate:"required"`
Type CheckType `json:"type" validate:"required"`
Target string `json:"target" validate:"required"`
Interval time.Duration `default:"30s" json:"interval"`
Timeout time.Duration `default:"5s" json:"timeout"`
Retries int `default:"3" json:"retries"`
}
ConfigureRequest holds the parameters for creating or updating a health check.
type GRPCChecker ¶
type GRPCChecker struct {
// contains filtered or unexported fields
}
GRPCChecker performs gRPC health checks against a target address. This is a simplified checker that verifies TCP connectivity to the gRPC endpoint. A full implementation would use the gRPC health checking protocol (grpc.health.v1.Health).
func NewGRPCChecker ¶
func NewGRPCChecker(timeout time.Duration) *GRPCChecker
NewGRPCChecker creates a new gRPC health checker with the given timeout.
func (*GRPCChecker) Check ¶
func (c *GRPCChecker) Check(ctx context.Context, check *HealthCheck) (*HealthResult, error)
Check verifies connectivity to the gRPC endpoint and returns the result.
func (*GRPCChecker) Type ¶
func (c *GRPCChecker) Type() CheckType
Type returns the check type this checker handles.
type HTTPChecker ¶
type HTTPChecker struct {
// contains filtered or unexported fields
}
HTTPChecker performs HTTP GET health checks against a target URL.
func NewHTTPChecker ¶
func NewHTTPChecker(timeout time.Duration) *HTTPChecker
NewHTTPChecker creates a new HTTP health checker with the given timeout.
func (*HTTPChecker) Check ¶
func (c *HTTPChecker) Check(ctx context.Context, check *HealthCheck) (*HealthResult, error)
Check executes an HTTP GET against the health check target and returns the result.
func (*HTTPChecker) Type ¶
func (c *HTTPChecker) Type() CheckType
Type returns the check type this checker handles.
type HealthCheck ¶
type HealthCheck struct {
ctrlplane.Entity
TenantID string `db:"tenant_id" json:"tenant_id"`
InstanceID id.ID `db:"instance_id" json:"instance_id"`
Name string `db:"name" json:"name"`
Type CheckType `db:"type" json:"type"`
Target string `db:"target" json:"target"`
Interval time.Duration `db:"interval" json:"interval"`
Timeout time.Duration `db:"timeout" json:"timeout"`
Retries int `db:"retries" json:"retries"`
Enabled bool `db:"enabled" json:"enabled"`
}
HealthCheck is a configured check for an instance.
type HealthResult ¶
type HealthResult struct {
ctrlplane.Entity
CheckID id.ID `db:"check_id" json:"check_id"`
InstanceID id.ID `db:"instance_id" json:"instance_id"`
TenantID string `db:"tenant_id" json:"tenant_id"`
Status Status `db:"status" json:"status"`
Latency time.Duration `db:"latency" json:"latency"`
Message string `db:"message" json:"message,omitempty"`
StatusCode int `db:"status_code" json:"status_code,omitempty"`
CheckedAt time.Time `db:"checked_at" json:"checked_at"`
}
HealthResult is the outcome of a single check execution.
type HistoryOptions ¶
type HistoryOptions struct {
Since time.Time `json:"since"`
Until time.Time `json:"until"`
Limit int `json:"limit"`
}
HistoryOptions configures health result history queries.
type InstanceHealth ¶
type InstanceHealth struct {
InstanceID id.ID `json:"instance_id"`
Status Status `json:"status"`
Checks []CheckSummary `json:"checks"`
LastChecked time.Time `json:"last_checked"`
Uptime float64 `json:"uptime_percent"`
ConsecFails int `json:"consecutive_failures"`
}
InstanceHealth is the aggregate health for an instance.
type Service ¶
type Service interface {
// Configure adds or updates a health check for an instance.
Configure(ctx context.Context, req ConfigureRequest) (*HealthCheck, error)
// Remove deletes a health check.
Remove(ctx context.Context, checkID id.ID) error
// GetHealth returns aggregate health for an instance.
GetHealth(ctx context.Context, instanceID id.ID) (*InstanceHealth, error)
// GetHistory returns check results over time.
GetHistory(ctx context.Context, checkID id.ID, opts HistoryOptions) ([]HealthResult, error)
// ListChecks returns all checks for an instance.
ListChecks(ctx context.Context, instanceID id.ID) ([]HealthCheck, error)
// RunCheck executes a one-off health check.
RunCheck(ctx context.Context, checkID id.ID) (*HealthResult, error)
// RegisterChecker adds a custom checker type.
RegisterChecker(checker Checker)
}
Service manages health checks and their results.
type Status ¶
type Status string
Status represents the health status of a check or instance.
const ( // StatusHealthy indicates all checks pass. StatusHealthy Status = "healthy" // StatusDegraded indicates some checks are failing. StatusDegraded Status = "degraded" // StatusUnhealthy indicates the instance is unhealthy. StatusUnhealthy Status = "unhealthy" // StatusUnknown indicates health status cannot be determined. StatusUnknown Status = "unknown" )
type Store ¶
type Store interface {
// InsertCheck persists a new health check configuration.
InsertCheck(ctx context.Context, check *HealthCheck) error
// GetCheck retrieves a health check by ID.
GetCheck(ctx context.Context, tenantID string, checkID id.ID) (*HealthCheck, error)
// ListChecks returns all health checks for an instance.
ListChecks(ctx context.Context, tenantID string, instanceID id.ID) ([]HealthCheck, error)
// UpdateCheck persists changes to a health check.
UpdateCheck(ctx context.Context, check *HealthCheck) error
// DeleteCheck removes a health check.
DeleteCheck(ctx context.Context, tenantID string, checkID id.ID) error
// InsertResult persists a health check result.
InsertResult(ctx context.Context, result *HealthResult) error
// ListResults returns health results for a check within a time range.
ListResults(ctx context.Context, tenantID string, checkID id.ID, opts HistoryOptions) ([]HealthResult, error)
// GetLatestResult returns the most recent result for a check.
GetLatestResult(ctx context.Context, tenantID string, checkID id.ID) (*HealthResult, error)
}
Store is the persistence interface for health checks and results.
type TCPChecker ¶
type TCPChecker struct {
// contains filtered or unexported fields
}
TCPChecker performs TCP dial health checks against a target address.
func NewTCPChecker ¶
func NewTCPChecker(timeout time.Duration) *TCPChecker
NewTCPChecker creates a new TCP health checker with the given timeout.
func (*TCPChecker) Check ¶
func (c *TCPChecker) Check(ctx context.Context, check *HealthCheck) (*HealthResult, error)
Check dials the target address and returns the result.
func (*TCPChecker) Type ¶
func (c *TCPChecker) Type() CheckType
Type returns the check type this checker handles.