Skip to content

Commit

Permalink
Use more restrictive interface when initializing the config (#29799)
Browse files Browse the repository at this point in the history
  • Loading branch information
hush-hush authored Oct 7, 2024
1 parent b755dfa commit ecf99e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions pkg/config/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ type Setup interface {
// If env is provided, it will override the name of the environment variable used for this
// config key
BindEnvAndSetDefault(key string, val interface{}, env ...string)

AddConfigPath(in string)
AddExtraConfigPaths(in []string) error
SetConfigName(in string)
SetConfigFile(in string)
SetConfigType(in string)
}

// Compound is an interface for retrieving compound elements from the config, plus
Expand All @@ -144,12 +150,6 @@ type Compound interface {
MergeConfig(in io.Reader) error
MergeConfigMap(cfg map[string]any) error
MergeFleetPolicy(configPath string) error

AddConfigPath(in string)
AddExtraConfigPaths(in []string) error
SetConfigName(in string)
SetConfigFile(in string)
SetConfigType(in string)
}

// Config represents an object that can load and store configuration parameters
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/setup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ func init() {

// initCommonWithServerless initializes configs that are common to all agents, in particular serverless.
// Initializing the config keys takes too much time for serverless, so we try to initialize only what is reachable.
func initCommonWithServerless(config pkgconfigmodel.Config) {
func initCommonWithServerless(config pkgconfigmodel.Setup) {
for _, f := range serverlessConfigComponents {
f(config)
}
}

// InitConfig initializes the config defaults on a config used by all agents
// (in particular more than just the serverless agent).
func InitConfig(config pkgconfigmodel.Config) {
func InitConfig(config pkgconfigmodel.Setup) {
initCommonWithServerless(config)

// Auto exit configuration
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/setup/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var processesAddOverrideOnce sync.Once

// procBindEnvAndSetDefault is a helper function that generates both "DD_PROCESS_CONFIG_" and "DD_PROCESS_AGENT_" prefixes from a key.
// We need this helper function because the standard BindEnvAndSetDefault can only generate one prefix from a key.
func procBindEnvAndSetDefault(config pkgconfigmodel.Config, key string, val interface{}) {
func procBindEnvAndSetDefault(config pkgconfigmodel.Setup, key string, val interface{}) {
// Uppercase, replace "." with "_" and add "DD_" prefix to key so that we follow the same environment
// variable convention as the core agent.
processConfigKey := "DD_" + strings.Replace(strings.ToUpper(key), ".", "_", -1)
Expand All @@ -102,14 +102,14 @@ func procBindEnvAndSetDefault(config pkgconfigmodel.Config, key string, val inte

// procBindEnv is a helper function that generates both "DD_PROCESS_CONFIG_" and "DD_PROCESS_AGENT_" prefixes from a key, but does not set a default.
// We need this helper function because the standard BindEnv can only generate one prefix from a key.
func procBindEnv(config pkgconfigmodel.Config, key string) {
func procBindEnv(config pkgconfigmodel.Setup, key string) {
processConfigKey := "DD_" + strings.Replace(strings.ToUpper(key), ".", "_", -1)
processAgentKey := strings.Replace(processConfigKey, "PROCESS_CONFIG", "PROCESS_AGENT", 1)

config.BindEnv(key, processConfigKey, processAgentKey)
}

func setupProcesses(config pkgconfigmodel.Config) {
func setupProcesses(config pkgconfigmodel.Setup) {
// "process_config.enabled" is deprecated. We must still be able to detect if it is present, to know if we should use it
// or container_collection.enabled and process_collection.enabled.
procBindEnv(config, "process_config.enabled")
Expand Down

0 comments on commit ecf99e5

Please sign in to comment.