Documentation
¶
Overview ¶
Package health provides health check API handlers.
Index ¶
- func Handler(logger *slog.Logger, checker Checker, startTime time.Time, version string, ...) []func(e *echo.Echo)
- type AgentDetail
- type AgentMetrics
- type Checker
- type ClosureMetricsProvider
- func (p *ClosureMetricsProvider) GetAgentStats(ctx context.Context) (*AgentMetrics, error)
- func (p *ClosureMetricsProvider) GetComponentRegistry(ctx context.Context) ([]ComponentEntry, error)
- func (p *ClosureMetricsProvider) GetJobStats(ctx context.Context) (*JobMetrics, error)
- func (p *ClosureMetricsProvider) GetKVInfo(ctx context.Context) ([]KVMetrics, error)
- func (p *ClosureMetricsProvider) GetNATSInfo(ctx context.Context) (*NATSMetrics, error)
- func (p *ClosureMetricsProvider) GetObjectStoreInfo(ctx context.Context) ([]ObjectStoreMetrics, error)
- func (p *ClosureMetricsProvider) GetStreamInfo(ctx context.Context) ([]StreamMetrics, error)
- type ComponentEntry
- type ConsumerDetail
- type ConsumerMetrics
- type Health
- func (h *Health) GetHealth(_ context.Context, _ gen.GetHealthRequestObject) (gen.GetHealthResponseObject, error)
- func (h *Health) GetHealthReady(ctx context.Context, _ gen.GetHealthReadyRequestObject) (gen.GetHealthReadyResponseObject, error)
- func (h *Health) GetHealthStatus(ctx context.Context, _ gen.GetHealthStatusRequestObject) (gen.GetHealthStatusResponseObject, error)
- func (h *Health) StartMetricsRefresh(ctx context.Context)
- type JobMetrics
- type KVMetrics
- type MetricsProvider
- type NATSChecker
- type NATSMetrics
- type ObjectStoreMetrics
- type StreamMetrics
- type SubComponentInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AgentDetail ¶
AgentDetail holds per-agent registration info.
type AgentMetrics ¶
type AgentMetrics struct {
Total int
Ready int
Agents []AgentDetail
}
AgentMetrics holds agent fleet statistics.
type ClosureMetricsProvider ¶
type ClosureMetricsProvider struct {
NATSInfoFn func(ctx context.Context) (*NATSMetrics, error)
StreamInfoFn func(ctx context.Context) ([]StreamMetrics, error)
KVInfoFn func(ctx context.Context) ([]KVMetrics, error)
ObjectStoreInfoFn func(ctx context.Context) ([]ObjectStoreMetrics, error)
JobStatsFn func(ctx context.Context) (*JobMetrics, error)
AgentStatsFn func(ctx context.Context) (*AgentMetrics, error)
ComponentRegistryFn func(ctx context.Context) ([]ComponentEntry, error)
}
ClosureMetricsProvider implements MetricsProvider using function closures.
func (*ClosureMetricsProvider) GetAgentStats ¶
func (p *ClosureMetricsProvider) GetAgentStats( ctx context.Context, ) (*AgentMetrics, error)
GetAgentStats delegates to the AgentStatsFn closure.
func (*ClosureMetricsProvider) GetComponentRegistry ¶
func (p *ClosureMetricsProvider) GetComponentRegistry( ctx context.Context, ) ([]ComponentEntry, error)
GetComponentRegistry delegates to the ComponentRegistryFn closure. Returns nil, nil when the closure is not configured.
func (*ClosureMetricsProvider) GetJobStats ¶
func (p *ClosureMetricsProvider) GetJobStats( ctx context.Context, ) (*JobMetrics, error)
GetJobStats delegates to the JobStatsFn closure.
func (*ClosureMetricsProvider) GetKVInfo ¶
func (p *ClosureMetricsProvider) GetKVInfo( ctx context.Context, ) ([]KVMetrics, error)
GetKVInfo delegates to the KVInfoFn closure.
func (*ClosureMetricsProvider) GetNATSInfo ¶
func (p *ClosureMetricsProvider) GetNATSInfo( ctx context.Context, ) (*NATSMetrics, error)
GetNATSInfo delegates to the NATSInfoFn closure.
func (*ClosureMetricsProvider) GetObjectStoreInfo ¶
func (p *ClosureMetricsProvider) GetObjectStoreInfo( ctx context.Context, ) ([]ObjectStoreMetrics, error)
GetObjectStoreInfo delegates to the ObjectStoreInfoFn closure.
func (*ClosureMetricsProvider) GetStreamInfo ¶
func (p *ClosureMetricsProvider) GetStreamInfo( ctx context.Context, ) ([]StreamMetrics, error)
GetStreamInfo delegates to the StreamInfoFn closure.
type ComponentEntry ¶
type ComponentEntry struct {
Type string
Hostname string
Status string
Conditions []string
Age string
CPUPercent float64
MemBytes int64
SubComponents map[string]SubComponentInfo
}
ComponentEntry holds unified component registration details for the registry.
type ConsumerDetail ¶
ConsumerDetail holds per-consumer information.
type ConsumerMetrics ¶
type ConsumerMetrics struct {
Total int
Consumers []ConsumerDetail
}
ConsumerMetrics holds JetStream consumer statistics.
type Health ¶
type Health struct {
// Checker performs dependency health checks.
Checker Checker
// StartTime records when the server started.
StartTime time.Time
// Version is the application version string.
Version string
// Metrics provides system metrics (optional, can be nil).
Metrics MetricsProvider
// SubComponents reports the status of internal services.
SubComponents map[string]SubComponentInfo
// MetricsRefreshInterval overrides the default metrics cache TTL
// for the background refresh goroutine. Zero uses metricsCacheTTL.
MetricsRefreshInterval time.Duration
// contains filtered or unexported fields
}
Health implementation of the Health APIs operations.
func New ¶
func New( logger *slog.Logger, checker Checker, startTime time.Time, version string, metrics MetricsProvider, subComponents map[string]SubComponentInfo, ) *Health
New factory to create a new instance.
func (*Health) GetHealth ¶
func (h *Health) GetHealth( _ context.Context, _ gen.GetHealthRequestObject, ) (gen.GetHealthResponseObject, error)
GetHealth liveness probe — always returns 200 if the process is running.
func (*Health) GetHealthReady ¶
func (h *Health) GetHealthReady( ctx context.Context, _ gen.GetHealthReadyRequestObject, ) (gen.GetHealthReadyResponseObject, error)
GetHealthReady readiness probe — returns 200 when dependencies are reachable.
func (*Health) GetHealthStatus ¶
func (h *Health) GetHealthStatus( ctx context.Context, _ gen.GetHealthStatusRequestObject, ) (gen.GetHealthStatusResponseObject, error)
GetHealthStatus returns per-component health status with system metrics (authenticated).
func (*Health) StartMetricsRefresh ¶
StartMetricsRefresh starts a background goroutine that refreshes the metrics cache on a fixed interval. This ensures the health endpoint always serves from cache and never blocks on NATS queries.
type JobMetrics ¶
type JobMetrics struct {
Total int
Unprocessed int
Processing int
Completed int
Failed int
DLQ int
}
JobMetrics holds job queue statistics.
type MetricsProvider ¶
type MetricsProvider interface {
GetNATSInfo(ctx context.Context) (*NATSMetrics, error)
GetStreamInfo(ctx context.Context) ([]StreamMetrics, error)
GetKVInfo(ctx context.Context) ([]KVMetrics, error)
GetObjectStoreInfo(ctx context.Context) ([]ObjectStoreMetrics, error)
GetJobStats(ctx context.Context) (*JobMetrics, error)
GetAgentStats(ctx context.Context) (*AgentMetrics, error)
GetComponentRegistry(ctx context.Context) ([]ComponentEntry, error)
}
MetricsProvider retrieves system metrics for the status endpoint.
type NATSChecker ¶
type NATSChecker struct {
// NATSCheck verifies NATS connectivity.
NATSCheck func() error
// KVCheck verifies KV bucket accessibility.
KVCheck func() error
}
NATSChecker checks NATS and KV bucket connectivity.
func (*NATSChecker) CheckHealth ¶
func (c *NATSChecker) CheckHealth( _ context.Context, ) error
CheckHealth runs all dependency checks and returns the first error.
func (*NATSChecker) CheckKV ¶
func (c *NATSChecker) CheckKV() error
CheckKV runs only the KV bucket check.
func (*NATSChecker) CheckNATS ¶
func (c *NATSChecker) CheckNATS() error
CheckNATS runs only the NATS connectivity check.
type NATSMetrics ¶
NATSMetrics holds NATS connection information.
type ObjectStoreMetrics ¶
ObjectStoreMetrics holds Object Store bucket statistics.
type StreamMetrics ¶
StreamMetrics holds JetStream stream statistics.
type SubComponentInfo ¶
SubComponentInfo holds the status and optional address of a sub-component.