config

package
v8.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config defines the standard configuration schema supported by all versions of Relay.

Index

Constants

View Source
const (
	// DefaultPort is the port that Relay runs on if not otherwise specified.
	DefaultPort = 8030

	// DefaultBaseURI is the default value for Config.BaseURI. This is the base URI of LaunchDarkly
	// services for server-side SDKs other than streaming, such as polling and Big Segment services.
	DefaultBaseURI = "https://sdk.launchdarkly.com"

	// DefaultClientSideBaseURI is the default value for Config.ClientSideBaseURI. This is the base
	// URI of LaunchDarkly services for client-side SDKs other than streaming, such as polling and goals.
	DefaultClientSideBaseURI = "https://clientsdk.launchdarkly.com"

	// DefaultStreamURI is the default value for Config.StreamURI. This is the base URI of the
	// LaunchDarkly streaming service for server-side SDKs. The Relay Proxy does not need an equivalent
	// for client-side SDKs, because in its own connections to LaunchDarkly it always pretends to be a
	// server-side SDK.
	DefaultStreamURI = "https://stream.launchdarkly.com"

	// DefaultEventsURI is the default value for Config.EventsURI. This is the base URI of the
	// LaunchDarkly service for recording events.
	DefaultEventsURI = "https://events.launchdarkly.com"

	// DefaultInitTimeout is the default value for MainConfig.InitTimeout if not specified.
	DefaultInitTimeout = time.Second * 10

	// DefaultEventCapacity is the default value for EventsConfig.Capacity if not specified.
	DefaultEventCapacity = 1000

	// DefaultHeartbeatInterval is the default value for MainConfig.HeartBeatInterval if not specified.
	DefaultHeartbeatInterval = time.Minute * 3

	// DefaultEventsFlushInterval is the default value for EventsConfig.FlushInterval if not specified.
	DefaultEventsFlushInterval = time.Second * 5

	// DefaultDisconnectedStatusTime is the default value for MainConfig.DisconnectedStatusTime if not specified.
	DefaultDisconnectedStatusTime = time.Minute

	// DefaultDatabaseCacheTTL is the default value for the LocalTTL parameter for databases if not specified.
	DefaultDatabaseCacheTTL = time.Second * 30

	// DefaultPrometheusPort is the default value for PrometheusConfig.Port if not specified.
	DefaultPrometheusPort = 8031

	// DefaultBigSegmentsStaleThreshold is the default value for MainConfig.BigSegmentsStaleThreshold if not specified.
	DefaultBigSegmentsStaleThreshold = time.Minute * 5

	// AutoConfigEnvironmentIDPlaceholder is a string that can appear within
	// AutoConfigConfig.EnvDataStorePrefix or AutoConfigConfig.EnvDataStoreTableName to indicate that
	// the environment ID should be substituted at that point.
	//
	// For instance, if EnvDataStorePrefix is "LD-$CID", the value of that setting for an environment
	// whose ID is "12345" would be "LD-12345".
	//
	// If the environment is scoped to a Payload Filter, then the filter key will be concatenated as follows:
	// Given: "LD-$CID", environment ID "12345" and filter key "microservice-a"
	// The substituted result would be: "LD-12345.microservice-a"
	//
	// The same convention is used in OfflineModeConfig.
	AutoConfigEnvironmentIDPlaceholder = "$CID"
)
View Source
const DefaultFilter = FilterKey("")

DefaultFilter represents the lack of a filter, meaning a full LaunchDarkly environment.

Variables

View Source
var DefaultLoggers = logging.MakeDefaultLoggers() //nolint:gochecknoglobals

DefaultLoggers is the default logging configuration used by Relay.

Output goes to stdout, except Error level which goes to stderr. Debug level is disabled.

Functions

func FilterGcfgError

func FilterGcfgError(err error) error

FilterGcfgError transforms errors returned by gcfg to our preferred format.

func LoadConfigFile

func LoadConfigFile(c *Config, path string, loggers ldlog.Loggers) error

LoadConfigFile reads a configuration file into a Config struct and performs basic validation.

The Config parameter should be initialized with default values first.

func LoadConfigFromEnvironment

func LoadConfigFromEnvironment(c *Config, loggers ldlog.Loggers) error

LoadConfigFromEnvironment sets parameters in a Config struct from environment variables.

The Config parameter should be initialized with default values first.

func LoadConfigFromEnvironmentBase

func LoadConfigFromEnvironmentBase(c *Config, loggers ldlog.Loggers) ct.ValidationResult

LoadConfigFromEnvironmentBase performs the initial steps of reading Config fields from environment variables, but returns the intermediate result before fully validating it.

func ValidateConfig

func ValidateConfig(c *Config, loggers ldlog.Loggers) error

ValidateConfig ensures that the configuration does not contain contradictory properties.

This method covers validation rules that can't be enforced on a per-field basis (for instance, if either field A or field B can be specified but it's invalid to specify both). It is allowed to modify the Config struct in order to canonicalize settings in a way that simplifies things for the Relay code (for instance, converting Redis host/port settings into a Redis URL, or converting deprecated fields to non-deprecated ones).

LoadConfigFromEnvironment and LoadConfigFromFile both call this method as a last step, but it is also called again by the Relay constructor because it is possible for application code that uses Relay as a library to construct a Config programmatically.

Types

type AutoConfigConfig

type AutoConfigConfig struct {
	Key                   AutoConfigKey    `conf:"AUTO_CONFIG_KEY"`
	EnvDatastorePrefix    string           `conf:"ENV_DATASTORE_PREFIX"`
	EnvDatastoreTableName string           `conf:"ENV_DATASTORE_TABLE_NAME"`
	EnvAllowedOrigin      ct.OptStringList `conf:"ENV_ALLOWED_ORIGIN"`
	EnvAllowedHeader      ct.OptStringList `conf:"ENV_ALLOWED_HEADER"`
}

AutoConfigConfig contains configuration parameters for the auto-configuration feature.

type AutoConfigKey

type AutoConfigKey string

AutoConfigKey is a type tag to indicate when a string is used as an auto-configuration key.

func (AutoConfigKey) Defined

func (k AutoConfigKey) Defined() bool

func (AutoConfigKey) GetAuthorizationHeaderValue

func (k AutoConfigKey) GetAuthorizationHeaderValue() string

GetAuthorizationHeaderValue for AutoConfigKey returns the same string, since these keys are passed in the Authorization header. Note that unlike the other kinds of authorization keys, this one is never present in an incoming request; it is only used in requests from Relay to LaunchDarkly.

func (AutoConfigKey) Masked added in v8.8.0

func (k AutoConfigKey) Masked() string

func (AutoConfigKey) String

func (k AutoConfigKey) String() string

func (*AutoConfigKey) UnmarshalText

func (k *AutoConfigKey) UnmarshalText(data []byte) error

UnmarshalText allows the AutoConfigKey type to be set from environment variables.

type Config

type Config struct {
	Main        MainConfig
	AutoConfig  AutoConfigConfig
	OfflineMode OfflineModeConfig
	Events      EventsConfig
	Redis       RedisConfig
	Consul      ConsulConfig
	DynamoDB    DynamoDBConfig
	Environment map[string]*EnvConfig
	Filters     map[string]*FiltersConfig
	Proxy       ProxyConfig

	// Optional configuration for metrics integrations. Note that unlike the other fields in Config,
	// MetricsConfig is not the name of a configuration file section; the actual sections are the
	// structs within this struct (Datadog, etc.).
	MetricsConfig
}

Config describes the configuration for a relay instance.

Some fields use special types that enforce validation rules, such as URL fields which must be absolute URLs, port numbers which must be greater than zero, or durations. This validation is done automatically when reading the configuration from a file or from environment variables.

If you are incorporating Relay into your own code and configuring it programmatically, you may need to use functions from go-configtypes such as NewOptDuration to set fields that have validation rules.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type ConsulConfig

type ConsulConfig struct {
	Host      string         `conf:"CONSUL_HOST"`
	LocalTTL  ct.OptDuration `conf:"CACHE_TTL"`
	Token     string         `conf:"CONSUL_TOKEN"`
	TokenFile string         `conf:"CONSUL_TOKEN_FILE"`
}

ConsulConfig configures the optional Consul integration.

Consul is enabled if Host is non-empty.

This corresponds to the [Consul] section in the configuration file.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type DatadogConfig

type DatadogConfig struct {
	Enabled   bool     `conf:"USE_DATADOG"`
	Prefix    string   `conf:"DATADOG_PREFIX"`
	TraceAddr string   `conf:"DATADOG_TRACE_ADDR"`
	StatsAddr string   `conf:"DATADOG_STATS_ADDR"`
	Tag       []string // special handling in LoadConfigFromEnvironment
}

DatadogConfig configures the optional Datadog integration, which is used only if Enabled is true.

This corresponds to the [Datadog] section in the configuration file.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type DynamoDBConfig

type DynamoDBConfig struct {
	Enabled   bool              `conf:"USE_DYNAMODB"`
	TableName string            `conf:"DYNAMODB_TABLE"`
	URL       ct.OptURLAbsolute `conf:"DYNAMODB_URL"`
	LocalTTL  ct.OptDuration    `conf:"CACHE_TTL"`
}

DynamoDBConfig configures the optional DynamoDB integration, which is used only if Enabled is true.

This corresponds to the [DynamoDB] section in the configuration file.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type EnvConfig

type EnvConfig struct {
	SDKKey        SDKKey           // set from env var LD_ENV_envname
	MobileKey     MobileKey        `conf:"LD_MOBILE_KEY_"`
	EnvID         EnvironmentID    `conf:"LD_CLIENT_SIDE_ID_"`
	Prefix        string           `conf:"LD_PREFIX_"`     // used only if Redis, Consul, or DynamoDB is enabled
	TableName     string           `conf:"LD_TABLE_NAME_"` // used only if DynamoDB is enabled
	AllowedOrigin ct.OptStringList `conf:"LD_ALLOWED_ORIGIN_"`
	AllowedHeader ct.OptStringList `conf:"LD_ALLOWED_HEADER_"`
	SecureMode    bool             `conf:"LD_SECURE_MODE_"`
	LogLevel      OptLogLevel      `conf:"LD_LOG_LEVEL_"`
	TTL           ct.OptDuration   `conf:"LD_TTL_"`
	ProjKey       string           `conf:"LD_PROJ_KEY_"`
	FilterKey     FilterKey        // injected based on [filters] section
	Offline       bool             // set to true if this environment was created in offline mode
}

EnvConfig describes an environment to be relayed. There may be any number of these.

This corresponds to one of the [environment "env-name"] sections in the configuration file. In the Config.Environment map, each key is an environment name and each value is an EnvConfig.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type EnvironmentID

type EnvironmentID string

EnvironmentID is a type tag to indicate when a string is used as a client-side environment ID for a LaunchDarkly environment.

func (EnvironmentID) Defined

func (k EnvironmentID) Defined() bool

func (EnvironmentID) GetAuthorizationHeaderValue

func (k EnvironmentID) GetAuthorizationHeaderValue() string

GetAuthorizationHeaderValue for EnvironmentID returns an empty string, since environment IDs are not passed in a header but as part of the request URL.

func (EnvironmentID) Masked added in v8.8.0

func (k EnvironmentID) Masked() string

Masked is an alias for String(), because EnvironmentIDs are considered non-sensitive public information.

func (EnvironmentID) String

func (k EnvironmentID) String() string

func (*EnvironmentID) UnmarshalText

func (k *EnvironmentID) UnmarshalText(data []byte) error

UnmarshalText allows the EnvironmentID type to be set from environment variables.

type EventsConfig

type EventsConfig struct {
	EventsURI             ct.OptURLAbsolute        `conf:"EVENTS_HOST"`
	SendEvents            bool                     `conf:"USE_EVENTS"`
	FlushInterval         ct.OptDuration           `conf:"EVENTS_FLUSH_INTERVAL"`
	Capacity              ct.OptIntGreaterThanZero `conf:"EVENTS_CAPACITY"`
	InlineUsers           bool                     `conf:"EVENTS_INLINE_USERS"`
	MaxInboundPayloadSize ct.OptBase2Bytes         `conf:"EVENTS_MAX_INBOUND_PAYLOAD_SIZE"`
}

EventsConfig contains configuration parameters for proxying events.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type FilterID

type FilterID string

FilterID represents the unique ID for a filter. It is different from the key, which is scoped to the project level.

type FilterKey

type FilterKey string

FilterKey represents the key that should be used when making requests to LaunchDarkly in order to obtain a filtered environment.

type FiltersConfig

type FiltersConfig struct {
	Keys ct.OptStringList `conf:"LD_FILTER_KEYS_"`
}

type MainConfig

type MainConfig struct {
	ExitOnError                      bool                     `conf:"EXIT_ON_ERROR"`
	ExitAlways                       bool                     `conf:"EXIT_ALWAYS"`
	IgnoreConnectionErrors           bool                     `conf:"IGNORE_CONNECTION_ERRORS"`
	StreamURI                        ct.OptURLAbsolute        `conf:"STREAM_URI"`
	BaseURI                          ct.OptURLAbsolute        `conf:"BASE_URI"`
	ClientSideBaseURI                ct.OptURLAbsolute        `conf:"CLIENT_SIDE_BASE_URI"`
	Port                             ct.OptIntGreaterThanZero `conf:"PORT"`
	InitTimeout                      ct.OptDuration           `conf:"INIT_TIMEOUT"`
	HeartbeatInterval                ct.OptDuration           `conf:"HEARTBEAT_INTERVAL"`
	MaxClientConnectionTime          ct.OptDuration           `conf:"MAX_CLIENT_CONNECTION_TIME"`
	DisconnectedStatusTime           ct.OptDuration           `conf:"DISCONNECTED_STATUS_TIME"`
	TLSEnabled                       bool                     `conf:"TLS_ENABLED"`
	TLSCert                          string                   `conf:"TLS_CERT"`
	TLSKey                           string                   `conf:"TLS_KEY"`
	TLSMinVersion                    OptTLSVersion            `conf:"TLS_MIN_VERSION"`
	LogLevel                         OptLogLevel              `conf:"LOG_LEVEL"`
	BigSegmentsStaleAsDegraded       bool                     `conf:"BIG_SEGMENTS_STALE_AS_DEGRADED"`
	BigSegmentsStaleThreshold        ct.OptDuration           `conf:"BIG_SEGMENTS_STALE_THRESHOLD"`
	ExpiredCredentialCleanupInterval ct.OptDuration           `conf:"EXPIRED_CREDENTIAL_CLEANUP_INTERVAL"`
}

MainConfig contains global configuration options for Relay.

This corresponds to the [Main] section in the configuration file.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type MetricsConfig

type MetricsConfig struct {
	Datadog     DatadogConfig
	Stackdriver StackdriverConfig
	Prometheus  PrometheusConfig
}

MetricsConfig contains configurations for optional metrics integrations.

This corresponds to the [Datadog], [Stackdriver], and [Prometheus] sections in the configuration file.

type MobileKey

type MobileKey string

MobileKey is a type tag to indicate when a string is used as a mobile key for a LaunchDarkly environment.

func (MobileKey) Defined

func (k MobileKey) Defined() bool

func (MobileKey) GetAuthorizationHeaderValue

func (k MobileKey) GetAuthorizationHeaderValue() string

GetAuthorizationHeaderValue for MobileKey returns the same string, since mobile keys are passed in the Authorization header.

func (MobileKey) Masked added in v8.8.0

func (k MobileKey) Masked() string

func (MobileKey) String

func (k MobileKey) String() string

func (*MobileKey) UnmarshalText

func (k *MobileKey) UnmarshalText(data []byte) error

UnmarshalText allows the MobileKey type to be set from environment variables.

type OfflineModeConfig

type OfflineModeConfig struct {
	FileDataSource                   string           `conf:"FILE_DATA_SOURCE"`
	FileDataSourceMonitoringInterval ct.OptDuration   `conf:"FILE_DATA_SOURCE_MONITORING_INTERVAL"`
	EnvDatastorePrefix               string           `conf:"ENV_DATASTORE_PREFIX"`
	EnvDatastoreTableName            string           `conf:"ENV_DATASTORE_TABLE_NAME"`
	EnvAllowedOrigin                 ct.OptStringList `conf:"ENV_ALLOWED_ORIGIN"`
	EnvAllowedHeader                 ct.OptStringList `conf:"ENV_ALLOWED_HEADER"`
}

OfflineModeConfig contains configuration parameters for the offline/file data source feature.

type OptLogLevel

type OptLogLevel struct {
	// contains filtered or unexported fields
}

OptLogLevel represents an optional log level parameter. It must match one of the level names "debug", "info", "warn", or "error" (case-insensitive).

The zero value OptLogLevel{} is valid and undefined (IsDefined() is false).

func NewOptLogLevel

func NewOptLogLevel(level ldlog.LogLevel) OptLogLevel

NewOptLogLevel creates an OptLogLevel that wraps the given value.

func NewOptLogLevelFromString

func NewOptLogLevelFromString(levelName string) (OptLogLevel, error)

NewOptLogLevelFromString creates an OptLogLevel from a string that must either be a valid log level name or an empty string.

func (OptLogLevel) GetOrElse

func (o OptLogLevel) GetOrElse(orElseValue ldlog.LogLevel) ldlog.LogLevel

GetOrElse returns the wrapped value, or the alternative value if there is no value.

func (OptLogLevel) IsDefined

func (o OptLogLevel) IsDefined() bool

IsDefined returns true if the instance contains a value.

func (*OptLogLevel) UnmarshalText

func (o *OptLogLevel) UnmarshalText(data []byte) error

UnmarshalText attempts to parse the value from a byte string, using the same logic as NewOptLogLevelFromString.

type OptTLSVersion

type OptTLSVersion struct {
	// contains filtered or unexported fields
}

OptTLSVersion represents an optional TLS level parameter. When represented as a string, it must be "1.0", "1.1", "1.2", or "1.3". This is converted into a uint16 value as defined by crypto/tls.

func NewOptTLSVersion

func NewOptTLSVersion(value uint16) OptTLSVersion

NewOptTLSVersion creates an OptTLSVersion that wraps the given value. It does not validate that the value is one supported by crypto/tls. A value of zero is equivalent to undefined.

func NewOptTLSVersionFromString

func NewOptTLSVersionFromString(version string) (OptTLSVersion, error)

NewOptTLSVersionFromString creates an OptTLSVersion corresponding to the given version string, which must be either a valid TLS major and minor version ("1.2") or an empty string.

func (OptTLSVersion) Get

func (o OptTLSVersion) Get() uint16

Get returns the wrapped value, or zero if there is no value.

func (OptTLSVersion) IsDefined

func (o OptTLSVersion) IsDefined() bool

IsDefined returns true if the instance contains a value.

func (OptTLSVersion) String

func (o OptTLSVersion) String() string

String returns a string description of the value.

func (*OptTLSVersion) UnmarshalText

func (o *OptTLSVersion) UnmarshalText(data []byte) error

UnmarshalText attempts to parse the value from a byte string, using the same logic as NewOptTLSVersionFromString.

type PrometheusConfig

type PrometheusConfig struct {
	Enabled bool                     `conf:"USE_PROMETHEUS"`
	Prefix  string                   `conf:"PROMETHEUS_PREFIX"`
	Port    ct.OptIntGreaterThanZero `conf:"PROMETHEUS_PORT"`
}

PrometheusConfig configures the optional Prometheus integration, which is used only if Enabled is true.

This corresponds to the PrometheusConfig section in the configuration file.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type ProxyConfig

type ProxyConfig struct {
	URL         ct.OptURLAbsolute `conf:"PROXY_URL"`
	NTLMAuth    bool              `conf:"PROXY_AUTH_NTLM"`
	User        string            `conf:"PROXY_AUTH_USER"`
	Password    string            `conf:"PROXY_AUTH_PASSWORD"`
	Domain      string            `conf:"PROXY_AUTH_DOMAIN"`
	CACertFiles ct.OptStringList  `conf:"PROXY_CA_CERTS"`
}

ProxyConfig represents all the supported proxy options.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type RedisConfig

type RedisConfig struct {
	Host     string `conf:"REDIS_HOST"`
	Port     ct.OptIntGreaterThanZero
	URL      ct.OptURLAbsolute `conf:"REDIS_URL"`
	LocalTTL ct.OptDuration    `conf:"CACHE_TTL"`
	TLS      bool              `conf:"REDIS_TLS"`
	Username string            `conf:"REDIS_USERNAME"`
	Password string            `conf:"REDIS_PASSWORD"`
}

RedisConfig configures the optional Redis integration.

Redis is enabled if URL or Host is non-empty or if Port is set. If only Host or Port is set, the other value is set to defaultRedisPort or defaultRedisHost. It is an error to set Host or Port if URL is also set.

This corresponds to the [Redis] section in the configuration file.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

type SDKKey

type SDKKey string

SDKKey is a type tag to indicate when a string is used as a server-side SDK key for a LaunchDarkly environment.

func (SDKKey) Defined

func (k SDKKey) Defined() bool

func (SDKKey) GetAuthorizationHeaderValue

func (k SDKKey) GetAuthorizationHeaderValue() string

GetAuthorizationHeaderValue for SDKKey returns the same string, since SDK keys are passed in the Authorization header.

func (SDKKey) Masked added in v8.8.0

func (k SDKKey) Masked() string

func (SDKKey) String

func (k SDKKey) String() string

func (*SDKKey) UnmarshalText

func (k *SDKKey) UnmarshalText(data []byte) error

UnmarshalText allows the SDKKey type to be set from environment variables.

type StackdriverConfig

type StackdriverConfig struct {
	Enabled   bool   `conf:"USE_STACKDRIVER"`
	Prefix    string `conf:"STACKDRIVER_PREFIX"`
	ProjectID string `conf:"STACKDRIVER_PROJECT_ID"`
}

StackdriverConfig configures the optional Stackdriver integration, which is used only if Enabled is true.

This corresponds to the StackdriverConfig section in the configuration file.

Since configuration options can be set either programmatically, or from a file, or from environment variables, individual fields are not documented here; instead, see the `README.md` section on configuration.

Jump to

Keyboard shortcuts

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