internal

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HealthStatusHealthy   = shared.HealthStatusHealthy
	HealthStatusDegraded  = shared.HealthStatusDegraded
	HealthStatusUnhealthy = shared.HealthStatusUnhealthy
	HealthStatusUnknown   = shared.HealthStatusUnknown
)

Variables

This section is empty.

Functions

func CreateHealthEndpoints

func CreateHealthEndpoints(router shared.Router, healthService shared.HealthManager, logger logger.Logger, metrics shared.Metrics) error

CreateHealthEndpoints creates health endpoints for a router

func CreateHealthEndpointsWithConfig

func CreateHealthEndpointsWithConfig(router shared.Router, healthService shared.HealthManager, logger logger.Logger, metrics shared.Metrics, config *EndpointConfig) error

CreateHealthEndpointsWithConfig creates health endpoints with custom configuration

Types

type AggregatorConfig

type AggregatorConfig struct {
	CriticalServices   []string
	DegradedThreshold  float64 // Percentage of services that can be degraded before overall is degraded
	UnhealthyThreshold float64 // Percentage of services that can be unhealthy before overall is unhealthy
	EnableDependencies bool
	Weights            map[string]float64 // Weight for each service (default 1.0)
}

AggregatorConfig contains configuration for the health aggregator

func DefaultAggregatorConfig

func DefaultAggregatorConfig() *AggregatorConfig

DefaultAggregatorConfig returns default configuration for the health aggregator

type AsyncHealthCheck

type AsyncHealthCheck struct {
	*BaseHealthCheck
	// contains filtered or unexported fields
}

AsyncHealthCheck implements an asynchronous health check

func NewAsyncHealthCheck

func NewAsyncHealthCheck(config *HealthCheckConfig, checkFunc HealthCheckFunc) *AsyncHealthCheck

NewAsyncHealthCheck creates a new asynchronous health check

func (*AsyncHealthCheck) Check

Check returns the last health check result

func (*AsyncHealthCheck) GetResultChannel

func (ahc *AsyncHealthCheck) GetResultChannel() <-chan *shared.HealthResult

GetResultChannel returns the result channel for async updates

func (*AsyncHealthCheck) IsRunning

func (ahc *AsyncHealthCheck) IsRunning() bool

IsRunning returns true if the health check is running

func (*AsyncHealthCheck) Start

func (ahc *AsyncHealthCheck) Start(ctx context.Context)

Start starts the asynchronous health check

func (*AsyncHealthCheck) Stop

func (ahc *AsyncHealthCheck) Stop()

Stop stops the asynchronous health check

type BaseHealthCheck

type BaseHealthCheck struct {
	// contains filtered or unexported fields
}

BaseHealthCheck provides base functionality for health checks

func NewBaseHealthCheck

func NewBaseHealthCheck(config *HealthCheckConfig) *BaseHealthCheck

NewBaseHealthCheck creates a new base health check

func (*BaseHealthCheck) Check

Check performs the health check (to be implemented by concrete types)

func (*BaseHealthCheck) Critical

func (bhc *BaseHealthCheck) Critical() bool

Critical returns whether the health check is critical

func (*BaseHealthCheck) Dependencies

func (bhc *BaseHealthCheck) Dependencies() []string

Dependencies returns the dependencies of the health check

func (*BaseHealthCheck) GetLastCheck

func (bhc *BaseHealthCheck) GetLastCheck() time.Time

GetLastCheck returns the time of the last health check

func (*BaseHealthCheck) GetLastResult

func (bhc *BaseHealthCheck) GetLastResult() *shared.HealthResult

GetLastResult returns the last health check result

func (*BaseHealthCheck) Interval

func (bhc *BaseHealthCheck) Interval() time.Duration

Interval returns the check interval

func (*BaseHealthCheck) Metadata

func (bhc *BaseHealthCheck) Metadata() map[string]interface{}

Metadata returns the metadata for the health check

func (*BaseHealthCheck) Name

func (bhc *BaseHealthCheck) Name() string

Name returns the name of the health check

func (*BaseHealthCheck) Retries

func (bhc *BaseHealthCheck) Retries() int

Retries returns the number of retries

func (*BaseHealthCheck) RetryDelay

func (bhc *BaseHealthCheck) RetryDelay() time.Duration

RetryDelay returns the retry delay

func (*BaseHealthCheck) SetLastResult

func (bhc *BaseHealthCheck) SetLastResult(result *shared.HealthResult)

SetLastResult sets the last health check result

func (*BaseHealthCheck) ShouldCheck

func (bhc *BaseHealthCheck) ShouldCheck() bool

ShouldCheck returns true if the health check should be performed

func (*BaseHealthCheck) Tags

func (bhc *BaseHealthCheck) Tags() map[string]string

Tags returns the tags for the health check

func (*BaseHealthCheck) Timeout

func (bhc *BaseHealthCheck) Timeout() time.Duration

Timeout returns the timeout for the health check

type CompositeHealthCheck

type CompositeHealthCheck struct {
	*BaseHealthCheck
	// contains filtered or unexported fields
}

CompositeHealthCheck implements a health check that combines multiple checks

func NewCompositeHealthCheck

func NewCompositeHealthCheck(config *HealthCheckConfig, checks ...HealthCheck) *CompositeHealthCheck

NewCompositeHealthCheck creates a new composite health check

func (*CompositeHealthCheck) AddCheck

func (chc *CompositeHealthCheck) AddCheck(check HealthCheck)

AddCheck adds a health check to the composite

func (*CompositeHealthCheck) Check

Check performs all health checks and aggregates the results

type DetailedHealthHandler

type DetailedHealthHandler = func(ctx context.Context, input DetailedHealthStatusInput) (*DetailedHealthStatusOutput, error)

type DetailedHealthStatusInput

type DetailedHealthStatusInput struct {
}

type DetailedHealthStatusOutput

type DetailedHealthStatusOutput struct {
	Body       *HealthReport `json:"overall"`
	StatusCode int           `json:"status_code"`
}

type EndpointConfig

type EndpointConfig struct {
	PathPrefix        string            `yaml:"path_prefix" json:"path_prefix"`
	EnableDetailed    bool              `yaml:"enable_detailed" json:"enable_detailed"`
	EnableMetrics     bool              `yaml:"enable_metrics" json:"enable_metrics"`
	EnableLiveness    bool              `yaml:"enable_liveness" json:"enable_liveness"`
	EnableReadiness   bool              `yaml:"enable_readiness" json:"enable_readiness"`
	EnableInfo        bool              `yaml:"enable_info" json:"enable_info"`
	CacheMaxAge       int               `yaml:"cache_max_age" json:"cache_max_age"`
	Headers           map[string]string `yaml:"headers" json:"headers"`
	EnableCORS        bool              `yaml:"enable_cors" json:"enable_cors"`
	CORSOrigins       []string          `yaml:"cors_origins" json:"cors_origins"`
	AuthEnabled       bool              `yaml:"auth_enabled" json:"auth_enabled"`
	AuthToken         string            `yaml:"auth_token" json:"auth_token"`
	EnableCompression bool              `yaml:"enable_compression" json:"enable_compression"`
	ResponseTimeout   time.Duration     `yaml:"response_timeout" json:"response_timeout"`
}

EndpointConfig contains configuration for health endpoints

func DefaultEndpointConfig

func DefaultEndpointConfig() *EndpointConfig

DefaultEndpointConfig returns default configuration for health endpoints

type HealthAggregator

type HealthAggregator struct {
	// contains filtered or unexported fields
}

HealthAggregator aggregates health check results into an overall health status

func NewHealthAggregator

func NewHealthAggregator(config *AggregatorConfig) *HealthAggregator

NewHealthAggregator creates a new health aggregator

func (*HealthAggregator) AddCriticalService

func (ha *HealthAggregator) AddCriticalService(serviceName string)

AddCriticalService adds a service to the critical services list

func (*HealthAggregator) Aggregate

func (ha *HealthAggregator) Aggregate(results map[string]*HealthResult) *HealthReport

Aggregate aggregates multiple health results into an overall health status

func (*HealthAggregator) AggregateWithContext

func (ha *HealthAggregator) AggregateWithContext(ctx context.Context, results map[string]*HealthResult) *HealthReport

AggregateWithContext aggregates health results with context information

func (*HealthAggregator) GetDependencies

func (ha *HealthAggregator) GetDependencies(service string) []string

GetDependencies returns the dependencies for a service

func (*HealthAggregator) GetWeight

func (ha *HealthAggregator) GetWeight(serviceName string) float64

GetWeight returns the weight for a service (default 1.0)

func (*HealthAggregator) IsCriticalService

func (ha *HealthAggregator) IsCriticalService(serviceName string) bool

IsCriticalService returns true if the service is marked as critical

func (*HealthAggregator) RemoveCriticalService

func (ha *HealthAggregator) RemoveCriticalService(serviceName string)

RemoveCriticalService removes a service from the critical services list

func (*HealthAggregator) SetDependency

func (ha *HealthAggregator) SetDependency(service string, dependencies []string)

SetDependency sets a dependency relationship between services

func (*HealthAggregator) SetWeight

func (ha *HealthAggregator) SetWeight(serviceName string, weight float64)

SetWeight sets the weight for a service

type HealthCallback

type HealthCallback = shared.HealthCallback

HealthCallback is a callback function for health status changes

type HealthCheck

type HealthCheck = shared.HealthCheck

HealthCheck defines the interface for health checks

type HealthCheckConfig

type HealthCheckConfig struct {
	Name         string
	Timeout      time.Duration
	Critical     bool
	Dependencies []string
	Interval     time.Duration
	Retries      int
	RetryDelay   time.Duration
	Tags         map[string]string
	Metadata     map[string]interface{}
}

HealthCheckConfig contains configuration for health checks

func DefaultHealthCheckConfig

func DefaultHealthCheckConfig() *HealthCheckConfig

DefaultHealthCheckConfig returns default configuration for health checks

type HealthCheckFactory

type HealthCheckFactory func(config *HealthCheckConfig) (HealthCheck, error)

HealthCheckFactory defines a factory function for creating health checks

type HealthCheckFunc

type HealthCheckFunc = shared.HealthCheckFn

HealthCheckFunc is a function type for simple health checks

type HealthCheckWrapper

type HealthCheckWrapper struct {
	// contains filtered or unexported fields
}

HealthCheckWrapper wraps a health check with additional functionality

func NewHealthCheckWrapper

func NewHealthCheckWrapper(check HealthCheck) *HealthCheckWrapper

NewHealthCheckWrapper creates a new health check wrapper

func (*HealthCheckWrapper) Check

Check performs the wrapped health check

func (*HealthCheckWrapper) Critical

func (hcw *HealthCheckWrapper) Critical() bool

Critical returns whether the wrapped health check is critical

func (*HealthCheckWrapper) Dependencies

func (hcw *HealthCheckWrapper) Dependencies() []string

Dependencies returns the dependencies of the wrapped health check

func (*HealthCheckWrapper) Name

func (hcw *HealthCheckWrapper) Name() string

Name returns the name of the wrapped health check

func (*HealthCheckWrapper) Timeout

func (hcw *HealthCheckWrapper) Timeout() time.Duration

Timeout returns the timeout of the wrapped health check

func (*HealthCheckWrapper) WithAfter

func (hcw *HealthCheckWrapper) WithAfter(afterFunc func(ctx context.Context, result *shared.HealthResult) error) *HealthCheckWrapper

WithAfter adds an after function to the wrapper

func (*HealthCheckWrapper) WithBefore

func (hcw *HealthCheckWrapper) WithBefore(beforeFunc func(ctx context.Context) error) *HealthCheckWrapper

WithBefore adds a before function to the wrapper

type HealthCheckerStats

type HealthCheckerStats = shared.HealthCheckerStats

HealthCheckerStats contains statistics about the health checker

type HealthConfig

type HealthConfig = shared.HealthConfig

HealthConfig contains configuration for the health checker

func DefaultHealthCheckerConfig

func DefaultHealthCheckerConfig() *HealthConfig

DefaultHealthCheckerConfig returns default configuration

type HealthEndpointHandlers

type HealthEndpointHandlers struct {
	// contains filtered or unexported fields
}

HealthEndpointHandlers provides direct handler functions for integration

func NewHealthEndpointHandlers

func NewHealthEndpointHandlers(manager *HealthEndpointManager) *HealthEndpointHandlers

NewHealthEndpointHandlers creates new health endpoint handlers

func (*HealthEndpointHandlers) DetailedHealthHandler

func (heh *HealthEndpointHandlers) DetailedHealthHandler() DetailedHealthHandler

DetailedHealthHandler returns the detailed health handler function

func (*HealthEndpointHandlers) HealthHandler

func (heh *HealthEndpointHandlers) HealthHandler() func(ctx shared.Context, input HealthStatusInput) (*HealthStatusOutput, error)

HealthHandler returns the health handler function

func (*HealthEndpointHandlers) InfoHandler

func (heh *HealthEndpointHandlers) InfoHandler() func(ctx shared.Context, input InfoInput) (*InfoOutput, error)

InfoHandler returns the info handler function

func (*HealthEndpointHandlers) LivenessHandler

func (heh *HealthEndpointHandlers) LivenessHandler() func(ctx shared.Context, input LivenessInput) (*LivenessOutput, error)

LivenessHandler returns the liveness handler function

func (*HealthEndpointHandlers) ReadinessHandler

func (heh *HealthEndpointHandlers) ReadinessHandler() func(ctx shared.Context, input ReadinessInput) (*ReadinessOutput, error)

ReadinessHandler returns the readiness handler function

func (*HealthEndpointHandlers) ServiceHealthHandler

func (heh *HealthEndpointHandlers) ServiceHealthHandler() func(ctx shared.Context, input ServiceHealthInput) (*ServiceHealthOutput, error)

ServiceHealthHandler returns the service health handler function

func (*HealthEndpointHandlers) StatsHandler

func (heh *HealthEndpointHandlers) StatsHandler() func(ctx shared.Context, input StatsInput) (*StatsOutput, error)

StatsHandler returns the stats handler function

type HealthEndpointManager

type HealthEndpointManager struct {
	// contains filtered or unexported fields
}

HealthEndpointManager manages HTTP endpoints for health checks

func NewHealthEndpointManager

func NewHealthEndpointManager(healthService HealthService, logger logger.Logger, metrics shared.Metrics, config *EndpointConfig) *HealthEndpointManager

NewHealthEndpointManager creates a new health endpoint manager

func (*HealthEndpointManager) RegisterEndpoints

func (hem *HealthEndpointManager) RegisterEndpoints(r shared.Router) error

RegisterEndpoints registers health endpoints with the router

type HealthMonitor

type HealthMonitor interface {
	// Subscribe adds a callback for health status changes
	Subscribe(callback HealthCallback) error

	// GetLastReport returns the last health report
	GetLastReport() *HealthReport

	// GetStats returns health service statistics
	GetStats() *HealthCheckerStats
}

HealthMonitor defines methods for monitoring and reporting health status

type HealthPrediction

type HealthPrediction struct {
	PredictedStatus HealthStatus  `json:"predicted_status"`
	Confidence      float64       `json:"confidence"`
	TimeWindow      time.Duration `json:"time_window"`
	Recommendations []string      `json:"recommendations"`
}

HealthPrediction represents a health prediction

type HealthReport

type HealthReport = shared.HealthReport

HealthReport represents a comprehensive health report

func NewHealthReport

func NewHealthReport() *HealthReport

NewHealthReport creates a new health report

type HealthReportCallback

type HealthReportCallback = shared.HealthReportCallback

HealthReportCallback is a callback function for health report changes

type HealthResult

type HealthResult = shared.HealthResult

HealthResult represents the result of a health check

func NewHealthResult

func NewHealthResult(name string, status HealthStatus, message string) *HealthResult

NewHealthResult creates a new health result

type HealthService

type HealthService = shared.HealthManager

HealthService defines the contract for health monitoring services

type HealthServiceRegistry

type HealthServiceRegistry interface {
	// RegisterService registers a health service
	RegisterService(name string, service HealthService) error

	// UnregisterService unregisters a health service
	UnregisterService(name string) error

	// GetService retrieves a registered health service
	GetService(name string) (HealthService, error)

	// ListServices returns all registered service names
	ListServices() []string

	// GetServiceStatus returns the status of a specific service
	GetServiceStatus(name string) (HealthStatus, error)

	// GetAllStatuses returns the status of all registered services
	GetAllStatuses() map[string]HealthStatus
}

HealthServiceRegistry defines an interface for registering and discovering health services

type HealthStatus

type HealthStatus = shared.HealthStatus

HealthStatus represents the health status of a service or component

type HealthStatusInput

type HealthStatusInput struct {
	Status    HealthStatus `json:"status"`
	Timestamp string       `json:"timestamp"`
}

type HealthStatusOutput

type HealthStatusOutput struct {
	Status    HealthStatus `json:"status"`
	Timestamp string       `json:"timestamp"`
}

type HealthStatusSnapshot

type HealthStatusSnapshot struct {
	Timestamp time.Time
	Overall   HealthStatus
	Services  map[string]HealthStatus
}

HealthStatusSnapshot represents a point-in-time health status

type HealthStatusSummary

type HealthStatusSummary struct {
	TotalChecks    int          `json:"total_checks"`
	OverallStatus  HealthStatus `json:"overall_status"`
	LastReportTime string       `json:"last_report_time"`
	HealthyCount   int          `json:"healthy_count,omitempty"`
	DegradedCount  int          `json:"degraded_count,omitempty"`
	UnhealthyCount int          `json:"unhealthy_count,omitempty"`
	CriticalCount  int          `json:"critical_count,omitempty"`
}

type HealthSummary

type HealthSummary struct {
	Total       int `json:"total"`
	Healthy     int `json:"healthy"`
	Degraded    int `json:"degraded"`
	Unhealthy   int `json:"unhealthy"`
	Critical    int `json:"critical"`
	NonCritical int `json:"non_critical"`
}

HealthSummary provides a summary of health check results

type InfoInput

type InfoInput struct{}

type InfoOutput

type InfoOutput struct {
	Service          string       `json:"service"`
	Version          string       `json:"version"`
	Environment      string       `json:"environment"`
	Hostname         string       `json:"hostname"`
	Uptime           string       `json:"uptime"`
	RegisteredChecks int          `json:"registered_checks"`
	Subscribers      int          `json:"subscribers"`
	LastReportTime   string       `json:"last_report_time"`
	OverallStatus    HealthStatus `json:"overall_status"`
	Timestamp        string       `json:"timestamp"`
}

type LivenessInput

type LivenessInput struct{}

type LivenessOutput

type LivenessOutput struct {
	Status    string `json:"status"`
	Timestamp string `json:"timestamp"`
	Uptime    string `json:"uptime"`
}

type PredictiveAggregator

type PredictiveAggregator struct {
	*SmartAggregator
	// contains filtered or unexported fields
}

PredictiveAggregator implements predictive health aggregation

func NewPredictiveAggregator

func NewPredictiveAggregator(config *AggregatorConfig) *PredictiveAggregator

NewPredictiveAggregator creates a new predictive health aggregator

func (*PredictiveAggregator) PredictHealth

func (pa *PredictiveAggregator) PredictHealth() *HealthPrediction

PredictHealth predicts the health status for the next prediction window

type ReadinessInput

type ReadinessInput struct{}

type ReadinessOutput

type ReadinessOutput struct {
	Status    HealthStatus `json:"status"`
	Ready     bool         `json:"ready"`
	Timestamp string       `json:"timestamp"`
}

type ServiceHealthInput

type ServiceHealthInput struct {
	Name string `json:"-" path:"name"`
}

type ServiceHealthOutput

type ServiceHealthOutput struct {
	Body *HealthResult
}

type SimpleHealthCheck

type SimpleHealthCheck struct {
	*BaseHealthCheck
	// contains filtered or unexported fields
}

SimpleHealthCheck implements a simple function-based health check

func NewSimpleHealthCheck

func NewSimpleHealthCheck(config *HealthCheckConfig, checkFunc HealthCheckFunc) *SimpleHealthCheck

NewSimpleHealthCheck creates a new simple health check

func (*SimpleHealthCheck) Check

Check performs the health check

type SmartAggregator

type SmartAggregator struct {
	*HealthAggregator
	// contains filtered or unexported fields
}

SmartAggregator implements advanced aggregation logic with machine learning-like features

func NewSmartAggregator

func NewSmartAggregator(config *AggregatorConfig) *SmartAggregator

NewSmartAggregator creates a new smart health aggregator

func (*SmartAggregator) Aggregate

func (sa *SmartAggregator) Aggregate(results map[string]*HealthResult) *HealthReport

Aggregate aggregates health results with smart analysis

func (*SmartAggregator) EnableAdaptiveThresholds

func (sa *SmartAggregator) EnableAdaptiveThresholds(enabled bool)

EnableAdaptiveThresholds enables/disables adaptive thresholds

func (*SmartAggregator) EnableTrends

func (sa *SmartAggregator) EnableTrends(enabled bool)

EnableTrends enables/disables trend analysis

func (*SmartAggregator) GetServiceTrends

func (sa *SmartAggregator) GetServiceTrends(serviceName string) []HealthStatusSnapshot

GetServiceTrends returns trends for a specific service

func (*SmartAggregator) GetStabilityScore

func (sa *SmartAggregator) GetStabilityScore() float64

GetStabilityScore returns a stability score (0-1) based on recent health history

func (*SmartAggregator) GetTrends

func (sa *SmartAggregator) GetTrends() []HealthStatusSnapshot

GetTrends returns health trends over time

func (*SmartAggregator) SetMaxHistorySize

func (sa *SmartAggregator) SetMaxHistorySize(size int)

SetMaxHistorySize sets the maximum number of snapshots to keep in history

type StatsInput

type StatsInput struct{}

type StatsOutput

type StatsOutput struct {
	Stats   *HealthCheckerStats  `json:"stats"`
	Summary *HealthStatusSummary `json:"summary"`
}

Jump to

Keyboard shortcuts

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