Documentation ¶
Overview ¶
Package config is responsible for loading the configuration from various sources, e.g., environment variables, configuration files and user input. It also accepts dynamic settings from the collector server.
In order to add a new configuration item, you need to:
- add a field to the Config struct and assign the corresponding env variable name and the default value via struct tags.
- add validation code to method `Config.validate()` (optional).
- add a method to retrieve the config value and a wrapper for the default global variable `conf` (see wrappers.go).
Index ¶
- Constants
- Variables
- func InvalidEnv(env string, val string) string
- func IsValidEc2MetadataTimeout(t int) bool
- func IsValidFile(file string) bool
- func IsValidHost(host string) bool
- func IsValidHostnameAlias(a string) bool
- func IsValidReporterType(t string) bool
- func IsValidSampleRate(rate int) bool
- func IsValidTokenBucketCap(cap float64) bool
- func IsValidTokenBucketRate(rate float64) bool
- func IsValidTracingMode(m TracingMode) bool
- func MaskServiceKey(validKey string) string
- func MissingEnv(env string) string
- func ToInteger(i string) int
- func ToServiceKey(s string) string
- type Config
- func (c *Config) GetCollector() string
- func (c *Config) GetCollectorUDP() string
- func (c *Config) GetDebugLevel() string
- func (c *Config) GetDelta() *Delta
- func (c *Config) GetDisabled() bool
- func (c *Config) GetEc2MetadataTimeout() int
- func (c *Config) GetHostAlias() string
- func (c *Config) GetPrecision() int
- func (c *Config) GetPrependDomain() bool
- func (c *Config) GetProxy() string
- func (c *Config) GetProxyCertPath() string
- func (c *Config) GetReportQueryString() bool
- func (c *Config) GetReporter() *ReporterOptions
- func (c *Config) GetReporterType() string
- func (c *Config) GetRuntimeMetrics() bool
- func (c *Config) GetSQLSanitize() int
- func (c *Config) GetSampleRate() int
- func (c *Config) GetServiceKey() string
- func (c *Config) GetTokenBucketCap() float64
- func (c *Config) GetTokenBucketRate() float64
- func (c *Config) GetTracingMode() TracingMode
- func (c *Config) GetTransactionFiltering() []TransactionFilter
- func (c *Config) GetTransactionName() string
- func (c *Config) GetTriggerTrace() bool
- func (c *Config) GetTrustedPath() string
- func (c *Config) Load(opts ...Option) *Config
- func (c *Config) SamplingConfigured() bool
- type Delta
- type DeltaItem
- type FilterType
- type Option
- type ReporterOptions
- type SamplingConfig
- func (s *SamplingConfig) Configured() bool
- func (s *SamplingConfig) ResetSampleRate()
- func (s *SamplingConfig) ResetTracingMode()
- func (s *SamplingConfig) SetSampleRate(rate int)
- func (s *SamplingConfig) SetTracingMode(mode TracingMode)
- func (s *SamplingConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
- type TracingMode
- type TransactionFilter
Constants ¶
const ( // MaxSampleRate is the maximum sample rate we can have MaxSampleRate = 1000000 // MinSampleRate is the minimum sample rate we can have MinSampleRate = 0 )
Variables ¶
var ( ErrUnsupportedFormat = errors.New("unsupported format") ErrFileTooLarge = errors.New("file size exceeds limit") ErrInvalidServiceKey = errors.New(fullTextInvalidServiceKey) )
Errors
var ( ErrTFInvalidType = errors.New("invalid Type") ErrTFInvalidTracing = errors.New("invalid Tracing") ErrTFInvalidRegExExt = errors.New("must set either RegEx or Extensions, but not both") )
TransactionFilter unmarshal errors
var ( // IsValidServiceKey verifies if the service key is a valid one. // A valid service key is something like 'service_token:service_name'. // The service_token should be of 64 characters long and the size of // service_name is larger than 0 but up to 255 characters. IsValidServiceKey = regexp.MustCompile(validServiceKeyPattern).MatchString // ReplaceSpacesWith replaces all the spaces with valid characters (hyphen) ReplaceSpacesWith = regexp.MustCompile(spacesPattern).ReplaceAllString // RemoveInvalidChars remove invalid characters RemoveInvalidChars = regexp.MustCompile(invalidCharacters).ReplaceAllString )
var DebugLevel = conf.GetDebugLevel
DebugLevel is a wrapper to the method of the global config
var GetCollector = conf.GetCollector
GetCollector is a wrapper to the method of the global config
var GetCollectorUDP = conf.GetCollectorUDP
GetCollectorUDP is a wrapper to the method of the global config
var GetDelta = conf.GetDelta
var GetDisabled = conf.GetDisabled
GetDisabled is a wrapper to the method of the global config
var GetEc2MetadataTimeout = conf.GetEc2MetadataTimeout
GetEc2MetadataTimeout is a wrapper to the method of the global config
var GetHostAlias = conf.GetHostAlias
GetHostAlias is a wrapper to the method of the global config
var GetPrecision = conf.GetPrecision
GetPrecision is a wrapper to the method of the global config
var GetPrependDomain = conf.GetPrependDomain
GetPrependDomain is a wrapper to the method of the global config
var GetProxy = conf.GetProxy
GetProxy is a wrapper to the method of the global config
var GetProxyCertPath = conf.GetProxyCertPath
GetProxyCertPath is a wrapper to the method of the global config
var GetReportQueryString = conf.GetReportQueryString
var GetReporterType = conf.GetReporterType
GetReporterType is a wrapper to the method of the global config
var GetRuntimeMetrics = conf.GetRuntimeMetrics
GetRuntimeMetrics is a wrapper to the method of the global config
var GetSQLSanitize = conf.GetSQLSanitize
GetSQLSanitize is a wrapper to method GetSQLSanitize of the global variable config.
var GetSampleRate = conf.GetSampleRate
GetSampleRate is a wrapper to the method of the global config
var GetServiceKey = conf.GetServiceKey
GetServiceKey is a wrapper to the method of the global config
var GetTokenBucketCap = conf.GetTokenBucketCap
var GetTokenBucketRate = conf.GetTokenBucketRate
var GetTracingMode = conf.GetTracingMode
GetTracingMode is a wrapper to the method of the global config
var GetTransactionFiltering = conf.GetTransactionFiltering
GetTransactionFiltering is a wrapper to the method of the global config
var GetTransactionName = conf.GetTransactionName
var GetTriggerTrace = conf.GetTriggerTrace
GetTriggerTrace is a wrapper to the method of the global config
var GetTrustedPath = conf.GetTrustedPath
GetTrustedPath is a wrapper to the method of the global config
var Load = conf.Load
Load reads the customized configurations
var ReporterOpts = conf.GetReporter
ReporterOpts is a wrapper to the method of the global config
var SamplingConfigured = conf.SamplingConfigured
SamplingConfigured is a wrapper to the method of the global config
Functions ¶
func InvalidEnv ¶
InvalidEnv returns a string indicating invalid environment variables
func IsValidEc2MetadataTimeout ¶
IsValidEc2MetadataTimeout checks if the timeout is within the designated range
func IsValidFile ¶
IsValidFile checks if the string represents a valid file.
func IsValidHost ¶
IsValidHost verifies if the host is in a valid format
func IsValidHostnameAlias ¶
IsValidHostnameAlias checks if the alias is valid
func IsValidReporterType ¶
IsValidReporterType checks if the reporter type is valid.
func IsValidSampleRate ¶
IsValidSampleRate checks if the rate is valid
func IsValidTokenBucketCap ¶
func IsValidTokenBucketRate ¶
func IsValidTracingMode ¶
func IsValidTracingMode(m TracingMode) bool
IsValidTracingMode checks if the mode is valid
func MaskServiceKey ¶
MaskServiceKey masks the middle part of the token and returns the masked service key. For example: key: "ae38315f6116585d64d82ec2455aa3ec61e02fee25d286f74ace9e4fea189217:go" masked:"ae38********************************************************9217:go"
func MissingEnv ¶
MissingEnv returns a string indicating missing environment variables
func ToServiceKey ¶
ToServiceKey converts a string to a service key. The argument should be a valid service key string.
It doesn't touch the service key but does the following to the original service name: - convert all characters to lowercase - convert spaces to hyphens - remove invalid characters ( [^a-z0-9.:_-])
Types ¶
type Config ¶
type Config struct { sync.RWMutex `yaml:"-"` // Collector defines the host and port of the AppOptics collector Collector string `yaml:"Collector,omitempty" env:"APPOPTICS_COLLECTOR" default:"collector.appoptics.com:443"` // ServiceKey defines the service key and service name ServiceKey string `yaml:"ServiceKey,omitempty" env:"APPOPTICS_SERVICE_KEY"` // The file path of the cert file for gRPC connection TrustedPath string `yaml:"TrustedPath,omitempty" env:"APPOPTICS_TRUSTEDPATH"` // The host and port of the UDP collector CollectorUDP string `yaml:"CollectorUDP,omitempty" env:"APPOPTICS_COLLECTOR_UDP"` // The reporter type, ssl or udp ReporterType string `yaml:"ReporterType,omitempty" env:"APPOPTICS_REPORTER" default:"ssl"` Sampling *SamplingConfig `yaml:"Sampling,omitempty"` // Whether the domain should be prepended to the transaction name. PrependDomain bool `yaml:"PrependDomain,omitempty" env:"APPOPTICS_PREPEND_DOMAIN"` // The alias of the hostname HostAlias string `yaml:"HostAlias,omitempty" env:"APPOPTICS_HOSTNAME_ALIAS"` // The precision of the histogram Precision int `yaml:"Precision,omitempty" env:"APPOPTICS_HISTOGRAM_PRECISION" default:"2"` // The SQL sanitization level SQLSanitize int `yaml:"SQLSanitize,omitempty" env:"APPOPTICS_SQL_SANITIZE" default:"0"` // The reporter options ReporterProperties *ReporterOptions `yaml:"ReporterProperties,omitempty"` // The transaction filtering config TransactionSettings []TransactionFilter `yaml:"TransactionSettings,omitempty"` Disabled bool `yaml:"Disabled,omitempty" env:"APPOPTICS_DISABLED"` // EC2 metadata retrieval timeout in milliseconds Ec2MetadataTimeout int `yaml:"Ec2MetadataTimeout,omitempty" env:"APPOPTICS_EC2_METADATA_TIMEOUT" default:"1000"` // The default log level. It should follow the level defined in log.DefaultLevel DebugLevel string `yaml:"DebugLevel,omitempty" env:"APPOPTICS_DEBUG_LEVEL" default:"warn"` // The flag for trigger trace. It's enabled by default. TriggerTrace bool `yaml:"TriggerTrace" env:"APPOPTICS_TRIGGER_TRACE" default:"true"` // Url of the HTTP/HTTPS proxy in the format of "scheme://<username>:<password>@<host>:<port>" Proxy string `yaml:"Proxy,omitempty" env:"APPOPTICS_PROXY"` // Cert path for the HTTP/HTTPS proxy ProxyCertPath string `yaml:"ProxyCertPath" env:"APPOPTICS_PROXY_CERT_PATH"` // Report runtime metrics or not RuntimeMetrics bool `yaml:"RuntimeMetrics" env:"APPOPTICS_RUNTIME_METRICS" default:"true"` // ReportQueryString indicates if the query string should be reported as part of the URL ReportQueryString bool `yaml:"ReportQueryString" env:"APPOPTICS_REPORT_QUERY_STRING" default:"true"` TokenBucketCap float64 `yaml:"TokenBucketCap" env:"APPOPTICS_TOKEN_BUCKET_CAPACITY" default:"8"` TokenBucketRate float64 `yaml:"TokenBucketRate" env:"APPOPTICS_TOKEN_BUCKET_RATE" default:"0.17"` // The user-defined transaction name. It's only available in the AWS Lambda environment. TransactionName string `yaml:"TransactionName" env:"APPOPTICS_TRANSACTION_NAME"` }
Config is the struct to define the agent configuration. The configuration options in this struct (excluding those from ReporterOptions) are not intended for dynamically updating.
func NewConfig ¶
NewConfig initializes a Config object and override default values with options provided as arguments. It may print errors if there are invalid values in the configuration file or the environment variables.
If there is a fatal error (e.g., invalid config file), it will return a config object with default values.
func (*Config) GetCollector ¶
GetCollector returns the collector address
func (*Config) GetCollectorUDP ¶
GetCollectorUDP returns the UDP collector host
func (*Config) GetDebugLevel ¶
GetDebugLevel returns the global logging level. Note that it may return an empty string
func (*Config) GetDisabled ¶
GetDisabled returns if the agent is disabled
func (*Config) GetEc2MetadataTimeout ¶
GetEc2MetadataTimeout returns the EC2 metadata retrieval timeout in milliseconds
func (*Config) GetHostAlias ¶
GetHostAlias returns the host alias
func (*Config) GetPrecision ¶
GetPrecision returns the histogram precision
func (*Config) GetPrependDomain ¶
GetPrependDomain returns the prepend domain config
func (*Config) GetProxyCertPath ¶
GetProxyCertPath returns the proxy's certificate path
func (*Config) GetReportQueryString ¶
GetReportQueryString returns the ReportQueryString flag
func (*Config) GetReporter ¶
func (c *Config) GetReporter() *ReporterOptions
GetReporter returns the reporter options struct
func (*Config) GetReporterType ¶
GetReporterType returns the reporter type
func (*Config) GetRuntimeMetrics ¶
GetRuntimeMetrics returns the runtime metrics flag
func (*Config) GetSQLSanitize ¶
GetSQLSanitize returns the SQL sanitization level.
The meaning of each level: 0 - disable SQL sanitizing (the default). 1 - enable SQL sanitizing and attempt to automatically determine which quoting form to use. 2 - enable SQL sanitizing and force dropping double quoted characters. 4 - enable SQL sanitizing and force retaining double quoted character.
func (*Config) GetSampleRate ¶
GetSampleRate returns the local sample rate
func (*Config) GetServiceKey ¶
GetServiceKey returns the service key
func (*Config) GetTokenBucketCap ¶
GetTokenBucketCap returns the token bucket capacity
func (*Config) GetTokenBucketRate ¶
GetTokenBucketRate returns the token bucket rate
func (*Config) GetTracingMode ¶
func (c *Config) GetTracingMode() TracingMode
GetTracingMode returns the local tracing mode
func (*Config) GetTransactionFiltering ¶
func (c *Config) GetTransactionFiltering() []TransactionFilter
GetTransactionFiltering returns the transaction filtering config
func (*Config) GetTransactionName ¶
GetTransactionName returns the user-defined transaction name. It's only available in the AWS Lambda environment.
func (*Config) GetTriggerTrace ¶
GetTriggerTrace returns the trigger trace configuration
func (*Config) GetTrustedPath ¶
GetTrustedPath returns the file path of the cert file
func (*Config) SamplingConfigured ¶
SamplingConfigured returns if tracing mode or sampling rate is configured
type Delta ¶
type Delta struct {
// contains filtered or unexported fields
}
Delta defines the overall delta of two Config objects
type DeltaItem ¶
type DeltaItem struct {
// contains filtered or unexported fields
}
DeltaItem defines a delta item of two Config objects
type FilterType ¶
type FilterType string
FilterType defines the type of the transaction filter
const ( // URL based filter URL FilterType = "url" )
type Option ¶
type Option func(c *Config)
Option is a function type that accepts a Config pointer and applies the configuration option it defines.
func WithCollector ¶
WithCollector defines a Config option for collector address.
func WithServiceKey ¶
WithServiceKey defines a Config option for the service key.
type ReporterOptions ¶
type ReporterOptions struct { // Events flush interval in seconds EventFlushInterval int64 `yaml:"EventFlushInterval,omitempty" env:"APPOPTICS_EVENTS_FLUSH_INTERVAL" default:"2"` // The maximum bytes per RPC request MaxReqBytes int64 `yaml:"MaxReqBytes,omitempty" env:"APPOPTICS_MAX_REQUEST_BYTES" default:"2048000"` // Metrics flush interval in seconds MetricFlushInterval int64 `yaml:"MetricFlushInterval,omitempty" default:"30"` // GetSettings interval in seconds GetSettingsInterval int64 `yaml:"GetSettingsInterval,omitempty" default:"30"` // Settings timeout interval in seconds SettingsTimeoutInterval int64 `yaml:"SettingsTimeoutInterval,omitempty" default:"10"` // Ping interval in seconds PingInterval int64 `yaml:"PingInterval,omitempty" default:"20"` // Retry backoff initial delay RetryDelayInitial int64 `yaml:"RetryDelayInitial,omitempty" default:"500"` // Maximum retry delay RetryDelayMax int `yaml:"RetryDelayMax,omitempty" default:"60"` // Maximum redirect times RedirectMax int `yaml:"RedirectMax,omitempty" default:"20"` // The threshold of retries before debug printing RetryLogThreshold int `yaml:"RetryLogThreshold,omitempty" default:"10"` // The maximum retries MaxRetries int `yaml:"MaxRetries,omitempty" default:"20"` }
ReporterOptions defines the options of a reporter. The fields of it must be accessed through atomic operators
func (*ReporterOptions) GetEventFlushInterval ¶
func (r *ReporterOptions) GetEventFlushInterval() int64
GetEventFlushInterval returns the current event flush interval
func (*ReporterOptions) GetMaxReqBytes ¶
func (r *ReporterOptions) GetMaxReqBytes() int64
GetMaxReqBytes returns the maximum RPC request size
func (*ReporterOptions) SetEventFlushInterval ¶
func (r *ReporterOptions) SetEventFlushInterval(i int64)
SetEventFlushInterval sets the event flush interval to i
func (*ReporterOptions) SetMaxReqBytes ¶
func (r *ReporterOptions) SetMaxReqBytes(i int64)
SetMaxReqBytes sets the maximum bytes of the PRC request body to i
type SamplingConfig ¶
type SamplingConfig struct { // The tracing mode TracingMode TracingMode `yaml:"TracingMode,omitempty" env:"APPOPTICS_TRACING_MODE" default:"enabled"` // The sample rate SampleRate int `yaml:"SampleRate,omitempty" env:"APPOPTICS_SAMPLE_RATE" default:"1000000"` // contains filtered or unexported fields }
SamplingConfig defines the configuration options for the sampling decision
func (*SamplingConfig) Configured ¶
func (s *SamplingConfig) Configured() bool
Configured returns if either the tracing mode or the sampling rate has been configured
func (*SamplingConfig) ResetSampleRate ¶
func (s *SamplingConfig) ResetSampleRate()
ResetSampleRate resets the sample rate to its default value and clear the flag.
func (*SamplingConfig) ResetTracingMode ¶
func (s *SamplingConfig) ResetTracingMode()
ResetTracingMode resets the tracing mode to its default value and clear the flag.
func (*SamplingConfig) SetSampleRate ¶
func (s *SamplingConfig) SetSampleRate(rate int)
SetSampleRate assigns the sample rate and set the corresponding flag. Note: Do not change the method name as it (`Set`+Field name) is used in method `loadEnvsInternal` to assign the values loaded from env variables dynamically.
func (*SamplingConfig) SetTracingMode ¶
func (s *SamplingConfig) SetTracingMode(mode TracingMode)
SetTracingMode assigns the tracing mode and set the corresponding flag. Note: Do not change the method name as it (`Set`+Field name) is used in method `loadEnvsInternal` to assign the values loaded from env variables dynamically.
func (*SamplingConfig) UnmarshalYAML ¶
func (s *SamplingConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML is the customized unmarshal method for SamplingConfig
type TracingMode ¶
type TracingMode string
TracingMode defines the tracing mode which is either `enabled` or `disabled`
const ( // EnabledTracingMode means tracing is enabled EnabledTracingMode TracingMode = "enabled" // DisabledTracingMode means tracing is disabled DisabledTracingMode TracingMode = "disabled" UnknownTracingMode TracingMode = "unknown" )
func NormalizeTracingMode ¶
func NormalizeTracingMode(m TracingMode) TracingMode
NormalizeTracingMode converts an old-style tracing mode (always/never) to a new-style tracing mode (enabled/disabled).
type TransactionFilter ¶
type TransactionFilter struct { Type FilterType `yaml:"Type"` RegEx string `yaml:"RegEx,omitempty"` Extensions []string `yaml:"Extensions,omitempty"` Tracing TracingMode `yaml:"Tracing"` }
TransactionFilter defines the transaction filtering based on a filter type.
func (*TransactionFilter) UnmarshalYAML ¶
func (f *TransactionFilter) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML is the customized unmarshal method for TransactionFilter