config

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Config constants.
	Default               = "default"
	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            = 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

	// 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
)
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 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 Client

type Client struct {
	Network            string        `json:"network" jsonschema:"enum=tcp,enum=udp,enum=unix"`
	Address            string        `json:"address"`
	TCPKeepAlive       bool          `json:"tcpKeepAlive"`
	TCPKeepAlivePeriod time.Duration `json:"tcpKeepAlivePeriod" jsonschema:"oneof_type=string;integer"`
	ReceiveChunkSize   int           `json:"receiveChunkSize"`
	ReceiveDeadline    time.Duration `json:"receiveDeadline" jsonschema:"oneof_type=string;integer"`
	ReceiveTimeout     time.Duration `json:"receiveTimeout" jsonschema:"oneof_type=string;integer"`
	SendDeadline       time.Duration `json:"sendDeadline" jsonschema:"oneof_type=string;integer"`
	DialTimeout        time.Duration `json:"dialTimeout" jsonschema:"oneof_type=string;integer"`
	Retries            int           `json:"retries"`
	Backoff            time.Duration `json:"backoff" jsonschema:"oneof_type=string;integer"`
	BackoffMultiplier  float64       `json:"backoffMultiplier"`
	DisableBackoffCaps bool          `json:"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) InitConfig added in v0.4.5

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

func (*Config) LoadDefaults added in v0.3.1

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

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)

LoadGlobalConfigFile loads the plugin configuration file.

func (*Config) LoadGlobalEnvVars added in v0.3.1

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

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)

LoadPluginConfigFile loads the plugin configuration file.

func (*Config) LoadPluginEnvVars added in v0.3.1

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

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]interface{},
)

func (*Config) UnmarshalGlobalConfig added in v0.3.1

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

UnmarshalGlobalConfig unmarshals the global configuration for easier access.

func (*Config) UnmarshalPluginConfig added in v0.3.1

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

UnmarshalPluginConfig unmarshals the plugin configuration for easier access.

func (*Config) ValidateGlobalConfig added in v0.6.6

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

type GlobalConfig

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

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)
	LoadDefaults(ctx context.Context)
	LoadPluginEnvVars(ctx context.Context)
	LoadGlobalEnvVars(ctx context.Context)
	LoadGlobalConfigFile(ctx context.Context)
	LoadPluginConfigFile(ctx context.Context)
	MergeGlobalConfig(ctx context.Context, updatedGlobalConfig map[string]interface{})
}

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"`
	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"`
}

type Proxy

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

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"`
}

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