config

package
v0.0.0-...-14d5243 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BalancePolicyResource   = "resource"
	BalancePolicyLocation   = "location"
	BalancePolicyConnection = "connection"

	RoutingPolicyPreferIdle = "prefer-idle"
	RoutingPolicyRandom     = "random"
	RoutingPolicyIdlest     = "idlest"

	// MatchClientCIDRStr is used for MatchClientCIDR.
	MatchClientCIDRStr = "client_cidr"
	// MatchProxyCIDRStr is used for MatchProxyCIDR.
	MatchProxyCIDRStr = "proxy_cidr"
)
View Source
const (
	// LocationLabelName indicates the label name that decides the location of TiProxy and backends.
	// We use `zone` because the follower read in TiDB also uses `zone` to decide location.
	LocationLabelName = "zone"
	KeyspaceLabelName = "keyspace"
	CidrLabelName     = "cidr"
)

Variables

View Source
var (
	ErrUnsupportedProxyProtocolVersion = errors.New("unsupported proxy protocol version")
	ErrInvalidConfigValue              = errors.New("invalid config value")
)

Functions

func ConfigInfo

func ConfigInfo(format string) (string, error)

ConfigInfo outputs the config info used for loading to the operation system.

Types

type API

type API struct {
	Addr          string `yaml:"addr,omitempty" toml:"addr,omitempty" json:"addr,omitempty" reloadable:"false"`
	ProxyProtocol string `yaml:"proxy-protocol,omitempty" toml:"proxy-protocol,omitempty" json:"proxy-protocol,omitempty" reloadable:"false"`
}

type BackendNamespace

type BackendNamespace struct {
	Instances []string  `yaml:"instances" json:"instances" toml:"instances"`
	Security  TLSConfig `yaml:"security" json:"security" toml:"security"`
}

type Balance

type Balance struct {
	LabelName     string          `yaml:"label-name,omitempty" toml:"label-name,omitempty" json:"label-name,omitempty" reloadable:"true"`
	RoutingRule   string          `yaml:"routing-rule,omitempty" toml:"routing-rule,omitempty" json:"routing-rule,omitempty" reloadable:"false"`
	Policy        string          `yaml:"policy,omitempty" toml:"policy,omitempty" json:"policy,omitempty" reloadable:"true"`
	RoutingPolicy string          `yaml:"routing-policy,omitempty" toml:"routing-policy,omitempty" json:"routing-policy,omitempty" reloadable:"true"`
	Status        Factor          `yaml:"status,omitempty" toml:"status,omitempty" json:"status,omitempty" reloadable:"true"`
	Health        Factor          `yaml:"health,omitempty" toml:"health,omitempty" json:"health,omitempty" reloadable:"true"`
	Memory        Factor          `yaml:"memory,omitempty" toml:"memory,omitempty" json:"memory,omitempty" reloadable:"true"`
	CPU           Factor          `yaml:"cpu,omitempty" toml:"cpu,omitempty" json:"cpu,omitempty" reloadable:"true"`
	Location      Factor          `yaml:"location,omitempty" toml:"location,omitempty" json:"location,omitempty" reloadable:"true"`
	ConnCount     ConnCountFactor `yaml:"conn-count,omitempty" toml:"conn-count,omitempty" json:"conn-count,omitempty" reloadable:"true"`
}

func DefaultBalance

func DefaultBalance() Balance

func (*Balance) Check

func (b *Balance) Check() error

type Config

type Config struct {
	Proxy               ProxyServer           `yaml:"proxy,omitempty" toml:"proxy,omitempty" json:"proxy,omitempty"`
	API                 API                   `yaml:"api,omitempty" toml:"api,omitempty" json:"api,omitempty"`
	Workdir             string                `yaml:"workdir,omitempty" toml:"workdir,omitempty" json:"workdir,omitempty" reloadable:"false"`
	Security            Security              `yaml:"security,omitempty" toml:"security,omitempty" json:"security,omitempty"`
	Log                 Log                   `yaml:"log,omitempty" toml:"log,omitempty" json:"log,omitempty"`
	Balance             Balance               `yaml:"balance,omitempty" toml:"balance,omitempty" json:"balance,omitempty"`
	Labels              map[string]string     `yaml:"labels,omitempty" toml:"labels,omitempty" json:"labels,omitempty" reloadable:"true"`
	HA                  HA                    `yaml:"ha,omitempty" toml:"ha,omitempty" json:"ha,omitempty"`
	Metering            config.MeteringConfig `yaml:"metering,omitempty" toml:"metering,omitempty" json:"metering,omitempty" reloadable:"false"`
	EnableTrafficReplay bool                  `` /* 134-byte string literal not displayed */
}

func NewConfig

func NewConfig() *Config

func (*Config) Check

func (cfg *Config) Check() error

func (*Config) Clone

func (cfg *Config) Clone() *Config

func (*Config) GetIPPort

func (cfg *Config) GetIPPort() (ip, port, statusPort string, err error)

func (*Config) GetLocation

func (cfg *Config) GetLocation() string

func (*Config) ToBytes

func (cfg *Config) ToBytes() ([]byte, error)

type ConfigGetter

type ConfigGetter interface {
	GetConfig() *Config
}

type ConnCountFactor

type ConnCountFactor struct {
	Factor              `yaml:",inline" toml:",inline" json:",inline"`
	CountRatioThreshold float64 `` /* 134-byte string literal not displayed */
}

type Factor

type Factor struct {
	MigrationsPerSecond float64 `` /* 134-byte string literal not displayed */
}

type FrontendNamespace

type FrontendNamespace struct {
	User     string    `yaml:"user" json:"user" toml:"user"`
	Security TLSConfig `yaml:"security" json:"security" toml:"security"`
}

type HA

type HA struct {
	VirtualIP string `yaml:"virtual-ip,omitempty" toml:"virtual-ip,omitempty" json:"virtual-ip,omitempty" reloadable:"false"`
	Interface string `yaml:"interface,omitempty" toml:"interface,omitempty" json:"interface,omitempty" reloadable:"false"`
}

type HealthCheck

type HealthCheck struct {
	Enable          bool          `yaml:"enable" json:"enable" toml:"enable" reloadable:"false"`
	Interval        time.Duration `yaml:"interval" json:"interval" toml:"interval" reloadable:"false"`
	MaxRetries      int           `yaml:"max-retries" json:"max-retries" toml:"max-retries" reloadable:"false"`
	RetryInterval   time.Duration `yaml:"retry-interval" json:"retry-interval" toml:"retry-interval" reloadable:"false"`
	DialTimeout     time.Duration `yaml:"dial-timeout" json:"dial-timeout" toml:"dial-timeout" reloadable:"false"`
	MetricsInterval time.Duration `yaml:"metrics-interval" json:"metrics-interval" toml:"metrics-interval" reloadable:"false"`
	MetricsTimeout  time.Duration `yaml:"metrics-timeout" json:"metrics-timeout" toml:"metrics-timeout" reloadable:"false"`
}

HealthCheck contains some configurations for health check. Some general configurations of them may be exposed to users in the future. We can use shorter durations to speed up unit tests.

func NewDefaultHealthCheckConfig

func NewDefaultHealthCheckConfig() *HealthCheck

NewDefaultHealthCheckConfig creates a default HealthCheck.

func (*HealthCheck) Check

func (hc *HealthCheck) Check()

type HealthInfo

type HealthInfo struct {
	ConfigChecksum uint32 `json:"config_checksum"`
}

type KeepAlive

type KeepAlive struct {
	Enabled bool `yaml:"enabled,omitempty" toml:"enabled,omitempty" json:"enabled,omitempty" reloadable:"true"`
	// Idle, Cnt, and Intvl works only when the connection is idle. User packets will interrupt keep-alive.
	// If the peer crashes and doesn't send any packets, the connection will be closed within Idle+Cnt*Intvl.
	Idle  time.Duration `yaml:"idle,omitempty" toml:"idle,omitempty" json:"idle,omitempty" reloadable:"true"`
	Cnt   int           `yaml:"cnt,omitempty" toml:"cnt,omitempty" json:"cnt,omitempty" reloadable:"true"`
	Intvl time.Duration `yaml:"intvl,omitempty" toml:"intvl,omitempty" json:"intvl,omitempty" reloadable:"true"`
	// Timeout is the timeout of waiting ACK. It works for both user packets and keep-alive.
	// It is suggested to be equal or close to Cnt*Intvl.
	Timeout time.Duration `yaml:"timeout,omitempty" toml:"timeout,omitempty" json:"timeout,omitempty" reloadable:"true"`
}

func DefaultKeepAlive

func DefaultKeepAlive() (frontend, backendHealthy, backendUnhealthy KeepAlive)

type Log

type Log struct {
	Encoder   string `yaml:"encoder,omitempty" toml:"encoder,omitempty" json:"encoder,omitempty" reloadable:"false"`
	Simple    bool   `yaml:"simple,omitempty" toml:"simple,omitempty" json:"simple,omitempty" reloadable:"false"`
	LogOnline `yaml:",inline" toml:",inline" json:",inline"`
}

type LogFile

type LogFile struct {
	Filename   string `yaml:"filename,omitempty" toml:"filename,omitempty" json:"filename,omitempty" reloadable:"true"`
	MaxSize    int    `yaml:"max-size,omitempty" toml:"max-size,omitempty" json:"max-size,omitempty" reloadable:"true"`
	MaxDays    int    `yaml:"max-days,omitempty" toml:"max-days,omitempty" json:"max-days,omitempty" reloadable:"true"`
	MaxBackups int    `yaml:"max-backups,omitempty" toml:"max-backups,omitempty" json:"max-backups,omitempty" reloadable:"true"`
}

type LogOnline

type LogOnline struct {
	Level   string  `yaml:"level,omitempty" toml:"level,omitempty" json:"level,omitempty" reloadable:"true"`
	LogFile LogFile `yaml:"log-file,omitempty" toml:"log-file,omitempty" json:"log-file,omitempty"`
}

type Namespace

type Namespace struct {
	Namespace string            `yaml:"namespace" json:"namespace" toml:"namespace"`
	Frontend  FrontendNamespace `yaml:"frontend" json:"frontend" toml:"frontend"`
	Backend   BackendNamespace  `yaml:"backend" json:"backend" toml:"backend"`
}

func NewNamespace

func NewNamespace(data []byte) (*Namespace, error)

func (*Namespace) ToBytes

func (cfg *Namespace) ToBytes() ([]byte, error)

type ProxyServer

type ProxyServer struct {
	Addr              string `yaml:"addr,omitempty" toml:"addr,omitempty" json:"addr,omitempty" reloadable:"false"`
	AdvertiseAddr     string `yaml:"advertise-addr,omitempty" toml:"advertise-addr,omitempty" json:"advertise-addr,omitempty" reloadable:"false"`
	PDAddrs           string `yaml:"pd-addrs,omitempty" toml:"pd-addrs,omitempty" json:"pd-addrs,omitempty" reloadable:"false"`
	ProxyServerOnline `yaml:",inline" toml:",inline" json:",inline"`
}

type ProxyServerOnline

type ProxyServerOnline struct {
	MaxConnections    uint64    `yaml:"max-connections,omitempty" toml:"max-connections,omitempty" json:"max-connections,omitempty" reloadable:"true"`
	ConnBufferSize    int       `yaml:"conn-buffer-size,omitempty" toml:"conn-buffer-size,omitempty" json:"conn-buffer-size,omitempty" reloadable:"true"`
	FrontendKeepalive KeepAlive `yaml:"frontend-keepalive" toml:"frontend-keepalive" json:"frontend-keepalive"`
	// BackendHealthyKeepalive applies when the observer treats the backend as healthy.
	// The config values should be conservative to save CPU and tolerate network fluctuation.
	BackendHealthyKeepalive KeepAlive `yaml:"backend-healthy-keepalive" toml:"backend-healthy-keepalive" json:"backend-healthy-keepalive"`
	// BackendUnhealthyKeepalive applies when the observer treats the backend as unhealthy.
	// The config values can be aggressive because the backend may stop anytime.
	BackendUnhealthyKeepalive KeepAlive `yaml:"backend-unhealthy-keepalive" toml:"backend-unhealthy-keepalive" json:"backend-unhealthy-keepalive"`
	ProxyProtocol             string    `yaml:"proxy-protocol,omitempty" toml:"proxy-protocol,omitempty" json:"proxy-protocol,omitempty" reloadable:"true"`
	// In k8s, the pod terminationGracePeriodSeconds can be set to very long so that these configs can be updated online.
	GracefulWaitBeforeShutdown int `` /* 158-byte string literal not displayed */
	GracefulCloseConnTimeout   int `` /* 152-byte string literal not displayed */
	// Public and private traffic are metered separately.
	PublicEndpoints []string `yaml:"public-endpoints,omitempty" toml:"public-endpoints,omitempty" json:"public-endpoints,omitempty" reloadable:"true"`
}

type Security

type Security struct {
	ServerSQLTLS      TLSConfig `yaml:"server-tls,omitempty" toml:"server-tls,omitempty" json:"server-tls,omitempty"`
	ServerHTTPTLS     TLSConfig `yaml:"server-http-tls,omitempty" toml:"server-http-tls,omitempty" json:"server-http-tls,omitempty"`
	ClusterTLS        TLSConfig `yaml:"cluster-tls,omitempty" toml:"cluster-tls,omitempty" json:"cluster-tls,omitempty"`
	SQLTLS            TLSConfig `yaml:"sql-tls,omitempty" toml:"sql-tls,omitempty" json:"sql-tls,omitempty"`
	EncryptionKeyPath string    `` /* 128-byte string literal not displayed */
	RequireBackendTLS bool      `` /* 128-byte string literal not displayed */
}

type TLSConfig

type TLSConfig struct {
	Cert               string   `yaml:"cert,omitempty" toml:"cert,omitempty" json:"cert,omitempty" reloadable:"true"`
	Key                string   `yaml:"key,omitempty" toml:"key,omitempty" json:"key,omitempty" reloadable:"true"`
	CA                 string   `yaml:"ca,omitempty" toml:"ca,omitempty" json:"ca,omitempty" reloadable:"true"`
	MinTLSVersion      string   `yaml:"min-tls-version,omitempty" toml:"min-tls-version,omitempty" json:"min-tls-version,omitempty" reloadable:"true"`
	CertAllowedCN      []string `yaml:"cert-allowed-cn,omitempty" toml:"cert-allowed-cn,omitempty" json:"cert-allowed-cn,omitempty" reloadable:"true"`
	AutoCerts          bool     `yaml:"auto-certs,omitempty" toml:"auto-certs,omitempty" json:"auto-certs,omitempty" reloadable:"true"`
	RSAKeySize         int      `yaml:"rsa-key-size,omitempty" toml:"rsa-key-size,omitempty" json:"rsa-key-size,omitempty" reloadable:"true"`
	AutoExpireDuration string   `` /* 143-byte string literal not displayed */
	SkipCA             bool     `yaml:"skip-ca,omitempty" toml:"skip-ca,omitempty" json:"skip-ca,omitempty" reloadable:"true"`
}

func (TLSConfig) HasCA

func (c TLSConfig) HasCA() bool

func (TLSConfig) HasCert

func (c TLSConfig) HasCert() bool

Jump to

Keyboard shortcuts

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