Documentation
¶
Overview ¶
Package health provides health monitoring for vMCP backend MCP servers.
This package implements the HealthChecker interface and provides periodic health monitoring with configurable intervals and failure thresholds.
Index ¶
- func IsHealthCheck(ctx context.Context) bool
- func NewHealthChecker(client vmcp.BackendClient, timeout time.Duration, ...) vmcp.HealthChecker
- func WithHealthCheckMarker(ctx context.Context) context.Context
- type Monitor
- func (m *Monitor) GetAllBackendStates() map[string]*State
- func (m *Monitor) GetBackendState(backendID string) (*State, error)
- func (m *Monitor) GetBackendStatus(backendID string) (vmcp.BackendHealthStatus, error)
- func (m *Monitor) GetHealthSummary() Summary
- func (m *Monitor) IsBackendHealthy(backendID string) bool
- func (m *Monitor) Start(ctx context.Context) error
- func (m *Monitor) Stop() error
- type MonitorConfig
- type State
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsHealthCheck ¶
IsHealthCheck returns true if the context is marked as a health check. Authentication strategies use this to bypass authentication for health checks, since health checks verify backend availability and should not require user credentials. Returns false for nil contexts.
func NewHealthChecker ¶
func NewHealthChecker(client vmcp.BackendClient, timeout time.Duration, degradedThreshold time.Duration) vmcp.HealthChecker
NewHealthChecker creates a new health checker that uses BackendClient.ListCapabilities as the health check mechanism. This validates the full MCP communication stack: network connectivity, MCP protocol compliance, authentication, and responsiveness.
Parameters:
- client: BackendClient for communicating with backend MCP servers
- timeout: Maximum duration for health check operations (0 = no timeout)
- degradedThreshold: Response time threshold for marking backend as degraded (0 = disabled)
Returns a new HealthChecker implementation.
Types ¶
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor performs periodic health checks on backend MCP servers. It runs background goroutines for each backend, tracking their health status and consecutive failure counts. The monitor supports graceful shutdown and provides thread-safe access to backend health information.
func NewMonitor ¶
func NewMonitor( client vmcp.BackendClient, backends []vmcp.Backend, config MonitorConfig, ) (*Monitor, error)
NewMonitor creates a new health monitor for the given backends.
Parameters:
- client: BackendClient for communicating with backend MCP servers
- backends: List of backends to monitor
- config: Configuration for health monitoring
Returns (monitor, error). Error is returned if configuration is invalid.
func (*Monitor) GetAllBackendStates ¶
GetAllBackendStates returns health states for all monitored backends. Returns a map of backend ID to State.
func (*Monitor) GetBackendState ¶
GetBackendState returns the full health state for a backend. Returns (state, error). Error is returned if the backend is not being monitored.
func (*Monitor) GetBackendStatus ¶
func (m *Monitor) GetBackendStatus(backendID string) (vmcp.BackendHealthStatus, error)
GetBackendStatus returns the current health status for a backend. Returns (status, error). Error is returned if the backend is not being monitored.
func (*Monitor) GetHealthSummary ¶
GetHealthSummary returns a summary of backend health for logging/monitoring. Returns counts of healthy, degraded, unhealthy, and total backends.
func (*Monitor) IsBackendHealthy ¶
IsBackendHealthy returns true if the backend is currently healthy. Returns false if the backend is not being monitored or is unhealthy.
func (*Monitor) Start ¶
Start begins health monitoring for all backends. This spawns a background goroutine for each backend that performs periodic health checks. Returns an error if the monitor is already started, has been stopped, or if the parent context is invalid.
The monitor respects the parent context for cancellation. When the parent context is cancelled, all health check goroutines will stop gracefully.
Note: A monitor cannot be restarted after it has been stopped. Create a new monitor instead.
type MonitorConfig ¶
type MonitorConfig struct {
// CheckInterval is how often to perform health checks.
// Must be > 0. Recommended: 30s.
CheckInterval time.Duration
// UnhealthyThreshold is the number of consecutive failures before marking unhealthy.
// Must be >= 1. Recommended: 3 failures.
UnhealthyThreshold int
// Timeout is the maximum duration for a single health check operation.
// Zero means no timeout (not recommended).
Timeout time.Duration
// DegradedThreshold is the response time threshold for marking a backend as degraded.
// If a health check succeeds but takes longer than this duration, the backend is marked degraded.
// Zero means disabled (backends will never be marked degraded based on response time alone).
// Recommended: 5s.
DegradedThreshold time.Duration
}
MonitorConfig contains configuration for the health monitor.
func DefaultConfig ¶
func DefaultConfig() MonitorConfig
DefaultConfig returns sensible default configuration values.
type State ¶
type State struct {
// Status is the current health status.
Status vmcp.BackendHealthStatus
// ConsecutiveFailures is the number of consecutive failed health checks.
ConsecutiveFailures int
// LastCheckTime is when the last health check was performed.
LastCheckTime time.Time
// LastError is the last error encountered (if any).
LastError error
// LastTransitionTime is when the status last changed.
LastTransitionTime time.Time
}
State is an immutable snapshot of a backend's health state. This is returned by GetState and GetAllStates to provide thread-safe access to health information without holding locks.