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) GetASN() string
- func (b *Backend) GetAddress() string
- func (b *Backend) GetCity() string
- func (b *Backend) GetContinent() string
- func (b *Backend) GetCountry() string
- func (b *Backend) GetDescription() string
- func (b *Backend) GetFqdn() string
- func (b *Backend) GetHealthChecks() []GenericHealthCheck
- 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) GetPriority() 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) IsEnabled() bool
- func (b *Backend) IsHealthy() bool
- func (b *Backend) Lock()
- func (b *Backend) SetFqdn(fqdn string)
- func (b *Backend) Unlock()
- func (b *Backend) UnmarshalYAML(unmarshal func(interface{}) error) error
- type BackendInterface
- type ClientInfo
- type GRPCHealthCheck
- type GSLB
- func (g *GSLB) GetMaxStaggerStart() time.Duration
- func (g *GSLB) GetResolutionIdleTimeout() time.Duration
- func (g *GSLB) Name() string
- func (g *GSLB) RegisterAPIHandlers(mux *http.ServeMux)
- func (g *GSLB) ServeAPI()
- func (g *GSLB) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)
- 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 TCPHealthCheck
Constants ¶
const ICMPType = "icmp"
Variables ¶
var GlobalHealthcheckProfiles map[string]*HealthCheck
Global map for global healthcheck profiles loaded from Corefile
var Version = "dev"
Version of the GSLB plugin, set at build time
Functions ¶
func IncBackendSelected ¶
func IncBackendSelected(name, address string)
func IncConfigReloads ¶
func IncConfigReloads(result string)
func IncHealthcheckFailures ¶
func IncHealthcheckFailures(typ, address, reason string)
func IncHealthcheckTotal ¶
func IncHealthcheckTotal(name, typ, address, result string)
func IncRecordResolutions ¶
func IncRecordResolutions(name, result string)
func NewHTTPSTransport ¶
NewHTTPSTransport returns an HTTP transport configured using tls.Config
func NewTLSClientConfig ¶
NewTLSConfig returns a TLS config that includes a certificate and key pair If caPath is empty, system CAs will be used If certPath or keyPath are empty, client certificate will not be loaded
func ObserveHealthcheck ¶
func RegisterMetrics ¶
func RegisterMetrics()
func SetActiveBackends ¶
func SetBackendHealthStatus ¶
func SetBackendsTotal ¶
func SetBackendsTotal(value float64)
func SetHealthchecksTotal ¶
func SetHealthchecksTotal(value float64)
func SetRecordHealthStatus ¶
func SetRecordsTotal ¶
func SetRecordsTotal(value float64)
func SetVersionInfo ¶
func SetVersionInfo(version string)
func SetZonesTotal ¶
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
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
// contains filtered or unexported fields
}
Backend represents an individual backend with health check settings.
func (*Backend) GetAddress ¶
func (*Backend) GetContinent ¶
func (*Backend) GetCountry ¶
func (*Backend) GetDescription ¶
func (*Backend) GetHealthChecks ¶
func (b *Backend) GetHealthChecks() []GenericHealthCheck
func (*Backend) GetLatitude ¶
func (*Backend) GetLatitudeRad ¶
func (*Backend) GetLocation ¶
func (*Backend) GetLongitude ¶
func (*Backend) GetLongitudeRad ¶
func (*Backend) GetPriority ¶
func (*Backend) GetSubdivision ¶
func (*Backend) GetTimeout ¶
func (*Backend) HasGeoCoordinates ¶
func (*Backend) UnmarshalYAML ¶
type BackendInterface ¶
type BackendInterface interface {
GetFqdn() string
SetFqdn(fqdn string)
GetDescription() string
GetAddress() string
GetPriority() int
GetWeight() int
IsEnabled() bool
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
Lock()
Unlock()
// contains filtered or unexported methods
}
type ClientInfo ¶
func GetClientInfo ¶
func GetClientInfo(ctx context.Context) *ClientInfo
type GRPCHealthCheck ¶
func (*GRPCHealthCheck) Check ¶
func (h *GRPCHealthCheck) Check() error
func (*GRPCHealthCheck) Equals ¶
func (h *GRPCHealthCheck) Equals(other GenericHealthCheck) bool
func (*GRPCHealthCheck) GetType ¶
func (h *GRPCHealthCheck) GetType() string
func (*GRPCHealthCheck) PerformCheck ¶
func (h *GRPCHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
func (*GRPCHealthCheck) SetDefault ¶
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
UseEDNSCSubnet bool
LocationMap map[string]string
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
}
func (*GSLB) GetMaxStaggerStart ¶
func (*GSLB) GetResolutionIdleTimeout ¶
func (*GSLB) RegisterAPIHandlers ¶
RegisterAPIHandlers registers all API endpoints to the provided mux.
func (*GSLB) UnmarshalYAML ¶
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 ¶
func ResolveHealthcheckProfile ¶
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 ¶
func (*LuaHealthCheck) Equals ¶
func (l *LuaHealthCheck) Equals(other GenericHealthCheck) bool
func (*LuaHealthCheck) GetType ¶
func (l *LuaHealthCheck) GetType() string
func (*LuaHealthCheck) PerformCheck ¶
func (l *LuaHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
func (*LuaHealthCheck) SetDefault ¶
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 ¶
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 ¶
func (h *MySQLHealthCheck) Equals(other GenericHealthCheck) bool
func (*MySQLHealthCheck) GetType ¶
func (h *MySQLHealthCheck) GetType() string
func (*MySQLHealthCheck) PerformCheck ¶
func (h *MySQLHealthCheck) PerformCheck(backend *Backend, fqdn string, maxRetries int) bool
func (*MySQLHealthCheck) SetDefault ¶
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
Mode string
Backends []BackendInterface
Owner string
Description string
RecordTTL int
ScrapeInterval string
ScrapeRetries int
ScrapeTimeout 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 ¶
func (r *Record) UpdateRecord()
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.