health

package
v3.1.31 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package health provides comprehensive health checking for Gitea services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker func(ctx context.Context) *ComponentCheck

Checker is a function that performs a health check

func NewCacheChecker

func NewCacheChecker(pingFunc func(ctx context.Context) error) Checker

NewCacheChecker creates a cache health checker

func NewDatabaseChecker

func NewDatabaseChecker(pingFunc func(ctx context.Context) error) Checker

NewDatabaseChecker creates a database health checker

func NewExternalServiceChecker

func NewExternalServiceChecker(name string, checkFunc func(ctx context.Context) error) Checker

NewExternalServiceChecker creates a checker for external services

func NewGitChecker

func NewGitChecker(checkFunc func(ctx context.Context) (string, error)) Checker

NewGitChecker creates a git service health checker

func NewQueueChecker

func NewQueueChecker(getQueueStats func() (pending, processing int)) Checker

NewQueueChecker creates a checker for the task queue

func NewSSHChecker

func NewSSHChecker(isEnabled bool, port int) Checker

NewSSHChecker creates an SSH service health checker

type ComponentCheck

type ComponentCheck struct {
	Name        string         `json:"name"`
	Status      Status         `json:"status"`
	Message     string         `json:"message,omitempty"`
	Duration    time.Duration  `json:"duration_ms"`
	LastChecked time.Time      `json:"last_checked"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

ComponentCheck represents a health check for a single component

type Manager

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

Manager manages health checks

func GetManager

func GetManager() *Manager

GetManager returns the default health manager

func (*Manager) Check

func (m *Manager) Check(ctx context.Context, includeSystem bool) *Response

Check performs all health checks

func (*Manager) CheckSingle

func (m *Manager) CheckSingle(ctx context.Context, name string) (*ComponentCheck, bool)

CheckSingle performs a single component check

func (*Manager) LivenessCheck

func (m *Manager) LivenessCheck() *ComponentCheck

LivenessCheck performs a quick liveness check (is the service running?)

func (*Manager) ReadinessCheck

func (m *Manager) ReadinessCheck(ctx context.Context) *Response

ReadinessCheck performs a readiness check (can the service handle requests?)

func (*Manager) RegisterChecker

func (m *Manager) RegisterChecker(name string, checker Checker)

RegisterChecker registers a new health checker

func (*Manager) UnregisterChecker

func (m *Manager) UnregisterChecker(name string)

UnregisterChecker removes a health checker

type Response

type Response struct {
	Status     Status                          `json:"status"`
	Version    string                          `json:"version"`
	Uptime     time.Duration                   `json:"uptime_seconds"`
	Timestamp  time.Time                       `json:"timestamp"`
	Components map[string]*ComponentCheck      `json:"components"`
	System     *SystemInfo                     `json:"system,omitempty"`
	Circuits   map[string]circuitbreaker.Stats `json:"circuit_breakers,omitempty"`
}

Response represents the complete health check response

type Status

type Status string

Status represents the health status of a component

const (
	StatusHealthy   Status = "healthy"
	StatusDegraded  Status = "degraded"
	StatusUnhealthy Status = "unhealthy"
	StatusUnknown   Status = "unknown"
)

type SystemInfo

type SystemInfo struct {
	GoVersion     string  `json:"go_version"`
	NumGoroutines int     `json:"goroutines"`
	MemoryAllocMB float64 `json:"memory_alloc_mb"`
	MemorySysMB   float64 `json:"memory_sys_mb"`
	NumCPU        int     `json:"num_cpu"`
	GOMAXPROCS    int     `json:"gomaxprocs"`
}

SystemInfo contains system-level health information

Source Files

  • health.go

Jump to

Keyboard shortcuts

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