Documentation
¶
Index ¶
- Constants
- Variables
- func IncBackendSelected(name, address string)
- func IncConfigReloads(result string)
- func IncHealthcheckFailures(typ, address, reason string)
- func IncHealthcheckTotal(name, typ, address, result string)
- func IncRecordResolutions(name, result string)
- func NewHTTPSTransport(cc *tls.Config) *http.Transport
- func NewTLSClientConfig(certPath, keyPath, caPath string) (*tls.Config, error)
- func ObserveHealthcheck(name, typeStr, address string, start time.Time, result bool)
- func ObserveHealthcheckDuration(typ, address string, duration float64)
- func ObserveRecordResolutionDuration(name, result string, duration float64)
- func RegisterMetrics()
- func SetActiveBackends(name string, value float64)
- func SetBackendHealthStatus(name, address string, value float64)
- func SetBackendHealthcheckStatus(name, address, typeStr string, value float64)
- func SetBackendsTotal(value float64)
- func SetHealthchecksTotal(value float64)
- func SetRecordHealthStatus(name string, value float64)
- func SetRecordsTotal(value float64)
- func SetVersionInfo(version string)
- func SetZonesTotal(value float64)
- func WithClientInfo(ctx context.Context, ip net.IP, prefix uint8) context.Context
- type Backend
- func (b *Backend) ApplyHealthCheckResult(alive bool)
- func (b *Backend) GetASN() string
- func (b *Backend) GetAddress() string
- func (b *Backend) GetAssumeHealthy() bool
- func (b *Backend) GetCity() string
- func (b *Backend) GetContinent() string
- func (b *Backend) GetCountry() string
- func (b *Backend) GetDescription() string
- func (b *Backend) GetFall() int
- func (b *Backend) GetFqdn() string
- func (b *Backend) GetHealthChecks() []GenericHealthCheck
- func (b *Backend) GetLastHealthcheck() time.Time
- func (b *Backend) GetLatitude() float64
- func (b *Backend) GetLatitudeRad() float64
- func (b *Backend) GetLocation() string
- func (b *Backend) GetLongitude() float64
- func (b *Backend) GetLongitudeRad() float64
- func (b *Backend) GetPort() int
- func (b *Backend) GetPriority() int
- func (b *Backend) GetRise() int
- func (b *Backend) GetSubdivision() string
- func (b *Backend) GetTags() []string
- func (b *Backend) GetTimeout() string
- func (b *Backend) GetWeight() int
- func (b *Backend) HasGeoCoordinates() bool
- func (b *Backend) IsAlive() bool
- func (b *Backend) IsEnabled() bool
- func (b *Backend) IsHealthy() bool
- func (b *Backend) IsPassive() bool
- func (b *Backend) Lock()
- func (b *Backend) SetAlive(alive bool)
- func (b *Backend) SetFqdn(fqdn string)
- func (b *Backend) SetLastHealthcheck(t time.Time)
- func (b *Backend) Unlock()
- func (b *Backend) UnmarshalYAML(unmarshal func(interface{}) error) error
- type BackendInterface
- type BackendState
- type ClientInfo
- type CustomSubnet
- type DiscoveredEndpoint
- type DiscoveryConfig
- type FallbackPolicy
- type GRPCHealthCheck
- type GSLB
- func (g *GSLB) AcquireRedisLock(ctx context.Context, zone, fqdn, address string, ttl time.Duration) (bool, error)
- func (g *GSLB) ConnectRedis() error
- func (g *GSLB) GetMaxStaggerStart() time.Duration
- func (g *GSLB) GetRedisHealth(ctx context.Context, zone, fqdn, address string) (bool, error)
- func (g *GSLB) GetResolutionIdleTimeout() time.Duration
- func (g *GSLB) LoadState() error
- func (g *GSLB) Name() string
- func (g *GSLB) RegisterAPIHandlers(mux *http.ServeMux)
- func (g *GSLB) SaveState() error
- func (g *GSLB) ServeAPI()
- func (g *GSLB) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)
- func (g *GSLB) SetRedisHealth(ctx context.Context, zone, fqdn, address string, alive bool, ttl time.Duration) error
- func (g *GSLB) StartStatePersistLoop(ctx context.Context)
- func (g *GSLB) UnmarshalYAML(unmarshal func(interface{}) error) error
- type GenericHealthCheck
- type HTTPHealthCheck
- type HealthCheck
- type ICMPHealthCheck
- type LuaHealthCheck
- type MockHealthCheck
- type MySQLHealthCheck
- type Pinger
- type RealPinger
- type Record
- type RedisHealthUpdate
- type TCPHealthCheck
Constants ¶
const ICMPType = "icmp"
Variables ¶
var ( GlobalHealthcheckProfiles map[string]*HealthCheck ProfilesMutex sync.RWMutex )
Global map for global healthcheck profiles loaded from Corefile
var Version = "dev"
Version of the GSLB plugin, set at build time
Functions ¶
func IncBackendSelected ¶ added in v0.8.0
func IncBackendSelected(name, address string)
func IncConfigReloads ¶ added in v0.8.0
func IncConfigReloads(result string)
func IncHealthcheckFailures ¶ added in v0.8.0
func IncHealthcheckFailures(typ, address, reason string)
func IncHealthcheckTotal ¶ added in v0.3.0
func IncHealthcheckTotal(name, typ, address, result string)
func IncRecordResolutions ¶ added in v0.8.0
func IncRecordResolutions(name, result string)
func NewTLSClientConfig ¶ added in v0.19.0
NewTLSConfig returns a TLS config that includes a certificate and key pair If caPath is empty, default root store will be used If certPath or keyPath are empty, client certificate will not be loaded
func ObserveHealthcheck ¶ added in v0.3.0
func ObserveHealthcheckDuration ¶ added in v0.3.0
func ObserveRecordResolutionDuration ¶ added in v0.8.0
func RegisterMetrics ¶ added in v0.3.0
func RegisterMetrics()
func SetActiveBackends ¶ added in v0.8.0
func SetBackendHealthStatus ¶ added in v0.8.0
func SetBackendHealthcheckStatus ¶ added in v0.8.0
func SetBackendsTotal ¶ added in v0.8.0
func SetBackendsTotal(value float64)
func SetHealthchecksTotal ¶ added in v0.8.0
func SetHealthchecksTotal(value float64)
func SetRecordHealthStatus ¶ added in v0.8.0
func SetRecordsTotal ¶ added in v0.8.0
func SetRecordsTotal(value float64)
func SetVersionInfo ¶ added in v0.8.0
func SetVersionInfo(version string)
func SetZonesTotal ¶ added in v0.10.0
func SetZonesTotal(value float64)
Types ¶
type Backend ¶
type Backend struct {
Fqdn string // Fully qualified domain name
Description string // Description of the backend
Address string // IP address or hostname
Port int // Port number of the backend
Priority int // Priority for load balancing
Weight int // Weight for weighted load balancing
Enable bool // Enable or disable the backend
Tags []string // List of tags for filtering or grouping
HealthChecks []GenericHealthCheck `yaml:"healthchecks"` // Health check configurations
Timeout string // Timeout for requests
Alive bool // Indicates if the backend is alive
Continent string // Continent code for GeoIP (e.g. EU)
Country string // Country code for GeoIP
Subdivision string // Subdivision/state code for GeoIP (e.g. CA, NY)
City string // City name for GeoIP
ASN string // ASN for GeoIP
Location string // location
Longitude float64 // Longitude for distance-based GeoIP routing
Latitude float64 // Latitude for distance-based GeoIP routing
LongitudeRad float64 // Precomputed longitude in radians for distance calculations
LatitudeRad float64 // Precomputed latitude in radians for distance calculations
HasCoordinates bool // Indicates whether both coordinates were explicitly configured
LastHealthcheck time.Time // Last time a healthcheck was launched
AssumeHealthy bool `yaml:"assume_healthy"` // Bypass healthchecks and assume UP
Passive bool `yaml:"passive"` // Passive health checking, read from Redis only
Rise int `yaml:"rise" default:"2"`
Fall int `yaml:"fall" default:"3"`
// contains filtered or unexported fields
}
Backend represents an individual backend with health check settings.
func (*Backend) ApplyHealthCheckResult ¶ added in v0.22.0
func (*Backend) GetAddress ¶
func (*Backend) GetAssumeHealthy ¶ added in v0.21.0
func (*Backend) GetContinent ¶ added in v0.18.0
func (*Backend) GetCountry ¶ added in v0.3.0
func (*Backend) GetDescription ¶
func (*Backend) GetHealthChecks ¶
func (b *Backend) GetHealthChecks() []GenericHealthCheck
func (*Backend) GetLastHealthcheck ¶ added in v0.22.0
func (*Backend) GetLatitude ¶ added in v0.18.0
func (*Backend) GetLatitudeRad ¶ added in v0.18.0
func (*Backend) GetLocation ¶ added in v0.3.0
func (*Backend) GetLongitude ¶ added in v0.18.0
func (*Backend) GetLongitudeRad ¶ added in v0.18.0
func (*Backend) GetPriority ¶
func (*Backend) GetSubdivision ¶ added in v0.18.0
func (*Backend) GetTimeout ¶
func (*Backend) HasGeoCoordinates ¶ added in v0.18.0
func (*Backend) SetLastHealthcheck ¶ added in v0.22.0
func (*Backend) UnmarshalYAML ¶
type BackendInterface ¶
type BackendInterface interface {
GetFqdn() string
SetFqdn(fqdn string)
GetDescription() string
GetAddress() string
GetPort() int
GetPriority() int
GetWeight() int
IsEnabled() bool
GetAssumeHealthy() bool
IsPassive() bool
GetRise() int
GetFall() int
GetTags() []string
GetHealthChecks() []GenericHealthCheck
GetTimeout() string
GetContinent() string
GetCountry() string
GetSubdivision() string
GetCity() string
GetASN() string
GetLocation() string
GetLongitude() float64
GetLatitude() float64
GetLongitudeRad() float64
GetLatitudeRad() float64
HasGeoCoordinates() bool
IsHealthy() bool
IsAlive() bool
SetAlive(alive bool)
GetLastHealthcheck() time.Time
SetLastHealthcheck(t time.Time)
ApplyHealthCheckResult(alive bool)
Lock()
Unlock()
// contains filtered or unexported methods
}
type BackendState ¶ added in v0.22.0
type ClientInfo ¶ added in v0.3.0
func GetClientInfo ¶ added in v0.3.0
func GetClientInfo(ctx context.Context) *ClientInfo
type CustomSubnet ¶ added in v0.21.0
type DiscoveredEndpoint ¶ added in v0.21.0
type DiscoveryConfig ¶ added in v0.21.0
type DiscoveryConfig struct {
Type string `yaml:"type"`
Endpoint string `yaml:"endpoint"`
Service string `yaml:"service"`
Interval string `yaml:"interval"`
Tag string `yaml:"tag"`
}
func (*DiscoveryConfig) FetchEndpoints ¶ added in v0.21.0
func (d *DiscoveryConfig) FetchEndpoints() ([]DiscoveredEndpoint, error)
type FallbackPolicy ¶ added in v0.22.0
type FallbackPolicy struct {
Mode string `yaml:"mode"`
FallbackIPs []string `yaml:"fallback_ips"`
FallbackCNAME string `yaml:"fallback_cname"`
Rcode string `yaml:"rcode"`
}
FallbackPolicy represents the behavior of the record when all backends are unhealthy/disabled.
type GRPCHealthCheck ¶ added in v0.3.0
type GRPCHealthCheck struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Service string `yaml:"service"`
Timeout time.Duration `yaml:"timeout"`
EnableTLS bool `yaml:"enable_tls"`
Cert string `yaml:"cert_path"`
Key string `yaml:"key_path"`
CA string `yaml:"ca_path"`
SkipTLSVerify bool `yaml:"skip_tls_verify"`
}
func (*GRPCHealthCheck) Check ¶ added in v0.3.0
func (h *GRPCHealthCheck) Check() error
func (*GRPCHealthCheck) Equals ¶ added in v0.3.0
func (h *GRPCHealthCheck) Equals(other GenericHealthCheck) bool
func (*GRPCHealthCheck) GetType ¶ added in v0.3.0
func (h *GRPCHealthCheck) GetType() string
func (*GRPCHealthCheck) PerformCheck ¶ added in v0.3.0
func (h *GRPCHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
func (*GRPCHealthCheck) SetDefault ¶ added in v0.3.0
func (h *GRPCHealthCheck) SetDefault()
type GSLB ¶
type GSLB struct {
Next plugin.Handler
Zones map[string]string // List of authoritative domains
Records map[string]map[string]*Record // zone -> fqdn -> record
HealthcheckProfiles map[string]*HealthCheck `yaml:"healthcheck_profiles"`
Zone string // Zone attendue pour la vérification des records
LastResolution sync.Map // key: domain (string), value: time.Time
RoundRobinIndex sync.Map
MaxStaggerStart string
BatchSizeStart int
ResolutionIdleTimeout string
ResolutionIdleMultiplier int // Multiplier for slow healthcheck interval
HealthcheckIdleMultiplier int // Multiplier for slow healthcheck interval
Mutex sync.RWMutex
LocationMapMutex sync.Mutex
UseEDNSCSubnet bool
LocationMap map[string]string
LocationMapIPNet []CustomSubnet
GeoIPCountryDB *geoip2.Reader // Loaded MaxMind DB (country)
GeoIPCityDB *geoip2.Reader // Loaded MaxMind DB (city)
GeoIPASNDB *geoip2.Reader // Loaded MaxMind DB (ASN)
APIEnable bool // Enable/disable API HTTP server
APICertPath string // TLS certificate path for API
APIKeyPath string // TLS key path for API
APIListenAddr string // API listen address (default 0.0.0.0)
APIListenPort string // API listen port (default 8080)
APIBasicUser string // HTTP Basic Auth username (optional)
APIBasicPass string // HTTP Basic Auth password (optional)
// DisableTXT disables TXT record resolution if set to true
DisableTXT bool
RedisEnable bool
RedisAddr string
RedisPassword string
RedisDB int
RedisKeyPrefix string
RedisSyncMode string
StatePersistEnable bool
StatePersistPath string
StatePersistInterval string
StateMaxAge string
// contains filtered or unexported fields
}
func (*GSLB) AcquireRedisLock ¶ added in v0.22.0
func (g *GSLB) AcquireRedisLock(ctx context.Context, zone, fqdn, address string, ttl time.Duration) (bool, error)
AcquireRedisLock attempts to acquire a lock for performing a health check.
func (*GSLB) ConnectRedis ¶ added in v0.22.0
ConnectRedis initializes the Redis client and starts the Pub/Sub subscriber.
func (*GSLB) GetMaxStaggerStart ¶
func (*GSLB) GetRedisHealth ¶ added in v0.22.0
GetRedisHealth fetches the current health check result from Redis.
func (*GSLB) GetResolutionIdleTimeout ¶
func (*GSLB) LoadState ¶ added in v0.22.0
LoadState reads the persisted state from disk and applies it.
func (*GSLB) RegisterAPIHandlers ¶ added in v0.9.0
RegisterAPIHandlers registers all API endpoints to the provided mux.
func (*GSLB) SaveState ¶ added in v0.22.0
SaveState serializes the current health check state and last resolution times to disk.
func (*GSLB) SetRedisHealth ¶ added in v0.22.0
func (g *GSLB) SetRedisHealth(ctx context.Context, zone, fqdn, address string, alive bool, ttl time.Duration) error
SetRedisHealth stores the health check result in Redis and publishes it.
func (*GSLB) StartStatePersistLoop ¶ added in v0.22.0
StartStatePersistLoop starts the periodic state saving background loop.
func (*GSLB) UnmarshalYAML ¶ added in v0.9.0
UnmarshalYAML implements custom YAML unmarshaling to handle healthcheck_profiles
type GenericHealthCheck ¶
type GenericHealthCheck interface {
// PerformCheck executes the health check for a backend.
PerformCheck(backend *Backend, fdqn string, maxRetries int) bool
// GetType returns the type of the health check (e.g., "http/80").
GetType() string
// Equals compares the current health check with another instance for equality.
Equals(other GenericHealthCheck) bool
}
GenericHealthCheck defines a common interface for health checks
type HTTPHealthCheck ¶
type HTTPHealthCheck struct {
Port int `yaml:"port" default:"443"`
EnableTLS bool `yaml:"enable_tls" default:"true"`
Cert string `yaml:"cert_path" default:""`
Key string `yaml:"key_path" default:""`
CA string `yaml:"ca_path" default:""`
URI string `yaml:"uri" default:"/"`
Method string `yaml:"method" default:"GET"`
Host string `yaml:"host" default:"localhost"`
Headers map[string]string `yaml:"headers"`
Timeout string `yaml:"timeout" default:"5s"`
ExpectedCode int `yaml:"expected_code" default:"200"`
ExpectedBody string `yaml:"expected_body" default:""`
SkipTLSVerify bool `yaml:"skip_tls_verify" default:"false"`
}
HTTPHealthCheck represents HTTP-specific health check settings.
func (*HTTPHealthCheck) Equals ¶
func (h *HTTPHealthCheck) Equals(other GenericHealthCheck) bool
Equals compares two HTTPHealthCheck objects for equality.
func (*HTTPHealthCheck) GetType ¶
func (h *HTTPHealthCheck) GetType() string
func (*HTTPHealthCheck) PerformCheck ¶
func (h *HTTPHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
PerformCheck implements the HealthCheck interface for HTTP health checks
func (*HTTPHealthCheck) SetDefault ¶
func (h *HTTPHealthCheck) SetDefault()
type HealthCheck ¶
type HealthCheck struct {
Type string `yaml:"type"`
Params map[string]interface{} `yaml:"params"`
Rise int `yaml:"rise"`
Fall int `yaml:"fall"`
}
func ResolveHealthcheckProfile ¶ added in v0.9.0
func ResolveHealthcheckProfile(profileName string, localProfiles map[string]*HealthCheck) (*HealthCheck, error)
ResolveProfile resolves a healthcheck profile to a concrete HealthCheck
func (*HealthCheck) ToSpecificHealthCheck ¶
func (hc *HealthCheck) ToSpecificHealthCheck() (GenericHealthCheck, error)
type ICMPHealthCheck ¶
type ICMPHealthCheck struct {
Count int `yaml:"count" default:"3"` // Number of ICMP packets to send
Timeout string `yaml:"timeout" default:"5s"` // Maximum duration for pings
}
ICMPHealthCheck represents the configuration for an ICMP health check.
func (*ICMPHealthCheck) Equals ¶
func (h *ICMPHealthCheck) Equals(other GenericHealthCheck) bool
Equals compares two ICMPHealthCheck objects for equality.
func (*ICMPHealthCheck) GetType ¶
func (h *ICMPHealthCheck) GetType() string
GetType returns the type of the health check as a string.
func (*ICMPHealthCheck) PerformCheck ¶
func (h *ICMPHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
PerformCheck executes the ICMP health check for a backend.
func (*ICMPHealthCheck) SetDefault ¶
func (h *ICMPHealthCheck) SetDefault()
SetDefault applies default values to ICMPHealthCheck fields.
type LuaHealthCheck ¶ added in v0.8.0
type LuaHealthCheck struct {
Script string `yaml:"script"`
Timeout time.Duration `yaml:"timeout"`
Proto atomic.Pointer[gopherlua.FunctionProto] `yaml:"-"`
}
func (*LuaHealthCheck) Equals ¶ added in v0.8.0
func (l *LuaHealthCheck) Equals(other GenericHealthCheck) bool
func (*LuaHealthCheck) GetType ¶ added in v0.8.0
func (l *LuaHealthCheck) GetType() string
func (*LuaHealthCheck) PerformCheck ¶ added in v0.8.0
func (l *LuaHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
func (*LuaHealthCheck) SetDefault ¶ added in v0.8.0
func (l *LuaHealthCheck) SetDefault()
type MockHealthCheck ¶
type MockHealthCheck struct{}
Mock a health check that always returns true (successful) For testing purpose
func (*MockHealthCheck) Equals ¶
func (hc *MockHealthCheck) Equals(other GenericHealthCheck) bool
func (*MockHealthCheck) GetType ¶
func (hc *MockHealthCheck) GetType() string
func (*MockHealthCheck) PerformCheck ¶
func (hc *MockHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
type MySQLHealthCheck ¶ added in v0.3.0
type MySQLHealthCheck struct {
Host string `yaml:"host"`
Port int `yaml:"port" default:"3306"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
Timeout string `yaml:"timeout" default:"3s"`
Query string `yaml:"query" default:"SELECT 1"`
}
MySQLHealthCheck represents MySQL-specific health check settings.
func (*MySQLHealthCheck) Equals ¶ added in v0.3.0
func (h *MySQLHealthCheck) Equals(other GenericHealthCheck) bool
func (*MySQLHealthCheck) GetType ¶ added in v0.3.0
func (h *MySQLHealthCheck) GetType() string
func (*MySQLHealthCheck) PerformCheck ¶ added in v0.3.0
func (h *MySQLHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
func (*MySQLHealthCheck) SetDefault ¶ added in v0.3.0
func (h *MySQLHealthCheck) SetDefault()
type Pinger ¶
type Pinger interface {
Run() error
Statistics() *probing.Statistics
SetPrivileged(privileged bool)
}
type RealPinger ¶
type RealPinger struct {
// contains filtered or unexported fields
}
func (*RealPinger) Run ¶
func (r *RealPinger) Run() error
func (*RealPinger) SetPrivileged ¶
func (r *RealPinger) SetPrivileged(privileged bool)
func (*RealPinger) Statistics ¶
func (r *RealPinger) Statistics() *probing.Statistics
type Record ¶
type Record struct {
Fqdn string
Zone string
Mode string
Backends []BackendInterface
Owner string
Description string
RecordTTL int
ScrapeInterval string
ScrapeRetries int
ScrapeTimeout string
FallbackPolicy FallbackPolicy
Discovery *DiscoveryConfig
ALPN []string
// contains filtered or unexported fields
}
Record represents a GSLB record in the YAML config.
func (*Record) GetScrapeInterval ¶
GetScrapeInterval returns the health check interval for HTTPHealthCheck
func (*Record) GetScrapeTimeout ¶
GetScrapeTimeout returns the health check timeout for HTTPHealthCheck
func (*Record) UnmarshalYAML ¶
func (*Record) UpdateRecord ¶ added in v0.8.0
func (r *Record) UpdateRecord()
type RedisHealthUpdate ¶ added in v0.22.0
type TCPHealthCheck ¶
type TCPHealthCheck struct {
Port int `yaml:"port" default:"80"` // TCP port to connect to
Timeout string `yaml:"timeout" default:"5s"` // Timeout for the TCP connection
}
TCPHealthCheck represents TCP-specific health check settings.
func (*TCPHealthCheck) Equals ¶
func (h *TCPHealthCheck) Equals(other GenericHealthCheck) bool
Equals compares two TCPHealthCheck objects for equality.
func (*TCPHealthCheck) GetType ¶
func (h *TCPHealthCheck) GetType() string
GetType returns the type of the health check as a string.
func (*TCPHealthCheck) PerformCheck ¶
func (h *TCPHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
PerformCheck implements the health check logic for TCP connections.
func (*TCPHealthCheck) SetDefault ¶
func (h *TCPHealthCheck) SetDefault()
SetDefault applies default values to TCPHealthCheck fields.