recovery

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

internal/recovery/health_monitor.go

internal/recovery/restart_policy.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertSeverity

type AlertSeverity string

AlertSeverity represents alert severity

const (
	AlertSeverityInfo     AlertSeverity = "info"
	AlertSeverityWarning  AlertSeverity = "warning"
	AlertSeverityCritical AlertSeverity = "critical"
)

type AlertType

type AlertType string

AlertType represents the type of alert

const (
	AlertTypeHealthCheck     AlertType = "health_check"
	AlertTypeResourceLimit   AlertType = "resource_limit"
	AlertTypeRestartRequired AlertType = "restart_required"
	AlertTypeRecoveryFailed  AlertType = "recovery_failed"
)

type DiskUsage

type DiskUsage struct {
	Total       uint64
	Used        uint64
	Free        uint64
	PercentUsed float64
}

DiskUsage represents disk usage information

type HealthAlert

type HealthAlert struct {
	Service   string
	Type      AlertType
	Message   string
	Severity  AlertSeverity
	Timestamp time.Time
	Action    string
}

HealthAlert represents a health alert

type HealthCheckFunc

type HealthCheckFunc func(containerID string) error

HealthCheckFunc is a function that performs health check

type HealthMonitor

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

HealthMonitor monitors service health and triggers recovery

func NewHealthMonitor

func NewHealthMonitor(cfg *config.Config, restartMgr *RestartManager) (*HealthMonitor, error)

NewHealthMonitor creates a new health monitor

func (*HealthMonitor) GetAlerts

func (hm *HealthMonitor) GetAlerts() <-chan HealthAlert

GetAlerts returns the alerts channel

func (*HealthMonitor) GetStatus

func (hm *HealthMonitor) GetStatus() map[string]HealthStatus

GetStatus returns the current health status of all services

func (*HealthMonitor) RegisterService

func (hm *HealthMonitor) RegisterService(service, containerID string, checkFunc HealthCheckFunc)

RegisterService registers a service for health monitoring

func (*HealthMonitor) Start

func (hm *HealthMonitor) Start(ctx context.Context)

Start starts health monitoring for all registered services

func (*HealthMonitor) Stop

func (hm *HealthMonitor) Stop()

Stop stops all health monitors

type HealthStatus

type HealthStatus struct {
	Healthy       bool
	Message       string
	LastCheck     time.Time
	ResponseTime  time.Duration
	ResourceUsage ResourceUsage
}

HealthStatus represents the health status of a service

type ResourceUsage

type ResourceUsage struct {
	CPUPercent    float64
	MemoryPercent float64
	MemoryUsage   uint64
	MemoryLimit   uint64
	DiskUsage     uint64
	NetworkErrors uint64
}

ResourceUsage represents resource usage metrics

type RestartManager

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

RestartManager manages container restart policies

func NewRestartManager

func NewRestartManager() *RestartManager

NewRestartManager creates a new restart manager

func (*RestartManager) GetNotifications

func (rm *RestartManager) GetNotifications() <-chan RestartNotification

GetNotifications returns the notification channel

func (*RestartManager) GetStatus

func (rm *RestartManager) GetStatus() map[string]RestartStatus

GetStatus returns restart status for all services

func (*RestartManager) RecordRestart

func (rm *RestartManager) RecordRestart(service string, success bool)

RecordRestart records a restart attempt

func (*RestartManager) RegisterPolicy

func (rm *RestartManager) RegisterPolicy(service string, policy *ServicePolicy)

RegisterPolicy registers a restart policy for a service

func (*RestartManager) ResetAttempts

func (rm *RestartManager) ResetAttempts(service string)

ResetAttempts resets restart attempts for a service

func (*RestartManager) ShouldRestart

func (rm *RestartManager) ShouldRestart(service string, exitCode int) (bool, time.Duration)

ShouldRestart determines if a service should be restarted

type RestartNotification

type RestartNotification struct {
	Service   string
	Attempt   int
	Reason    string
	Success   bool
	Timestamp time.Time
}

RestartNotification represents a restart event

type RestartPolicy

type RestartPolicy string

RestartPolicy defines the restart behavior

const (
	RestartPolicyAlways        RestartPolicy = "always"
	RestartPolicyOnFailure     RestartPolicy = "on-failure"
	RestartPolicyUnlessStopped RestartPolicy = "unless-stopped"
	RestartPolicyNo            RestartPolicy = "no"
)

type RestartStatus

type RestartStatus struct {
	Service     string
	Policy      RestartPolicy
	Attempts    int
	MaxAttempts int
	LastRestart time.Time
	NextBackoff time.Duration
}

RestartStatus represents the restart status of a service

type ServiceMonitor

type ServiceMonitor struct {
	Service          string
	ContainerID      string
	HealthCheckFunc  HealthCheckFunc
	Interval         time.Duration
	Timeout          time.Duration
	FailureThreshold int
	// contains filtered or unexported fields
}

ServiceMonitor monitors a specific service

type ServicePolicy

type ServicePolicy struct {
	Service        string
	Policy         RestartPolicy
	MaxAttempts    int
	BackoffSeconds []int // Exponential backoff intervals
	OnRestart      func(service string, attempt int)
}

ServicePolicy defines restart policy for a service

type ServiceRestarter

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

ServiceRestarter handles the actual restart logic

func NewServiceRestarter

func NewServiceRestarter(manager *docker.Manager, restartMgr *RestartManager) *ServiceRestarter

NewServiceRestarter creates a new service restarter

func (*ServiceRestarter) MonitorService

func (sr *ServiceRestarter) MonitorService(ctx context.Context, containerID, service string)

MonitorService starts monitoring a service for restarts

func (*ServiceRestarter) StopMonitoring

func (sr *ServiceRestarter) StopMonitoring(service string)

StopMonitoring stops monitoring a service

Jump to

Keyboard shortcuts

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