health

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(h *health.Health) http.Handler

Handler is a wrapper for health.Handler from "github.com/hellofresh/health-go/v5"

func New

func New(options ...health.Option) (*health.Health, error)

New is a wrapper for health.New from "github.com/hellofresh/health-go/v5"

func NewComponent

func NewComponent(config ComponentConfig) health.Component

NewComponent creates a new health.Component from ComponentConfig.

func NewHealthOptions

func NewHealthOptions(config HealthOptionsConfig) []health.Option

NewHealthOptions creates a slice of health.Option from HealthOptionsConfig.

func RegisterKafkaHealthChecks

func RegisterKafkaHealthChecks(h *health.Health, configs []SyncKafkaChecker, isAsync bool) error

RegisterKafkaHealthChecks registers Kafka health checks with the health package.

func SetupHealthChecks

func SetupHealthChecks(componentName, componentVersion string, enableSystemInfo bool, checkers ...HealthChecker) (*health.Health, error)

SetupHealthChecks sets up and registers health checks, returning the health.Health instance.

func StartHealthCheckServer

func StartHealthCheckServer(h *health.Health, port string)

StartHealthCheckServer starts the health check server.

Types

type AsyncChecker

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

AsyncChecker manages the asynchronous execution of a HealthChecker.

func NewAsyncChecker

func NewAsyncChecker(checker HealthChecker, interval time.Duration) *AsyncChecker

NewAsyncChecker creates a new AsyncChecker.

func (*AsyncChecker) HealthCheck

func (ac *AsyncChecker) HealthCheck() health.Component

HealthCheck returns the health.Component for the health-go library (for async checks).

func (*AsyncChecker) Start

func (ac *AsyncChecker) Start(ctx context.Context)

Start starts the asynchronous health check loop.

type AsyncCheckerComponent

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

AsyncCheckerComponent adapts a HealthChecker for asynchronous checks using a store.

func (*AsyncCheckerComponent) Check

func (ac *AsyncCheckerComponent) Check(ctx context.Context) error

Check retrieves the cached health check result for async check.

func (*AsyncCheckerComponent) Name

func (ac *AsyncCheckerComponent) Name() string

Name returns the name of the async health check component.

func (*AsyncCheckerComponent) Type

func (ac *AsyncCheckerComponent) Type() string

Type returns the type of the async health check component.

type AsyncHealthStore

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

AsyncHealthStore stores the results of asynchronous health checks.

func NewAsyncHealthStore

func NewAsyncHealthStore() *AsyncHealthStore

NewAsyncHealthStore creates a new AsyncHealthStore.

func (*AsyncHealthStore) GetStatus

func (s *AsyncHealthStore) GetStatus(name string) error

GetStatus retrieves the status of a health check.

func (*AsyncHealthStore) UpdateStatus

func (s *AsyncHealthStore) UpdateStatus(name string, err error)

UpdateStatus updates the status of a health check.

type AsyncKafkaChecker

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

AsyncKafkaChecker is an asynchronous health checker for Kafka.

func NewAsyncKafkaChecker

func NewAsyncKafkaChecker(checker *KafkaChecker) *AsyncKafkaChecker

NewAsyncKafkaChecker creates a new AsyncKafkaChecker.

func (*AsyncKafkaChecker) Check

func (akc *AsyncKafkaChecker) Check(ctx context.Context) error

Check retrieves the cached health check result.

func (*AsyncKafkaChecker) GetTimeOut

func (k *AsyncKafkaChecker) GetTimeOut() time.Duration

GetTimeOut returns the timeout for the Kafka health check.

func (*AsyncKafkaChecker) Name

func (akc *AsyncKafkaChecker) Name() string

Name returns the name of the Kafka health check.

func (*AsyncKafkaChecker) Start

func (akc *AsyncKafkaChecker) Start(ctx context.Context)

Start begins the asynchronous Kafka health check loop.

func (*AsyncKafkaChecker) Type

func (akc *AsyncKafkaChecker) Type() string

Type returns the type of the health check.

type ComponentConfig

type ComponentConfig struct {
	Name    string
	Version string
}

ComponentConfig is the configuration for the health component.

type ConsumerClient

type ConsumerClient interface {
	Assignment() ([]kafka.TopicPartition, error)
	Position(partitions []kafka.TopicPartition) (offsets []kafka.TopicPartition, err error)
	Committed(partitions []kafka.TopicPartition, timeoutMs int) (offsets []kafka.TopicPartition, err error)
}

type ConsumerOffsetStore

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

Store previous offsets for each partition

func NewConsumerOffsetStore

func NewConsumerOffsetStore() *ConsumerOffsetStore

func (*ConsumerOffsetStore) GetOffsets

func (s *ConsumerOffsetStore) GetOffsets(topic string, partition int32) (position kafka.Offset, commit kafka.Offset, exists bool)

func (*ConsumerOffsetStore) SetOffsets

func (s *ConsumerOffsetStore) SetOffsets(topic string, partition int32, position kafka.Offset, commit kafka.Offset)

type HTTPChecker

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

HTTPChecker implements the HealthChecker interface for HTTP endpoints.

func NewHTTPChecker

func NewHTTPChecker(config HTTPCheckerConfig) *HTTPChecker

NewHTTPChecker creates a new HTTPChecker.

func (*HTTPChecker) Check

func (c *HTTPChecker) Check(ctx context.Context) error

Check performs the HTTP health check.

func (*HTTPChecker) GetTimeOut

func (c *HTTPChecker) GetTimeOut() time.Duration

func (*HTTPChecker) Name

func (c *HTTPChecker) Name() string

Name returns the name of the health check.

func (*HTTPChecker) Type

func (c *HTTPChecker) Type() string

Type returns the type of the health check (http).

type HTTPCheckerConfig

type HTTPCheckerConfig struct {
	URL            string
	Timeout        time.Duration
	Name           string
	ExpectedStatus int
}

HTTPCheckerConfig holds configuration for the HTTPChecker.

type HealthChecker

type HealthChecker interface {
	Check(ctx context.Context) error
	Name() string
	Type() string // e.g., "redis", "s3", "kafka", "http"
	GetTimeOut() time.Duration
}

HealthChecker is the interface that all health checks must implement.

type HealthOptionsConfig

type HealthOptionsConfig struct {
	ComponentConfig   ComponentConfig
	SystemInfoEnabled bool
}

HealthOptionsConfig allows configuring various aspects of the health checks.

type KafkaChecker

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

KafkaChecker holds the configuration for a KafkaChecker with a stop channel.

func NewSyncKafkaChecker

func NewSyncKafkaChecker(checker SyncKafkaChecker, store *ConsumerOffsetStore) *KafkaChecker

NewKafkaChecker creates a new KafkaChecker struct

func (*KafkaChecker) Check

func (k *KafkaChecker) Check(ctx context.Context) error

Check performs a Kafka health check.

func (*KafkaChecker) GetTimeOut

func (k *KafkaChecker) GetTimeOut() time.Duration

GetTimeOut returns the timeout for the Kafka health check.

func (*KafkaChecker) Name

func (k *KafkaChecker) Name() string

Name returns the name of the Kafka health check.

func (*KafkaChecker) Shutdown

func (k *KafkaChecker) Shutdown()

Shutdown stops the Kafka health check.

func (*KafkaChecker) Type

func (k *KafkaChecker) Type() string

Type returns the type of the Kafka health check.

type ProducerClient

type ProducerClient interface {
	GetMetadata(topic *string, allTopics bool, timeoutMs int) (*kafka.Metadata, error)
}

type S3Checker

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

S3Checker implements the HealthChecker interface for AWS S3.

func NewS3Checker

func NewS3Checker(config S3CheckerConfig) (*S3Checker, error)

NewS3Checker creates a new S3Checker. Handles optional client injection.

func (*S3Checker) Check

func (c *S3Checker) Check(ctx context.Context) error

Check performs the S3 health check.

func (*S3Checker) GetTimeOut

func (c *S3Checker) GetTimeOut() time.Duration

func (*S3Checker) Name

func (c *S3Checker) Name() string

Name returns the name of the health check.

func (*S3Checker) Type

func (c *S3Checker) Type() string

Type returns the type of the health check (s3).

type S3CheckerConfig

type S3CheckerConfig struct {
	BucketName string
	Timeout    time.Duration
	Name       string
	Region     string
	S3Client   s3iface.S3API
}

S3CheckerConfig holds configuration for the S3Checker.

type SyncKafkaChecker

type SyncKafkaChecker struct {
	Name     string        // Name of this health check.
	Interval time.Duration // Interval for the health check, only for repeated checks.
	Timeout  time.Duration // Timeout for the HTTP request.

	Producer       ProducerClient
	Consumer       ConsumerClient
	RequiredTopics []string
	MaxLag         int64
}

SyncKafkaChecker holds the configuration for a KafkaChecker.

Jump to

Keyboard shortcuts

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