Skip to content

Commit

Permalink
Fix agent not starting with api key missing on Windows (#19887)
Browse files Browse the repository at this point in the history
* Add a new module entry point for the Trace Agent configuration to allow the main Datadog Agent to start even if the API key is missing.

* Revive

* Use params

* Also supply the params to mock component
  • Loading branch information
julien-lebot authored Oct 3, 2023
1 parent bb30f44 commit 95e21f1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/agent/subcommands/run/command_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,8 @@ func getPlatformModules() fx.Option {
return fx.Options(
agentcrashdetect.Module,
comptraceconfig.Module,
fx.Replace(comptraceconfig.Params{
FailIfAPIKeyMissing: false,
}),
)
}
6 changes: 6 additions & 0 deletions comp/trace/config/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ type Mock interface {
// Module defines the fx options for this component.
var Module = fxutil.Component(
fx.Provide(newConfig),
fx.Supply(Params{
FailIfAPIKeyMissing: true,
}),
)

// MockModule defines the fx options for the mock component.
var MockModule = fxutil.Component(
fx.Provide(newMock),
fx.Supply(Params{
FailIfAPIKeyMissing: true,
}),
)
8 changes: 6 additions & 2 deletions comp/trace/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

type dependencies struct {
fx.In

Params Params
Config coreconfig.Component
}

Expand All @@ -43,8 +43,12 @@ type cfg struct {

func newConfig(deps dependencies) (Component, error) {
tracecfg, err := setupConfig(deps, "")

if err != nil {
return nil, err
// Allow main Agent to start with missing API key
if !(err == traceconfig.ErrMissingAPIKey && !deps.Params.FailIfAPIKeyMissing) {
return nil, err
}
}

c := cfg{
Expand Down
12 changes: 12 additions & 0 deletions comp/trace/config/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package config

// Params defines the parameters for the config component.
type Params struct {
// FailIfAPIKeyMissing controls if the Agent should fail if the API key is missing from the config.
FailIfAPIKeyMissing bool
}

0 comments on commit 95e21f1

Please sign in to comment.