health

package
v0.0.0-...-adf2613 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package health provides health check functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHealthStatus

func AddHealthStatus(serviceName string, status string)

AddHealthStatus adds a status point to the history.

Summary: Records a new health status point for a service.

Parameters:

  • serviceName: string. The name of the service.
  • status: string. The health status (e.g., "healthy", "unhealthy").

Side Effects:

  • Updates the global historyStore.
  • Prunes history if it exceeds 1000 points.

func CheckAuth

func CheckAuth() map[string]CheckResult

CheckAuth performs health checks for authentication configuration.

Summary: Validates the presence of critical API keys and OAuth configuration.

Returns:

  • map[string]CheckResult: A map of check names to their results.

Side Effects:

  • Reads environment variables.

func GetHealthHistory

func GetHealthHistory() map[string][]HistoryPoint

GetHealthHistory returns the history for all services.

Summary: Retrieves the complete health history map.

Returns:

  • map[string][]HistoryPoint: A map of service names to their health history points.

Side Effects:

  • Acquires a read lock on the history store.

func NewChecker

NewChecker creates a new health checker for the given upstream service.

It determines the type of service (HTTP, gRPC, etc.) and creates an appropriate health check strategy wrapped with latency metrics and status change listeners.

Parameters:

  • uc: *configv1.UpstreamServiceConfig. The configuration of the upstream service to check.

Returns:

  • health.Checker: A configured health checker instance. Returns nil if the configuration is nil or invalid.

Side Effects:

  • Registers metrics for the health check.

Summary: Initializes NewChecker operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func SetGlobalAlertConfig

func SetGlobalAlertConfig(cfg *configv1.AlertConfig)

SetGlobalAlertConfig sets the global alert configuration.

It updates the thread-safe global configuration used for sending alerts on health status changes.

Parameters:

  • cfg: *configv1.AlertConfig. The new alert configuration.

Returns:

None.

Side Effects:

  • Updates a global variable protected by a mutex.

Summary: Updates SetGlobalAlertConfig operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

Types

type CheckFunc

type CheckFunc func(context.Context) CheckResult

CheckFunc is a function that performs a health check.

Summary: Function signature for a health check execution logic.

type CheckResult

type CheckResult struct {
	Status  string `json:"status"`
	Message string `json:"message,omitempty"`
	Latency string `json:"latency,omitempty"`
	Diff    string `json:"diff,omitempty"`
}

CheckResult represents a single check result.

Summary: The outcome of a single health check execution.

type Doctor

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

Doctor is the health check handler.

Summary: Registry and handler for system health checks (Doctor).

func NewDoctor

func NewDoctor() *Doctor

NewDoctor creates a new Doctor.

Summary: Initializes a new Doctor instance.

Returns:

  • *Doctor: The initialized doctor registry.

Side Effects:

  • Initializes internal maps and HTTP client.

func (*Doctor) AddCheck

func (d *Doctor) AddCheck(name string, check CheckFunc)

AddCheck adds a named health check.

Summary: Registers a custom health check function.

Parameters:

  • name: string. The unique name of the check.
  • check: CheckFunc. The function to execute.

Side Effects:

  • Updates the internal checks map.

func (*Doctor) Handler

func (d *Doctor) Handler() http.HandlerFunc

Handler returns the http handler.

Summary: Returns an HTTP handler that runs all checks and returns a JSON report.

Returns:

  • http.HandlerFunc: The HTTP handler.

Side Effects:

  • Executes all registered health checks.
  • Makes an external network call to google.com (connectivity check).
  • Reads environment variables (Auth checks).
  • Writes JSON response to the client.

type DoctorReport

type DoctorReport struct {
	Status    string                 `json:"status"`
	Timestamp time.Time              `json:"timestamp"`
	Checks    map[string]CheckResult `json:"checks"`
}

DoctorReport represents the full doctor report.

Summary: Aggregated health report containing all check results.

type HTTPServiceWithHealthCheck

type HTTPServiceWithHealthCheck interface {
	// GetAddress returns the address of the service.
	//
	// Returns:
	//   - string: The network address of the service.
	GetAddress() string
	// GetHealthCheck returns the HTTP health check configuration for the service.
	//
	// Returns:
	//   - *configv1.HttpHealthCheck: The health check configuration.
	GetHealthCheck() *configv1.HttpHealthCheck
}

HTTPServiceWithHealthCheck is an interface for services that have an address and an HTTP health check.

Summary: Represents a HTTPServiceWithHealthCheck.

type HistoryPoint

type HistoryPoint struct {
	Timestamp int64  `json:"timestamp"` // Unix millis
	Status    string `json:"status"`
}

HistoryPoint represents a single point in time for a service's health.

Summary: A data point representing service health status at a specific time.

type ServiceHealthHistory

type ServiceHealthHistory struct {
	Points []HistoryPoint
}

ServiceHealthHistory stores the history for a service.

Summary: Collection of historical health data points for a service.

Jump to

Keyboard shortcuts

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