Skip to content

Commit

Permalink
Make all config structs suitable for config.FromEnv()
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Jul 17, 2024
1 parent f46692a commit 19eeb8c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
10 changes: 5 additions & 5 deletions config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

// TLS provides TLS configuration options.
type TLS struct {
Enable bool `yaml:"tls"`
Cert string `yaml:"cert"`
Key string `yaml:"key"`
Ca string `yaml:"ca"`
Insecure bool `yaml:"insecure"`
Enable bool `yaml:"tls" env:"TLS"`
Cert string `yaml:"cert" env:"CERT"`
Key string `yaml:"key" env:"KEY"`
Ca string `yaml:"ca" env:"CA"`
Insecure bool `yaml:"insecure" env:"INSECURE"`
}

// MakeConfig assembles a tls.Config from t and serverName.
Expand Down
14 changes: 7 additions & 7 deletions database/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (

// Config defines database client configuration.
type Config struct {
Type string `yaml:"type" default:"mysql"`
Host string `yaml:"host"`
Port int `yaml:"port"`
Database string `yaml:"database"`
User string `yaml:"user"`
Password string `yaml:"password"`
Type string `yaml:"type" env:"TYPE" default:"mysql"`
Host string `yaml:"host" env:"HOST"`
Port int `yaml:"port" env:"PORT"`
Database string `yaml:"database" env:"DATABASE"`
User string `yaml:"user" env:"USER"`
Password string `yaml:"password" env:"PASSWORD,unset"`
TlsOptions config.TLS `yaml:",inline"`
Options Options `yaml:"options"`
Options Options `yaml:"options" envPrefix:"OPTIONS_"`
}

// Validate checks constraints in the supplied database configuration and returns an error if they are violated.
Expand Down
10 changes: 5 additions & 5 deletions database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ type DB struct {
// Options define user configurable database options.
type Options struct {
// Maximum number of open connections to the database.
MaxConnections int `yaml:"max_connections" default:"16"`
MaxConnections int `yaml:"max_connections" env:"MAX_CONNECTIONS" default:"16"`

// Maximum number of connections per table,
// regardless of what the connection is actually doing,
// e.g. INSERT, UPDATE, DELETE.
MaxConnectionsPerTable int `yaml:"max_connections_per_table" default:"8"`
MaxConnectionsPerTable int `yaml:"max_connections_per_table" env:"MAX_CONNECTIONS_PER_TABLE" default:"8"`

// MaxPlaceholdersPerStatement defines the maximum number of placeholders in an
// INSERT, UPDATE or DELETE statement. Theoretically, MySQL can handle up to 2^16-1 placeholders,
// but this increases the execution time of queries and thus reduces the number of queries
// that can be executed in parallel in a given time.
// The default is 2^13, which in our tests showed the best performance in terms of execution time and parallelism.
MaxPlaceholdersPerStatement int `yaml:"max_placeholders_per_statement" default:"8192"`
MaxPlaceholdersPerStatement int `yaml:"max_placeholders_per_statement" env:"MAX_PLACEHOLDERS_PER_STATEMENT" default:"8192"`

// MaxRowsPerTransaction defines the maximum number of rows per transaction.
// The default is 2^13, which in our tests showed the best performance in terms of execution time and parallelism.
MaxRowsPerTransaction int `yaml:"max_rows_per_transaction" default:"8192"`
MaxRowsPerTransaction int `yaml:"max_rows_per_transaction" env:"MAX_ROWS_PER_TRANSACTION" default:"8192"`

// WsrepSyncWait enforces Galera cluster nodes to perform strict cluster-wide causality checks
// before executing specific SQL queries determined by the number you provided.
// Please refer to the below link for a detailed description.
// https://icinga.com/docs/icinga-db/latest/doc/03-Configuration/#galera-cluster
WsrepSyncWait int `yaml:"wsrep_sync_wait" default:"7"`
WsrepSyncWait int `yaml:"wsrep_sync_wait" env:"WSREP_SYNC_WAIT" default:"7"`
}

// Validate checks constraints in the supplied database options and returns an error if they are violated.
Expand Down
8 changes: 4 additions & 4 deletions logging/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type Options map[string]zapcore.Level
// Config defines Logger configuration.
type Config struct {
// zapcore.Level at 0 is for info level.
Level zapcore.Level `yaml:"level" default:"0"`
Output string `yaml:"output"`
Level zapcore.Level `yaml:"level" env:"LEVEL" default:"0"`
Output string `yaml:"output" env:"OUTPUT"`
// Interval for periodic logging.
Interval time.Duration `yaml:"interval" default:"20s"`
Interval time.Duration `yaml:"interval" env:"INTERVAL" default:"20s"`

Options `yaml:"options"`
Options `yaml:"options" env:"OPTIONS"`
}

// Validate checks constraints in the configuration and returns an error if they are violated.
Expand Down
20 changes: 10 additions & 10 deletions redis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

// Options define user configurable Redis options.
type Options struct {
BlockTimeout time.Duration `yaml:"block_timeout" default:"1s"`
HMGetCount int `yaml:"hmget_count" default:"4096"`
HScanCount int `yaml:"hscan_count" default:"4096"`
MaxHMGetConnections int `yaml:"max_hmget_connections" default:"8"`
Timeout time.Duration `yaml:"timeout" default:"30s"`
XReadCount int `yaml:"xread_count" default:"4096"`
BlockTimeout time.Duration `yaml:"block_timeout" env:"BLOCK_TIMEOUT" default:"1s"`
HMGetCount int `yaml:"hmget_count" env:"HMGET_COUNT" default:"4096"`
HScanCount int `yaml:"hscan_count" env:"HSCAN_COUNT" default:"4096"`
MaxHMGetConnections int `yaml:"max_hmget_connections" env:"MAX_HMGET_CONNECTIONS" default:"8"`
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT" default:"30s"`
XReadCount int `yaml:"xread_count" env:"XREAD_COUNT" default:"4096"`
}

// Validate checks constraints in the supplied Redis options and returns an error if they are violated.
Expand Down Expand Up @@ -42,11 +42,11 @@ func (o *Options) Validate() error {

// Config defines Config client configuration.
type Config struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Password string `yaml:"password"`
Host string `yaml:"host" env:"HOST"`
Port int `yaml:"port" env:"PORT"`
Password string `yaml:"password" env:"PASSWORD,unset"`
TlsOptions config.TLS `yaml:",inline"`
Options Options `yaml:"options"`
Options Options `yaml:"options" envPrefix:"OPTIONS_"`
}

// Validate checks constraints in the supplied Config configuration and returns an error if they are violated.
Expand Down

0 comments on commit 19eeb8c

Please sign in to comment.