health

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package health provides health check API handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentDetail

type AgentDetail struct {
	Hostname   string
	Labels     string
	Registered string
}

AgentDetail holds per-agent registration info.

type AgentMetrics

type AgentMetrics struct {
	Total  int
	Ready  int
	Agents []AgentDetail
}

AgentMetrics holds agent fleet statistics.

type Checker

type Checker interface {
	CheckHealth(ctx context.Context) error
}

Checker checks the health of a dependency.

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 []types.ConditionType
	Age        string
	CPUPercent float64
	MemBytes   int64
	// Version is the build version of the component's binary.
	Version       string
	SubComponents map[string]SubComponentInfo
}

ComponentEntry holds unified component registration details for the registry.

type ConsumerDetail

type ConsumerDetail struct {
	Name        string
	Pending     uint64
	AckPending  int
	Redelivered int
}

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

	// 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,
) *Health

New factory to create a new instance.

func (*Health) Ready

func (h *Health) Ready(
	ctx context.Context,
) error

Ready checks the controller's dependencies: nil when it can take traffic.

func (*Health) StartMetricsRefresh

func (h *Health) StartMetricsRefresh(
	ctx context.Context,
) (stop func())

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. It returns stop, which ends the refresh and waits until the goroutine returned: call it before the NATS connection that the metrics read closes.

func (*Health) Status

func (h *Health) Status(
	ctx context.Context,
) api.StatusResponse

Status is the health of each component, with the metrics of the system. Its status is degraded when a component is not healthy.

type JobMetrics

type JobMetrics struct {
	Total      int
	Submitted  int
	Processing int
	Completed  int
	Failed     int
	DLQ        int
}

JobMetrics holds job queue statistics.

type KVMetrics

type KVMetrics struct {
	Name  string
	Keys  int
	Bytes uint64
}

KVMetrics holds KV bucket 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

type NATSMetrics struct {
	URL     string
	Version string
}

NATSMetrics holds NATS connection information.

type ObjectStoreMetrics

type ObjectStoreMetrics struct {
	Name string
	Size uint64
}

ObjectStoreMetrics holds Object Store bucket statistics.

type StreamMetrics

type StreamMetrics struct {
	Name      string
	Messages  uint64
	Bytes     uint64
	Consumers int
}

StreamMetrics holds JetStream stream statistics.

type SubComponentInfo

type SubComponentInfo struct {
	Status  string
	Address string // Empty means no network endpoint.
	URL     string // Where a person opens it; empty when not configured.
}

SubComponentInfo holds the status, optional address and optional URL of a sub-component.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL