config

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStrategyBreak = errors.New("replica configuration complete")

Functions

This section is empty.

Types

type BackupConfig added in v1.3.1

type BackupConfig struct {
	Enabled  bool          `split_words:"true" default:"false"`
	Interval time.Duration `split_words:"true" default:"24h"`
	Storage  string        `split_words:"true" required:"false"`
	Keep     int           `split_words:"true" default:"1"`
}

type Config

type Config struct {
	Maintenance     bool                  `split_words:"true" default:"false"`
	BindAddr        string                `split_words:"true" default:":4436"`
	LogLevel        logger.LevelDecoder   `split_words:"true" default:"info"`
	ConsoleLog      bool                  `split_words:"true" default:"false"`
	Metrics         MetricsConfig         `split_words:"true"`
	Database        DatabaseConfig        `split_words:"true"`
	Replica         ReplicaConfig         `split_words:"true"`
	ReplicaStrategy ReplicaStrategyConfig `split_words:"true"`
	MTLS            MTLSConfig            `split_words:"true"`
	Backup          BackupConfig          `split_words:"true"`
	Sentry          sentry.Config         `split_words:"true"`
	// contains filtered or unexported fields
}

Config defines the struct that is expected to initialize the trtl server Note: because we need to validate the configuration, `config.New()` must be called to ensure that the `processed` is correctly set

func New

func New() (_ Config, err error)

New creates a new Config object, loading environment variables and defaults.

func (Config) GetHonuConfig

func (c Config) GetHonuConfig() honuconfig.Option

GetHonuConfig converts ReplicaConfig into honu's struct of the same name.

func (Config) GetLogLevel

func (c Config) GetLogLevel() zerolog.Level

func (Config) IsZero

func (c Config) IsZero() bool

func (Config) Mark

func (c Config) Mark() (Config, error)

Mark a manually constructed as processed as long as it is validated.

func (Config) Validate

func (c Config) Validate() (err error)

type DatabaseConfig

type DatabaseConfig struct {
	URL           string `split_words:"true" required:"true"`
	ReindexOnBoot bool   `split_words:"true" default:"false"`
}

type MTLSConfig added in v1.3.1

type MTLSConfig struct {
	Insecure  bool   `envconfig:"TRTL_INSECURE" default:"false"`
	ChainPath string `split_words:"true" required:"false"`
	CertPath  string `split_words:"true" required:"false"`
	// contains filtered or unexported fields
}

func (*MTLSConfig) GetCert added in v1.3.1

func (c *MTLSConfig) GetCert() (_ tls.Certificate, err error)

func (*MTLSConfig) GetCertPool added in v1.3.1

func (c *MTLSConfig) GetCertPool() (_ *x509.CertPool, err error)

func (*MTLSConfig) ParseTLSConfig added in v1.3.1

func (c *MTLSConfig) ParseTLSConfig() (_ *tls.Config, err error)

func (*MTLSConfig) Validate added in v1.3.1

func (c *MTLSConfig) Validate() error

type MetricsConfig added in v1.7.0

type MetricsConfig struct {
	Addr     string        `split_words:"true" default:":7777"`
	Enabled  bool          `split_words:"true" default:"true"`
	Interval time.Duration `split_words:"true" default:"5m"`
}

type ReplicaConfig

type ReplicaConfig struct {
	Enabled        bool          `split_words:"true" default:"true" json:"enabled"`
	PID            uint64        `split_words:"true" required:"false" json:"pid"`
	Region         string        `split_words:"true" required:"false" json:"region"`
	Name           string        `split_words:"true" required:"false" json:"name"`
	GossipInterval time.Duration `split_words:"true" default:"1m" json:"gossip_interval"`
	GossipSigma    time.Duration `split_words:"true" default:"5s" json:"gossip_sigma"`
}

func (ReplicaConfig) Configure added in v1.3.1

func (c ReplicaConfig) Configure(strategies ...ReplicaStrategy) (_ ReplicaConfig, err error)

Configure applies one or more replica strategies to determine the replica configuration, ensuring that the replica is unique in the system. Each strategy is applied in the order specified and will continue until a ErrStrategyBreak is returned or all strategies have been applied. A new configuration is returned and the original configuration is unmodified.

func (*ReplicaConfig) Validate

func (c *ReplicaConfig) Validate() error

type ReplicaStrategy added in v1.3.1

type ReplicaStrategy func(in ReplicaConfig, err error) (ReplicaConfig, error)

A ReplicaStrategy defines alternate methods for populating a ReplicaConfig besides simply loading them from the environment (the default configuration method). The strategy will receive an input config value (not a pointer) and it must create a new configuration with the modifications so that the original config is not changed during processing. The error result returned by the function defines how the strategy continues if multiple strategies are applied. If the function returns a special StrategyBreak error, the replica configuration will stop processing without an error returned; all other non-nil errors are passed to the next strategy, so that they can continue to pass the error

func FilePID added in v1.3.1

func FilePID(path string) ReplicaStrategy

FilePID reads the PID from a file and is intended as a fast way to set the PID on a POD or in a development environment, very similar to how a /var/run/proc.pid works. This strategy returns a MultiError for downstream processing if it cannot fetch the hostname or parse it; it does not return a StrategyBreak.

func HostnamePID added in v1.3.1

func HostnamePID(hostname string) ReplicaStrategy

HostnamePID attempts to process a pod-n hostname from a kubernetes pod created by a stateful set to determine the PID. If the hostname passed in is empty, then os.Hostname is used to determine the name. The PID (e.g. n from pod-n) is then added to the configured PID so that it can be used to specify a range of PIDs. E.g. if the environment PID is 40 and the hostname is trtl-2 then the PID will be 42. StatefulSets (or vms, or hardware) can then be configured with ranges of PID values. This strategy returns a MultiError for downstream processing if it cannot fetch the hostname or parse it; it does not return a StrategyBreak.

func JSONConfig added in v1.3.1

func JSONConfig(path string) ReplicaStrategy

JSONConfig attempts to configure the Replica by loading a JSON file that maps PID to configuration data. If the previous error is not nil, then no processing will happen and the error will be returned. If the configuration is successful, then this will return StrategyBreak. The idea here is that a universal config map can be loaded into a kubernetes cluster and a HostnamePID or FilePID applied before JSONConfig (if they fail, we shouldn't try to lookup the default PID). If successfully configured, the processing can stop, otherwise we can continue to other configuration strategies.

func MultiError added in v1.3.1

func MultiError(f ReplicaStrategy) ReplicaStrategy

MultiError collects errors from the strategy into a single error for reporting.

type ReplicaStrategyConfig added in v1.3.1

type ReplicaStrategyConfig struct {
	HostnamePID bool   `split_words:"true" default:"false"` // Set to true to use HostnamePID
	Hostname    string `envconfig:"TRTL_REPLICA_HOSTNAME"`  // configure the hostname from the environment
	FilePID     string `split_words:"true"`                 // Set to the PID filename path to use FilePID
	JSONConfig  string `split_words:"true"`                 // Set to the config map path to use JSONConfig
}

func (*ReplicaStrategyConfig) Strategies added in v1.3.1

func (c *ReplicaStrategyConfig) Strategies() (strategies []ReplicaStrategy)

Strategies extracts the replica configuration strategies from the configuration

Jump to

Keyboard shortcuts

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