Skip to content

Commit

Permalink
[SVLS-4071] Allow serverless proxy settings to be read from datadog.y…
Browse files Browse the repository at this point in the history
…aml and env vars
  • Loading branch information
duncanpharvey committed Nov 25, 2023
1 parent cdc12a3 commit 4be4b02
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
36 changes: 19 additions & 17 deletions cmd/serverless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ func runAgent(stopCh chan struct{}) (serverlessDaemon *daemon.Daemon, err error)
serverlessDaemon.ExecutionContext.SetArnFromExtensionResponse(string(functionArn))
}

// adaptive flush configuration
if v, exists := os.LookupEnv(flushStrategyEnvVar); exists {
if flushStrategy, err := flush.StrategyFromString(v); err != nil {
log.Debugf("Invalid flush strategy %s, will use adaptive flush instead. Err: %s", v, err)
} else {
serverlessDaemon.UseAdaptiveFlush(false) // we're forcing the flush strategy, we won't be using the adaptive flush
serverlessDaemon.SetFlushStrategy(flushStrategy)
}
} else {
serverlessDaemon.UseAdaptiveFlush(true) // already initialized to true, but let's be explicit just in case
}

config.Datadog.SetConfigFile(datadogConfigPath)
// Load datadog.yaml file into the config, so that metricAgent can pick these configurations
if _, err := config.LoadWithoutSecret(); err != nil {
log.Errorf("Error happened when loading configuration from datadog.yaml for metric agent: %s", err)
}

// api key reading
// ---------------

Expand All @@ -173,18 +191,6 @@ func runAgent(stopCh chan struct{}) (serverlessDaemon *daemon.Daemon, err error)
// KMS_ENCRYPTED or SECRET_ARN
apikey.SetSecretsFromEnv(os.Environ())

// adaptive flush configuration
if v, exists := os.LookupEnv(flushStrategyEnvVar); exists {
if flushStrategy, err := flush.StrategyFromString(v); err != nil {
log.Debugf("Invalid flush strategy %s, will use adaptive flush instead. Err: %s", v, err)
} else {
serverlessDaemon.UseAdaptiveFlush(false) // we're forcing the flush strategy, we won't be using the adaptive flush
serverlessDaemon.SetFlushStrategy(flushStrategy)
}
} else {
serverlessDaemon.UseAdaptiveFlush(true) // already initialized to true, but let's be explicit just in case
}

// validate that an apikey has been set, either by the env var, read from KMS or Secrets Manager.
// ---------------------------
if !config.Datadog.IsSet("api_key") {
Expand All @@ -193,11 +199,7 @@ func runAgent(stopCh chan struct{}) (serverlessDaemon *daemon.Daemon, err error)
// of reporting non-critical init errors.
log.Error("No API key configured")
}
config.Datadog.SetConfigFile(datadogConfigPath)
// Load datadog.yaml file into the config, so that metricAgent can pick these configurations
if _, err := config.LoadWithoutSecret(); err != nil {
log.Errorf("Error happened when loading configuration from datadog.yaml for metric agent: %s", err)
}

logChannel := make(chan *logConfig.ChannelMessage)
// Channels for ColdStartCreator
lambdaSpanChan := make(chan *pb.Span)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ require (
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.8.0
github.com/aquasecurity/trivy v0.0.0-00010101000000-000000000000
github.com/aws/aws-sdk-go-v2/service/kms v1.22.2
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.21.6
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.23.3
github.com/cloudfoundry-community/go-cfclient/v2 v2.0.1-0.20230503155151-3d15366c5820
github.com/containerd/cgroups/v3 v3.0.2
github.com/containerd/typeurl/v2 v2.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,7 @@ func EnvVarAreSetAndNotEqual(lhsName string, rhsName string) bool {

// sanitizeAPIKeyConfig strips newlines and other control characters from a given key.
func sanitizeAPIKeyConfig(config Config, key string) {
if !config.IsKnown(key) {
if !config.IsKnown(key) || !config.IsSet(key) {
return
}
config.Set(key, strings.TrimSpace(config.GetString(key)), pkgconfigmodel.SourceAgentRuntime)
Expand Down
2 changes: 1 addition & 1 deletion pkg/serverless/apikey/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ func getSecretEnvVars(envVars []string, kmsFunc decryptFunc, smFunc decryptFunc)
// their API key in plaintext through environment variables.
func SetSecretsFromEnv(envVars []string) {
for envKey, envVal := range getSecretEnvVars(envVars, readAPIKeyFromKMS, readAPIKeyFromSecretsManager) {
os.Setenv(envKey, envVal)
os.Setenv(envKey, strings.TrimSpace(envVal))
}
}

0 comments on commit 4be4b02

Please sign in to comment.