health

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HealthStatusHealthy   = shared.HealthStatusHealthy
	HealthStatusDegraded  = shared.HealthStatusDegraded
	HealthStatusUnhealthy = shared.HealthStatusUnhealthy
	HealthStatusUnknown   = shared.HealthStatusUnknown
)
View Source
const CheckerKey = shared.HealthCheckerKey
View Source
const ServiceKey = shared.HealthServiceKey

Variables

This section is empty.

Functions

func AssertHealthReportEqual

func AssertHealthReportEqual(t *testing.T, expected, actual *health.HealthReport)

AssertHealthReportEqual asserts that two health reports are equal

func AssertHealthResultEqual

func AssertHealthResultEqual(t *testing.T, expected, actual *health.HealthResult)

AssertHealthResultEqual asserts that two health results are equal

func BenchmarkHealthCheck

func BenchmarkHealthCheck(b *testing.B, check health.HealthCheck)

BenchmarkHealthCheck benchmarks a health check

func BenchmarkHealthService

func BenchmarkHealthService(b *testing.B, service health.HealthService)

BenchmarkHealthService benchmarks a health service

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

func CreateTestHealthReport

func CreateTestHealthReport(overall health.HealthStatus, services map[string]*health.HealthResult) *health.HealthReport

CreateTestHealthReport creates a test health report

func CreateTestHealthResult

func CreateTestHealthResult(name string, status health.HealthStatus, message string) *health.HealthResult

CreateTestHealthResult creates a test health result

func ExampleHealthTest

func ExampleHealthTest(t *testing.T)

ExampleHealthTest demonstrates how to use the health testing utilities

func GetHealthServiceFromContainer

func GetHealthServiceFromContainer(container shared.Container) (healthcore.HealthService, error)

GetHealthServiceFromContainer retrieves the health service from the container

func New

func New(config *HealthConfig, logger logger.Logger, metrics shared.Metrics, container shared.Container) shared.HealthManager

New creates a new health checker

func NewHealthChecker

func NewHealthChecker(config *HealthConfig, logger logger.Logger, metrics shared.Metrics, container shared.Container) shared.HealthManager

NewHealthChecker creates a new health checker

func NewNoOpHealthManager

func NewNoOpHealthManager() shared.HealthManager

NewNoOpHealthManager creates a no-op health manager that implements the full HealthManager interface but performs no actual health checking or monitoring. Useful for testing, benchmarking, or when health checks are disabled.

func RegisterHealthEndpointsWithContainer

func RegisterHealthEndpointsWithContainer(container shared.Container, router shared.Router) error

RegisterHealthEndpointsWithContainer registers health endpoints using the DI container

func RegisterHealthService

func RegisterHealthService(container shared.Container, conf *HealthConfig) error

RegisterHealthService registers the health service with the DI container

func WaitForHealthStatus

func WaitForHealthStatus(t *testing.T, service health.HealthService, expected health.HealthStatus, timeout time.Duration)

WaitForHealthStatus waits for a specific health status with timeout

Types

type AggregatorConfig

type AggregatorConfig = healthcore.AggregatorConfig

AggregatorConfig contains configuration for the health aggregator

func DefaultAggregatorConfig

func DefaultAggregatorConfig() *AggregatorConfig

DefaultAggregatorConfig returns default configuration for the health aggregator

type AsyncHealthCheck

type AsyncHealthCheck = healthcore.AsyncHealthCheck

AsyncHealthCheck implements an asynchronous health check

func NewAsyncHealthCheck

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

NewAsyncHealthCheck creates a new asynchronous health check

type BaseHealthCheck

type BaseHealthCheck = healthcore.BaseHealthCheck

BaseHealthCheck provides base functionality for health checks

func NewBaseHealthCheck

func NewBaseHealthCheck(config *HealthCheckConfig) *BaseHealthCheck

NewBaseHealthCheck creates a new base health check

type CompositeHealthCheck

type CompositeHealthCheck = healthcore.CompositeHealthCheck

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

type EndpointConfig

type EndpointConfig = healthcore.EndpointConfig

EndpointConfig contains configuration for health endpoints

func DefaultEndpointConfig

func DefaultEndpointConfig() *EndpointConfig

DefaultEndpointConfig returns default configuration for health endpoints

type HealthAggregator

type HealthAggregator = healthcore.HealthAggregator

HealthAggregator aggregates health check results into an overall health status

func NewHealthAggregator

func NewHealthAggregator(config *AggregatorConfig) *HealthAggregator

NewHealthAggregator creates a new health aggregator

type HealthCallback

type HealthCallback = healthcore.HealthCallback

HealthCallback is a callback function for health status changes

type HealthCheck

type HealthCheck = healthcore.HealthCheck

HealthCheck defines the interface for health checks

type HealthCheckConfig

type HealthCheckConfig = healthcore.HealthCheckConfig

HealthCheckConfig contains configuration for health checks

func DefaultHealthCheckConfig

func DefaultHealthCheckConfig() *HealthCheckConfig

DefaultHealthCheckConfig returns default configuration for health checks

type HealthCheckFunc

type HealthCheckFunc = healthcore.HealthCheckFunc

HealthCheckFunc is a function type for simple health checks

type HealthCheckWrapper

type HealthCheckWrapper = healthcore.HealthCheckWrapper

HealthCheckWrapper wraps a health check with additional functionality

func NewHealthCheckWrapper

func NewHealthCheckWrapper(check HealthCheck) *HealthCheckWrapper

NewHealthCheckWrapper creates a new health check wrapper

type HealthChecker

type HealthChecker = healthcore.HealthService

HealthChecker implements comprehensive health monitoring for all services

type HealthCheckerStats

type HealthCheckerStats = healthcore.HealthCheckerStats

HealthCheckerStats contains statistics about the health checker

type HealthConfig

type HealthConfig = healthinternal.HealthConfig

HealthConfig contains configuration for the health checker

func DefaultHealthConfig

func DefaultHealthConfig() *HealthConfig

DefaultHealthConfig returns default configuration

type HealthEndpointHandlers

type HealthEndpointHandlers = healthcore.HealthEndpointHandlers

HealthEndpointHandlers provides direct handler functions for integration

func NewHealthEndpointHandlers

func NewHealthEndpointHandlers(manager *HealthEndpointManager) *HealthEndpointHandlers

NewHealthEndpointHandlers creates new health endpoint handlers

type HealthEndpointManager

type HealthEndpointManager = healthcore.HealthEndpointManager

HealthEndpointManager manages HTTP endpoints for health checks

func NewHealthEndpointManager

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

NewHealthEndpointManager creates a new health endpoint manager

type HealthPrediction

type HealthPrediction = healthcore.HealthPrediction

HealthPrediction represents a health prediction

type HealthReport

type HealthReport = healthcore.HealthReport

HealthReport represents a comprehensive health report

func NewHealthReport

func NewHealthReport() *HealthReport

NewHealthReport creates a new health report

type HealthReportCallback

type HealthReportCallback = healthcore.HealthReportCallback

HealthReportCallback is a callback function for health report changes

type HealthResult

type HealthResult = healthcore.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 HealthStatus

type HealthStatus = shared.HealthStatus

HealthStatus represents the health status of a service or component

type HealthStatusSnapshot

type HealthStatusSnapshot = healthcore.HealthStatusSnapshot

HealthStatusSnapshot represents a point-in-time health status

type HealthTestBuilder

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

HealthTestBuilder helps build health test scenarios

func NewHealthTestBuilder

func NewHealthTestBuilder(t *testing.T) *HealthTestBuilder

NewHealthTestBuilder creates a new health test builder

func (*HealthTestBuilder) Build

func (htb *HealthTestBuilder) Build() *HealthTestSuite

Build builds the test suite

func (*HealthTestBuilder) WithCriticalCheck

func (htb *HealthTestBuilder) WithCriticalCheck(name string, status health.HealthStatus) *HealthTestBuilder

WithCriticalCheck adds a critical check

func (*HealthTestBuilder) WithCustomCheck

func (htb *HealthTestBuilder) WithCustomCheck(name string, checkFunc func(ctx context.Context) *health.HealthResult) *HealthTestBuilder

WithCustomCheck adds a custom check

func (*HealthTestBuilder) WithDegradedCheck

func (htb *HealthTestBuilder) WithDegradedCheck(name string) *HealthTestBuilder

WithDegradedCheck adds a degraded check

func (*HealthTestBuilder) WithHealthyCheck

func (htb *HealthTestBuilder) WithHealthyCheck(name string) *HealthTestBuilder

WithHealthyCheck adds a healthy check

func (*HealthTestBuilder) WithSlowCheck

func (htb *HealthTestBuilder) WithSlowCheck(name string, delay time.Duration) *HealthTestBuilder

WithSlowCheck adds a slow check for timeout testing

func (*HealthTestBuilder) WithUnhealthyCheck

func (htb *HealthTestBuilder) WithUnhealthyCheck(name string) *HealthTestBuilder

WithUnhealthyCheck adds an unhealthy check

type HealthTestSuite

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

HealthTestSuite provides a test suite for health checks

func NewHealthTestSuite

func NewHealthTestSuite(t *testing.T) *HealthTestSuite

NewHealthTestSuite creates a new health test suite

func (*HealthTestSuite) AddHealthCheck

func (hts *HealthTestSuite) AddHealthCheck(name string, status health.HealthStatus, message string) *MockHealthCheck

AddHealthCheck adds a health check to the test suite

func (*HealthTestSuite) AssertCheckCalled

func (hts *HealthTestSuite) AssertCheckCalled(name string, expectedCalls int)

AssertCheckCalled asserts that a specific check was called

func (*HealthTestSuite) AssertDegraded

func (hts *HealthTestSuite) AssertDegraded()

AssertDegraded asserts that the service is degraded

func (*HealthTestSuite) AssertHealthy

func (hts *HealthTestSuite) AssertHealthy()

AssertHealthy asserts that the service is healthy

func (*HealthTestSuite) AssertMethodCalled

func (hts *HealthTestSuite) AssertMethodCalled(method string, expectedCalls int)

AssertMethodCalled asserts that a service method was called

func (*HealthTestSuite) AssertUnhealthy

func (hts *HealthTestSuite) AssertUnhealthy()

AssertUnhealthy asserts that the service is unhealthy

func (*HealthTestSuite) Cleanup

func (hts *HealthTestSuite) Cleanup()

Cleanup cleans up the test suite

func (*HealthTestSuite) GetHealthCheck

func (hts *HealthTestSuite) GetHealthCheck(name string) *MockHealthCheck

GetHealthCheck returns a specific health check

func (*HealthTestSuite) GetHealthService

func (hts *HealthTestSuite) GetHealthService() *TestHealthService

GetHealthService returns the test health service

func (*HealthTestSuite) Start

func (hts *HealthTestSuite) Start()

Start starts the health service

func (*HealthTestSuite) Stop

func (hts *HealthTestSuite) Stop()

Stop stops the health service

type ManagerImpl

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

ManagerImpl implements comprehensive health monitoring for all services

func (*ManagerImpl) Check

CheckAll performs all health checks and returns a comprehensive report

func (*ManagerImpl) CheckOne

func (hc *ManagerImpl) CheckOne(ctx context.Context, name string) *healthinternal.HealthResult

CheckOne performs a single health check

func (*ManagerImpl) Environment

func (hc *ManagerImpl) Environment() string

func (*ManagerImpl) GetChecks

func (hc *ManagerImpl) GetChecks() map[string]healthinternal.HealthCheck

GetChecks returns all registered health checks

func (*ManagerImpl) GetLastReport

func (hc *ManagerImpl) GetLastReport() *healthinternal.HealthReport

GetLastReport returns the last health report

func (*ManagerImpl) GetStats

GetStats returns health checker statistics

func (*ManagerImpl) GetStatus

func (hc *ManagerImpl) GetStatus() healthinternal.HealthStatus

GetStatus returns the current overall health status

func (*ManagerImpl) Hostname

func (hc *ManagerImpl) Hostname() string

func (*ManagerImpl) Name

func (hc *ManagerImpl) Name() string

Name returns the service name

func (*ManagerImpl) OnHealthCheck

func (hc *ManagerImpl) OnHealthCheck(ctx context.Context) error

OnHealthCheck performs a health check on the health checker itself

func (*ManagerImpl) Register

func (hc *ManagerImpl) Register(check healthinternal.HealthCheck) error

Register registers a health check

func (*ManagerImpl) RegisterFn

func (hc *ManagerImpl) RegisterFn(name string, checkFn healthinternal.HealthCheckFunc) error

RegisterFn registers a function-based health check

func (*ManagerImpl) Reload

func (hc *ManagerImpl) Reload(config *HealthConfig) error

Reload reloads the health configuration at runtime

func (*ManagerImpl) SetContainer

func (hc *ManagerImpl) SetContainer(container shared.Container)

SetContainer sets the container reference for health checks

func (*ManagerImpl) SetEnvironment

func (hc *ManagerImpl) SetEnvironment(name string)

SetEnvironment sets the environment name for the HealthManagerImpl instance.

func (*ManagerImpl) SetHostname

func (hc *ManagerImpl) SetHostname(hostname string)

func (*ManagerImpl) SetVersion

func (hc *ManagerImpl) SetVersion(version string)

func (*ManagerImpl) Start

func (hc *ManagerImpl) Start(ctx context.Context) error

Start starts the health checker service

func (*ManagerImpl) StartTime

func (hc *ManagerImpl) StartTime() time.Time

func (*ManagerImpl) Stop

func (hc *ManagerImpl) Stop(ctx context.Context) error

Stop stops the health checker service

func (*ManagerImpl) Subscribe

func (hc *ManagerImpl) Subscribe(callback healthinternal.HealthCallback) error

Subscribe adds a callback for health status changes

func (*ManagerImpl) Unregister

func (hc *ManagerImpl) Unregister(name string) error

Unregister unregisters a health check

func (*ManagerImpl) Version

func (hc *ManagerImpl) Version() string

type MockHealthCheck

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

MockHealthCheck is a mock health check for testing

func NewMockHealthCheck

func NewMockHealthCheck(name string, status health.HealthStatus, message string) *MockHealthCheck

NewMockHealthCheck creates a new mock health check

func (*MockHealthCheck) Check

func (*MockHealthCheck) Critical

func (mhc *MockHealthCheck) Critical() bool

func (*MockHealthCheck) Dependencies

func (mhc *MockHealthCheck) Dependencies() []string

func (*MockHealthCheck) GetCallCount

func (mhc *MockHealthCheck) GetCallCount() int

func (*MockHealthCheck) GetLastCall

func (mhc *MockHealthCheck) GetLastCall() time.Time

func (*MockHealthCheck) Name

func (mhc *MockHealthCheck) Name() string

func (*MockHealthCheck) ResetCallCount

func (mhc *MockHealthCheck) ResetCallCount()

func (*MockHealthCheck) SetCheckFunc

func (mhc *MockHealthCheck) SetCheckFunc(fn func(ctx context.Context) *health.HealthResult)

func (*MockHealthCheck) SetCritical

func (mhc *MockHealthCheck) SetCritical(critical bool)

func (*MockHealthCheck) SetDependencies

func (mhc *MockHealthCheck) SetDependencies(deps []string)

func (*MockHealthCheck) SetMessage

func (mhc *MockHealthCheck) SetMessage(message string)

func (*MockHealthCheck) SetResult

func (mhc *MockHealthCheck) SetResult(result *health.HealthResult)

func (*MockHealthCheck) SetStatus

func (mhc *MockHealthCheck) SetStatus(status health.HealthStatus)

Test helpers for MockHealthCheck

func (*MockHealthCheck) SetTimeout

func (mhc *MockHealthCheck) SetTimeout(timeout time.Duration)

func (*MockHealthCheck) Timeout

func (mhc *MockHealthCheck) Timeout() time.Duration

type PredictiveAggregator

type PredictiveAggregator = healthcore.PredictiveAggregator

PredictiveAggregator implements predictive health aggregation

func NewPredictiveAggregator

func NewPredictiveAggregator(config *AggregatorConfig) *PredictiveAggregator

NewPredictiveAggregator creates a new predictive health aggregator

type SimpleHealthCheck

type SimpleHealthCheck = healthcore.SimpleHealthCheck

SimpleHealthCheck implements a simple function-based health check

func NewSimpleHealthCheck

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

NewSimpleHealthCheck creates a new simple health check

type SmartAggregator

type SmartAggregator = healthcore.SmartAggregator

SmartAggregator implements advanced aggregation logic with machine learning-like features

func NewSmartAggregator

func NewSmartAggregator(config *AggregatorConfig) *SmartAggregator

NewSmartAggregator creates a new smart health aggregator

type TestHealthChecker

type TestHealthChecker struct {
	shared.HealthManager
	// contains filtered or unexported fields
}

TestHealthChecker is a test-friendly health checker

func NewTestHealthChecker

func NewTestHealthChecker() *TestHealthChecker

NewTestHealthChecker creates a new test health checker

func (*TestHealthChecker) SetCheckResult

func (thc *TestHealthChecker) SetCheckResult(name string, result *health.HealthResult)

SetCheckResult sets a predefined result for a specific check

type TestHealthService

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

TestHealthService is a mock health service for testing

func NewTestHealthService

func NewTestHealthService(name string) *TestHealthService

NewTestHealthService creates a new test health service

func (*TestHealthService) CheckAll

func (ths *TestHealthService) CheckAll(ctx context.Context) *health.HealthReport

Health checking

func (*TestHealthService) CheckOne

func (ths *TestHealthService) CheckOne(ctx context.Context, name string) *health.HealthResult

func (*TestHealthService) Checker

func (ths *TestHealthService) Checker() shared.HealthManager

func (*TestHealthService) Dependencies

func (ths *TestHealthService) Dependencies() []string

func (*TestHealthService) GetCallCount

func (ths *TestHealthService) GetCallCount(method string) int

func (*TestHealthService) GetCheck

func (ths *TestHealthService) GetCheck(name string) (health.HealthCheck, error)

func (*TestHealthService) GetConfiguration

func (ths *TestHealthService) GetConfiguration() *health.HealthConfig

func (*TestHealthService) GetEnvironment

func (ths *TestHealthService) GetEnvironment() string

func (*TestHealthService) GetLastReport

func (ths *TestHealthService) GetLastReport() *health.HealthReport

func (*TestHealthService) GetMethodCalls

func (ths *TestHealthService) GetMethodCalls() []string

func (*TestHealthService) GetStats

func (ths *TestHealthService) GetStats() *health.HealthCheckerStats

func (*TestHealthService) GetStatus

func (ths *TestHealthService) GetStatus() health.HealthStatus

func (*TestHealthService) GetVersion

func (ths *TestHealthService) GetVersion() string

Service info

func (*TestHealthService) IsDegraded

func (ths *TestHealthService) IsDegraded() bool

func (*TestHealthService) IsHealthy

func (ths *TestHealthService) IsHealthy() bool

func (*TestHealthService) ListChecks

func (ths *TestHealthService) ListChecks() []string

func (*TestHealthService) Name

func (ths *TestHealthService) Name() string

Service lifecycle methods

func (*TestHealthService) OnHealthCheck

func (ths *TestHealthService) OnHealthCheck(ctx context.Context) error

func (*TestHealthService) RegisterCheck

func (ths *TestHealthService) RegisterCheck(name string, check health.HealthCheck) error

Health check management

func (*TestHealthService) ResetCalls

func (ths *TestHealthService) ResetCalls()

func (*TestHealthService) SetError

func (ths *TestHealthService) SetError(method string, err error)

func (*TestHealthService) SetLastReport

func (ths *TestHealthService) SetLastReport(report *health.HealthReport)

func (*TestHealthService) SetStatus

func (ths *TestHealthService) SetStatus(status health.HealthStatus)

Test helpers

func (*TestHealthService) Start

func (ths *TestHealthService) Start(ctx context.Context) error

func (*TestHealthService) Stop

func (ths *TestHealthService) Stop(ctx context.Context) error

func (*TestHealthService) Subscribe

func (ths *TestHealthService) Subscribe(callback health.HealthCallback) error

Health monitoring

func (*TestHealthService) UnregisterCheck

func (ths *TestHealthService) UnregisterCheck(name string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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