config

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Config constants.
	Default                   = "default"
	DefaultConfigurationBlock = "writes"
	EnvPrefix                 = "GATEWAYD_"
	TracerName                = "gatewayd"
	GlobalConfigFilename      = "gatewayd.yaml"
	PluginsConfigFilename     = "gatewayd_plugins.yaml"

	// Logger constants.
	DefaultLogOutput         = "console"
	DefaultLogFileName       = "gatewayd.log"
	DefaultLogLevel          = "info"
	DefaultNoColor           = false
	DefaultTimeFormat        = "unix"
	DefaultConsoleTimeFormat = "RFC3339"
	DefaultMaxSize           = 500 // megabytes
	DefaultMaxBackups        = 5
	DefaultMaxAge            = 30 // days
	DefaultCompress          = true
	DefaultLocalTime         = false
	DefaultSyslogTag         = "gatewayd"
	DefaultRSyslogNetwork    = "tcp"
	DefaultRSyslogAddress    = "localhost:514"
	DefaultSyslogPriority    = "info"

	// Plugin constants.
	DefaultMinPort                 = 50000
	DefaultMaxPort                 = 60000
	PluginPriorityStart            = uint(1000)
	DefaultPluginAddress           = "http://plugins/metrics"
	DefaultMetricsMergerPeriod     = 5 * time.Second
	DefaultPluginHealthCheckPeriod = 5 * time.Second
	DefaultPluginTimeout           = 30 * time.Second
	DefaultPluginStartTimeout      = 1 * time.Minute

	// Client constants.
	DefaultNetwork            = "tcp"
	DefaultAddress            = "localhost:5432"
	DefaultChunkSize          = 8192
	DefaultReceiveDeadline    = 0 // 0 means no deadline (timeout)
	DefaultSendDeadline       = 0
	DefaultTCPKeepAlivePeriod = 30 * time.Second
	DefaultTCPKeepAlive       = false
	DefaultReceiveTimeout     = 0
	DefaultDialTimeout        = 60 * time.Second
	DefaultRetries            = 3
	DefaultBackoff            = 1 * time.Second
	DefaultBackoffMultiplier  = 2.0
	DefaultDisableBackoffCaps = false

	// Pool constants.
	EmptyPoolCapacity        = 0
	DefaultPoolSize          = 10
	MinimumPoolSize          = 2
	DefaultHealthCheckPeriod = 60 * time.Second // This must match PostgreSQL authentication timeout.

	// Server constants.
	DefaultListenNetwork         = "tcp"
	DefaultListenAddress         = "0.0.0.0:15432"
	DefaultTickInterval          = 5 * time.Second
	DefaultHandshakeTimeout      = 5 * time.Second
	DefaultLoadBalancerStrategy  = "ROUND_ROBIN"
	DefaultLoadBalancerCondition = "DEFAULT"

	// Utility constants.
	DefaultSeed = 1000

	// Metrics constants.
	DefaultMetricsAddress       = "localhost:9090"
	DefaultMetricsPath          = "/metrics"
	DefaultReadHeaderTimeout    = 10 * time.Second
	DefaultMetricsServerTimeout = 10 * time.Second

	// Sentry constants.
	DefaultTraceSampleRate  = 0.2
	DefaultAttachStacktrace = true
	DefaultFlushTimeout     = 2 * time.Second

	// API constants.
	DefaultHTTPAPIAddress = "localhost:18080"
	DefaultGRPCAPINetwork = "tcp"
	DefaultGRPCAPIAddress = "localhost:19090"

	// Policies.
	DefaultCompatibilityPolicy = Strict

	// Act.
	DefaultPolicy             = "passthrough"
	DefaultPolicyTimeout      = 30 * time.Second
	DefaultActionTimeout      = 30 * time.Second
	DefaultActionRedisEnabled = false
	DefaultRedisAddress       = "localhost:6379"
	DefaultRedisChannel       = "gatewayd-actions"

	// Raft constants.
	DefaultRaftAddress     = "127.0.0.1:2223"
	DefaultRaftNodeID      = "node1"
	DefaultRaftIsBootstrap = true
	DefaultRaftDirectory   = "raft"
	DefaultRaftGRPCAddress = "127.0.0.1:50051"
)
View Source
const (
	RoundRobinStrategy         = "ROUND_ROBIN"
	RANDOMStrategy             = "RANDOM"
	WeightedRoundRobinStrategy = "WEIGHTED_ROUND_ROBIN"
)

Load balancing strategies.

View Source
const Name = "GatewayD"

Variables

View Source
var (
	CompatibilityPolicies = map[string]CompatibilityPolicy{
		"strict": Strict,
		"loose":  Loose,
	}

	TimeFormats = map[string]string{
		"":          zerolog.TimeFormatUnix,
		"unix":      zerolog.TimeFormatUnix,
		"unixms":    zerolog.TimeFormatUnixMs,
		"unixmicro": zerolog.TimeFormatUnixMicro,
		"unixnano":  zerolog.TimeFormatUnixNano,
	}
	ConsoleTimeFormats = map[string]string{
		"Layout":      time.Layout,
		"ANSIC":       time.ANSIC,
		"UnixDate":    time.UnixDate,
		"RubyDate":    time.RubyDate,
		"RFC822":      time.RFC822,
		"RFC822Z":     time.RFC822Z,
		"RFC850":      time.RFC850,
		"RFC1123":     time.RFC1123,
		"RFC1123Z":    time.RFC1123Z,
		"RFC3339":     time.RFC3339,
		"RFC3339Nano": time.RFC3339Nano,
		"Kitchen":     time.Kitchen,
		"Stamp":       time.Stamp,
		"StampMilli":  time.StampMilli,
		"StampMicro":  time.StampMicro,
		"StampNano":   time.StampNano,
	}
	LogLevels = map[string]zerolog.Level{
		"trace":    zerolog.TraceLevel,
		"debug":    zerolog.DebugLevel,
		"info":     zerolog.InfoLevel,
		"warn":     zerolog.WarnLevel,
		"error":    zerolog.ErrorLevel,
		"fatal":    zerolog.FatalLevel,
		"panic":    zerolog.PanicLevel,
		"disabled": zerolog.Disabled,
	}
)
View Source
var (
	// Version is the semantic version of GatewayD.
	Version = "0.0.0"
	// VersionDetails is the build timestamp and the tagged commit hash.
	VersionDetails = ""
)

Functions

func Exists added in v0.8.6

func Exists[T comparable, V any](map_ map[T]V, key T) bool

Exists returns true if key exists in map_, false otherwise.

func GetDefaultConfigFilePath added in v0.6.5

func GetDefaultConfigFilePath(filename string) string

GetDefaultConfigFilePath returns the path of the default config file.

func If added in v0.8.6

func If[T any](predicate bool, truthy, falsy T) T

If returns truthy if predicate is true, falsy otherwise.

func ValidateLoadBalancingRules added in v0.9.7

func ValidateLoadBalancingRules(
	serverConfig *Server,
	configGroup string,
	clientConfigGroups map[string]map[string]bool,
) []error

ValidateLoadBalancingRules validates the load balancing rules in the server configuration.

func VersionInfo added in v0.3.1

func VersionInfo() string

VersionInfo returns the full version and build information for the currently running GatewayD executable.

Types

type API added in v0.5.0

type API struct {
	Enabled     bool   `json:"enabled"`
	HTTPAddress string `json:"httpAddress"`
	GRPCAddress string `json:"grpcAddress"`
	GRPCNetwork string `json:"grpcNetwork" jsonschema:"enum=tcp,enum=udp,enum=unix"`
}

type ActionRedisConfig added in v0.9.6

type ActionRedisConfig struct {
	Enabled bool   `json:"enabled"`
	Address string `json:"address"`
	Channel string `json:"channel"`
}

type Client

type Client struct {
	BlockName string `json:"-"`
	GroupName string `json:"-"`

	Network            string        `json:"network" jsonschema:"enum=tcp,enum=udp,enum=unix" yaml:"network"`
	Address            string        `json:"address" yaml:"address"`
	TCPKeepAlive       bool          `json:"tcpKeepAlive" yaml:"tcpKeepAlive"`
	TCPKeepAlivePeriod time.Duration `json:"tcpKeepAlivePeriod" jsonschema:"oneof_type=string;integer" yaml:"tcpKeepAlivePeriod"`
	ReceiveChunkSize   int           `json:"receiveChunkSize" yaml:"receiveChunkSize"`
	ReceiveDeadline    time.Duration `json:"receiveDeadline" jsonschema:"oneof_type=string;integer" yaml:"receiveDeadline"`
	ReceiveTimeout     time.Duration `json:"receiveTimeout" jsonschema:"oneof_type=string;integer" yaml:"receiveTimeout"`
	SendDeadline       time.Duration `json:"sendDeadline" jsonschema:"oneof_type=string;integer" yaml:"sendDeadline"`
	DialTimeout        time.Duration `json:"dialTimeout" jsonschema:"oneof_type=string;integer" yaml:"dialTimeout"`
	Retries            int           `json:"retries" yaml:"retries"`
	Backoff            time.Duration `json:"backoff" jsonschema:"oneof_type=string;integer" yaml:"backoff"`
	BackoffMultiplier  float64       `json:"backoffMultiplier" yaml:"backoffMultiplier"`
	DisableBackoffCaps bool          `json:"disableBackoffCaps" yaml:"disableBackoffCaps"`
}

type CompatibilityPolicy added in v0.2.4

type CompatibilityPolicy string
const (
	Strict CompatibilityPolicy = "strict" // Expect all required plugins to be loaded and present
	Loose  CompatibilityPolicy = "loose"  // Load the plugin, even if the requirements are not met
)

CompatibilityPolicy is the compatibility policy for plugins.

type Config added in v0.3.1

type Config struct {
	GlobalConfigFile string
	PluginConfigFile string

	GlobalKoanf *koanf.Koanf
	PluginKoanf *koanf.Koanf

	Global GlobalConfig
	Plugin PluginConfig
	// contains filtered or unexported fields
}

func NewConfig added in v0.3.1

func NewConfig(ctx context.Context, config Config) *Config

func (*Config) ConvertKeysToLowercase added in v0.9.7

func (c *Config) ConvertKeysToLowercase(ctx context.Context) *gerr.GatewayDError

ConvertKeysToLowercase converts all keys in the global configuration to lowercase. It unmarshals the configuration data into a GlobalConfig struct, then recursively converts all map keys to lowercase.

Parameters:

  • ctx (context.Context): The context for tracing and cancellation, used for monitoring and propagating execution state.

Returns:

  • *gerr.GatewayDError: An error if unmarshalling fails, otherwise nil.

func (*Config) InitConfig added in v0.4.5

func (c *Config) InitConfig(ctx context.Context) *gerr.GatewayDError

func (*Config) LoadDefaults added in v0.3.1

func (c *Config) LoadDefaults(ctx context.Context) *gerr.GatewayDError

LoadDefaults loads the default configuration before loading the config files.

func (*Config) LoadGlobalConfigFile added in v0.3.1

func (c *Config) LoadGlobalConfigFile(ctx context.Context) *gerr.GatewayDError

LoadGlobalConfigFile loads the plugin configuration file.

func (*Config) LoadGlobalEnvVars added in v0.3.1

func (c *Config) LoadGlobalEnvVars(ctx context.Context) *gerr.GatewayDError

LoadGlobalEnvVars loads the environment variables into the global configuration with the given prefix, "GATEWAYD_".

func (*Config) LoadPluginConfigFile added in v0.3.1

func (c *Config) LoadPluginConfigFile(ctx context.Context) *gerr.GatewayDError

LoadPluginConfigFile loads the plugin configuration file.

func (*Config) LoadPluginEnvVars added in v0.3.1

func (c *Config) LoadPluginEnvVars(ctx context.Context) *gerr.GatewayDError

LoadPluginEnvVars loads the environment variables into the plugins configuration with the given prefix, "GATEWAYD_".

func (*Config) MergeGlobalConfig added in v0.3.1

func (c *Config) MergeGlobalConfig(
	ctx context.Context, updatedGlobalConfig map[string]any,
) *gerr.GatewayDError

func (*Config) UnmarshalGlobalConfig added in v0.3.1

func (c *Config) UnmarshalGlobalConfig(ctx context.Context) *gerr.GatewayDError

UnmarshalGlobalConfig unmarshals the global configuration for easier access.

func (*Config) UnmarshalPluginConfig added in v0.3.1

func (c *Config) UnmarshalPluginConfig(ctx context.Context) *gerr.GatewayDError

UnmarshalPluginConfig unmarshals the plugin configuration for easier access.

func (*Config) ValidateGlobalConfig added in v0.6.6

func (c *Config) ValidateGlobalConfig(ctx context.Context) *gerr.GatewayDError

type ConsistentHash added in v0.9.7

type ConsistentHash struct {
	UseSourceIP bool `json:"useSourceIp"`
}

type Distribution added in v0.9.7

type Distribution struct {
	ProxyName string `json:"proxyName"`
	Weight    int    `json:"weight"`
}

type GlobalConfig

type GlobalConfig struct {
	API     API                           `json:"api"`
	Loggers map[string]*Logger            `json:"loggers"`
	Clients map[string]map[string]*Client `json:"clients"`
	Pools   map[string]map[string]*Pool   `json:"pools"`
	Proxies map[string]map[string]*Proxy  `json:"proxies"`
	Servers map[string]*Server            `json:"servers"`
	Metrics map[string]*Metrics           `json:"metrics"`
	Raft    Raft                          `json:"raft"`
}

func (GlobalConfig) Filter added in v0.8.6

func (gc GlobalConfig) Filter(groupName string) *GlobalConfig

Filter returns a filtered global config based on the group name.

type IConfig added in v0.3.1

type IConfig interface {
	InitConfig(ctx context.Context) *gerr.GatewayDError
	LoadDefaults(ctx context.Context) *gerr.GatewayDError
	LoadPluginEnvVars(ctx context.Context) *gerr.GatewayDError
	LoadGlobalEnvVars(ctx context.Context) *gerr.GatewayDError
	LoadGlobalConfigFile(ctx context.Context) *gerr.GatewayDError
	LoadPluginConfigFile(ctx context.Context) *gerr.GatewayDError
	MergeGlobalConfig(
		ctx context.Context, updatedGlobalConfig map[string]any) *gerr.GatewayDError
}

type LoadBalancer added in v0.9.7

type LoadBalancer struct {
	Strategy           string              `json:"strategy"`
	LoadBalancingRules []LoadBalancingRule `json:"loadBalancingRules"`
	ConsistentHash     *ConsistentHash     `json:"consistentHash,omitempty"`
}

type LoadBalancingRule added in v0.9.7

type LoadBalancingRule struct {
	Condition    string         `json:"condition"`
	Distribution []Distribution `json:"distribution"`
}

type LogOutput

type LogOutput uint
const (
	Console LogOutput = iota
	Stdout
	Stderr
	File
	Syslog
	RSyslog
)

LogOutput is the output type for the logger.

type Logger

type Logger struct {
	Output            []string `json:"output"`
	TimeFormat        string   `json:"timeFormat" jsonschema:"enum=unix,enum=unixms,enum=unixmicro,enum=unixnano"`
	Level             string   `json:"level" jsonschema:"enum=trace,enum=debug,enum=info,enum=warn,enum=error,enum=fatal,enum=panic,enum=disabled"`
	ConsoleTimeFormat string   `` /* 253-byte string literal not displayed */
	NoColor           bool     `json:"noColor"`

	FileName   string `json:"fileName"`
	MaxSize    int    `json:"maxSize"`
	MaxBackups int    `json:"maxBackups"`
	MaxAge     int    `json:"maxAge"`
	Compress   bool   `json:"compress"`
	LocalTime  bool   `json:"localTime"`

	RSyslogNetwork string `json:"rsyslogNetwork" jsonschema:"enum=tcp,enum=udp,enum=unix"`
	RSyslogAddress string `json:"rsyslogAddress"`
	SyslogPriority string `json:"syslogPriority" jsonschema:"enum=debug,enum=info,enum=notice,enum=warning,enum=err,enum=crit,enum=alert,enum=emerg"`
}

func (Logger) GetOutput

func (l Logger) GetOutput() []LogOutput

GetOutput returns the logger output from config file.

func (Logger) GetSyslogPriority added in v0.3.2

func (l Logger) GetSyslogPriority() syslog.Priority

GetSyslogPriority returns the rsyslog facility from config file.

type Metrics added in v0.3.0

type Metrics struct {
	Enabled           bool          `json:"enabled"`
	Address           string        `json:"address"`
	Path              string        `json:"path"`
	ReadHeaderTimeout time.Duration `json:"readHeaderTimeout" jsonschema:"oneof_type=string;integer"`
	Timeout           time.Duration `json:"timeout" jsonschema:"oneof_type=string;integer"`
	CertFile          string        `json:"certFile"`
	KeyFile           string        `json:"keyFile"`
}

type Plugin

type Plugin struct {
	Name      string   `json:"name" jsonschema:"required"`
	Enabled   bool     `json:"enabled"`
	LocalPath string   `json:"localPath" jsonschema:"required"`
	Args      []string `json:"args"`
	Env       []string `json:"env" jsonschema:"required"`
	Checksum  string   `json:"checksum" jsonschema:"required"`
	URL       string   `json:"url"`
}

type PluginConfig

type PluginConfig struct {
	CompatibilityPolicy string            `json:"compatibilityPolicy" jsonschema:"enum=strict,enum=loose"`
	EnableMetricsMerger bool              `json:"enableMetricsMerger"`
	MetricsMergerPeriod time.Duration     `json:"metricsMergerPeriod" jsonschema:"oneof_type=string;integer"`
	HealthCheckPeriod   time.Duration     `json:"healthCheckPeriod" jsonschema:"oneof_type=string;integer"`
	ReloadOnCrash       bool              `json:"reloadOnCrash"`
	Timeout             time.Duration     `json:"timeout" jsonschema:"oneof_type=string;integer"`
	StartTimeout        time.Duration     `json:"startTimeout" jsonschema:"oneof_type=string;integer"`
	Plugins             []Plugin          `json:"plugins"`
	DefaultPolicy       string            `json:"defaultPolicy" jsonschema:"enum=passthrough,enum=terminate"` // TODO: Add more policies.
	PolicyTimeout       time.Duration     `json:"policyTimeout" jsonschema:"oneof_type=string;integer"`
	ActionTimeout       time.Duration     `json:"actionTimeout" jsonschema:"oneof_type=string;integer"`
	ActionRedis         ActionRedisConfig `json:"actionRedis"`
	Policies            []Policy          `json:"policies"`
}

func (PluginConfig) GetPlugins added in v0.5.2

func (p PluginConfig) GetPlugins(name ...string) []Plugin

GetPlugins returns the plugins from config file.

type Policy

type Policy struct {
	Name     string         `json:"name" jsonschema:"required"`
	Policy   string         `json:"policy" jsonschema:"required"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

type Pool

type Pool struct {
	Size int `json:"size" yaml:"size"`
}

type Proxy

type Proxy struct {
	HealthCheckPeriod time.Duration `json:"healthCheckPeriod" jsonschema:"oneof_type=string;integer" yaml:"healthCheckPeriod"`
}

type Raft added in v0.10.1

type Raft struct {
	Address     string     `json:"address"`
	NodeID      string     `json:"nodeId"`
	IsBootstrap bool       `json:"isBootstrap"`
	Peers       []RaftPeer `json:"peers"`
	Directory   string     `json:"directory" jsonschema:"default=raft"`
	GRPCAddress string     `json:"grpcAddress"`
}

type RaftPeer added in v0.10.1

type RaftPeer struct {
	ID          string `json:"id"`
	Address     string `json:"address"`
	GRPCAddress string `json:"grpcAddress"`
}

type Server

type Server struct {
	EnableTicker     bool          `json:"enableTicker"`
	TickInterval     time.Duration `json:"tickInterval" jsonschema:"oneof_type=string;integer"`
	Network          string        `json:"network" jsonschema:"enum=tcp,enum=udp,enum=unix"`
	Address          string        `json:"address"`
	EnableTLS        bool          `json:"enableTLS"` //nolint:tagliatelle
	CertFile         string        `json:"certFile"`
	KeyFile          string        `json:"keyFile"`
	HandshakeTimeout time.Duration `json:"handshakeTimeout" jsonschema:"oneof_type=string;integer"`
	LoadBalancer     LoadBalancer  `json:"loadBalancer"`
}

type Status

type Status uint
const (
	Running Status = iota
	Stopped
)

Status is the status of the server.

Jump to

Keyboard shortcuts

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