core

package
v0.0.0-...-b34e599 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package core implements the basic logic of health checking virtual and real servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONConfigLoader

func JSONConfigLoader(path string, config *Config) error

JSONConfigLoader is intended to load a configuration from a JSON file. Currently, it is not implemented and will panic if called.

func KeepalivedConfigLoader

func KeepalivedConfigLoader(path string, config *Config) error

KeepalivedConfigLoader loads a configuration from a keepalived format file.

Types

type Config

type Config struct {
	// List of virtual servers configurations.
	Services []*service.Config `keepalive:"virtual_server"`
}

Config represents the configuration for virtual servers.

func (*Config) Dump

func (m *Config) Dump(path string) error

Dump serializes the configuration to a JSON file at the specified path. It creates a temporary file to ensure atomic write operations.

func (*Config) Prepare

func (m *Config) Prepare() error

Prepare processes the configuration by performing validation, propagating fields, unmapping IP addresses, etc.

type ConfigFormat

type ConfigFormat string

ConfigFormat represents the format in which the services configuration is loaded.

const (
	// KeepalivedFormat represents the keepalived configuration format.
	KeepalivedFormat ConfigFormat = "keepalived"
	// JSONFormat represents the JSON configuration format.
	JSONFormat ConfigFormat = "json" // currently unused
)

type ConfigLoader

type ConfigLoader func(path string, config *Config) error

ConfigLoader is a function type for loading configuration.

type Core

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

Core manages the lifecycle of the services.

func New

func New(announcer *announcer.Announcer, balancer *balancer.Balancer, metrics *metrics.ScopedMetrics, logger *log.Logger) *Core

New creates a new Core instance.

func (*Core) Reload

func (m *Core) Reload(config *Config) error

Reload updates the Core with a new configuration.

It first updates the announcer with the new services' announce groups, ensuring the announcer is in sync with the latest configuration. Then, it either updates existing services or adds new ones based on the new configuration. Finally, it stops services that are no longer present in the new configuration and replaces the old services with the new ones.

func (*Core) Run

func (m *Core) Run(ctx context.Context)

Run starts the Core service.

It runs the core's worker pool. The core will continue running until its Stop method is invoked.

func (*Core) Status

func (m *Core) Status() []*monalivepb.ServiceStatus

Status retrieves the current status of all services managed by the Core instance. It returns a slice of monalivepb.ServiceStatus messages representing the status of each service.

func (*Core) Stop

func (m *Core) Stop()

Stop initiates a graceful shutdown of the Core and all its services. It ensures that no new services are started, and existing services are stopped. It uses the shutdown mechanism to signal that the Core should no longer accept new tasks and performs cleanup for all services.

type Manager

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

Manager is a wrapper around the Core to facilitate external communication. It handles configuration loading, reloading, and status retrieval.

func NewManager

func NewManager(config *ManagerConfig, core *Core, metrics metrics.Provider, logger *log.Logger) (*Manager, error)

NewManager creates a new Manager instance. It selects the appropriate configuration loader based on the format specified in the config.

func (*Manager) GetStatus

GetStatus handles the RPC method to retrieve the current status of the service. It implements the GetStatus method defined in monalivepb. It returns a monalivepb.GetStatusResponse message containing the update timestamp and the current status of the services.

func (*Manager) Reload

Reload handles the RPC method to reload the service configuration. Firstly, it loads the configuration using the selected loader. Then, it prepares the configuration by validating and processing it. Finally, it reloads the Core instance with the new configuration.

Implements the Reload method defined in monalivepb.

type ManagerConfig

type ManagerConfig struct {
	// Embedded ServicesConfig for configuration.
	Services ServicesConfig `yaml:"services_config"`
}

ManagerConfig encapsulates the services configuration within a manager configuration.

type Metrics

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

Metrics ...

func NewMetrics

func NewMetrics(provider *metrics.ScopedMetrics) *Metrics

NewMetrics ...

func (*Metrics) DeleteService

func (m *Metrics) DeleteService(serviceLabels metrics.Labels)

func (*Metrics) Reals

func (m *Metrics) Reals() metrics.Gauge

func (*Metrics) RealsEnabled

func (m *Metrics) RealsEnabled() metrics.Gauge

func (*Metrics) RealsEnabledForService

func (m *Metrics) RealsEnabledForService(serviceLabels metrics.Labels) metrics.Gauge

func (*Metrics) RealsErrorsForService

func (m *Metrics) RealsErrorsForService(serviceLabels metrics.Labels) metrics.CounterVec

func (*Metrics) RealsForService

func (m *Metrics) RealsForService(serviceLabels metrics.Labels) metrics.Gauge

func (*Metrics) RealsResponseTimeForService

func (m *Metrics) RealsResponseTimeForService(serviceLabels metrics.Labels) metrics.Histogram

func (*Metrics) RealsTrasitionPeriodForService

func (m *Metrics) RealsTrasitionPeriodForService(serviceLabels metrics.Labels) metrics.Histogram

type ServicesConfig

type ServicesConfig struct {
	// Format of the services configuration file.
	Format ConfigFormat `yaml:"format"`
	// Path to the services configuration file.
	Path string `yaml:"path"`
	// Path where the dumped configuration will be saved.
	DumpPath string `yaml:"dump_path"`
}

ServicesConfig defines the configuration for loading and dumping service configurations. It includes the format of the configuration file, the path to the configuration file, and the path where the dumped configuration will be saved.

Directories

Path Synopsis
Package checker implements a health checking mechanism that handles the execution and processing of health checks, managing state transitions and event generation based on the results of these checks.
Package checker implements a health checking mechanism that handles the execution and processing of health checks, managing state transitions and event generation based on the results of these checks.
check
Package check contains various implementations of the health check.
Package check contains various implementations of the health check.
Package real implements the management of a real server entity.
Package real implements the management of a real server entity.
Package service implements the management of virtual server entity.
Package service implements the management of virtual server entity.

Jump to

Keyboard shortcuts

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