Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V2 experimentation]profiler: remove WithAPIKey and WithAgentlessUpload #2224

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions profiler/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func defaultConfig() (*config, error) {
WithUploadTimeout(d)(&c)
}
if v := os.Getenv("DD_API_KEY"); v != "" {
WithAPIKey(v)(&c)
c.apiKey = v
}
if internal.BoolEnv("DD_PROFILING_AGENTLESS", false) {
WithAgentlessUpload()(&c)
Expand Down Expand Up @@ -319,19 +319,6 @@ func WithAgentAddr(hostport string) Option {
}
}

// WithAPIKey sets the Datadog API Key and takes precedence over the DD_API_KEY
// env variable. Historically this option was used to enable agentless
// uploading, but as of dd-trace-go v1.30.0 the behavior has changed to always
// default to agent based uploading which doesn't require an API key. So if you
// currently don't have an agent running on the default localhost:8126 hostport
// you need to set it up, or use WithAgentAddr to specify the hostport location
// of the agent. See WithAgentlessUpload for more information.
func WithAPIKey(key string) Option {
return func(cfg *config) {
cfg.apiKey = key
}
}

// WithAgentlessUpload is currently for internal usage only and not officially
JianyiGao marked this conversation as resolved.
Show resolved Hide resolved
// supported. You should not enable it unless somebody at Datadog instructed
// you to do so. It allows to skip the agent and talk to the Datadog API
Expand Down
15 changes: 0 additions & 15 deletions profiler/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,6 @@ func TestOptions(t *testing.T) {
assert.Equal(t, 5*time.Second, cfg.uploadTimeout)
})

t.Run("WithAPIKey", func(t *testing.T) {
var cfg config
WithAPIKey(testAPIKey)(&cfg)
assert.Equal(t, testAPIKey, cfg.apiKey)
assert.Equal(t, cfg.apiURL, cfg.targetURL)
})

t.Run("WithAPIKey/override", func(t *testing.T) {
t.Setenv("DD_API_KEY", "apikey")
var testAPIKey = "12345678901234567890123456789012"
var cfg config
WithAPIKey(testAPIKey)(&cfg)
assert.Equal(t, testAPIKey, cfg.apiKey)
})

t.Run("WithURL", func(t *testing.T) {
var cfg config
WithURL("my-url")(&cfg)
Expand Down
7 changes: 3 additions & 4 deletions profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ var (
// Start starts the profiler. If the profiler is already running, it will be
// stopped and restarted with the given options.
//
// It may return an error if an API key is not provided by means of the
// WithAPIKey option, or if a hostname is not found.
// It may return an error if a hostname is not found.
func Start(opts ...Option) error {
mu.Lock()
defer mu.Unlock()
Expand Down Expand Up @@ -143,7 +142,7 @@ func newProfiler(opts ...Option) (*profiler, error) {
// WithAgentlessUpload can be used to enable it for testing and debugging.
if cfg.agentless {
if !isAPIKeyValid(cfg.apiKey) {
return nil, errors.New("profiler.WithAgentlessUpload requires a valid API key. Use profiler.WithAPIKey or the DD_API_KEY env variable to set it")
return nil, errors.New("profiler.WithAgentlessUpload requires a valid API key. Use the DD_API_KEY env variable to set it")
}
// Always warn people against using this mode for now. All customers should
// use agent based uploading at this point.
Expand All @@ -156,7 +155,7 @@ func newProfiler(opts ...Option) (*profiler, error) {
// key configured, we warn the customers that this is probably a
// misconfiguration.
if cfg.apiKey != "" {
log.Warn("You are currently setting profiler.WithAPIKey or the DD_API_KEY env variable, but as of dd-trace-go v1.30.0 this value is getting ignored by the profiler. Please see the profiler.WithAPIKey go docs and verify that your integration is still working. If you can't remove DD_API_KEY from your environment, you can use WithAPIKey(\"\") to silence this warning.")
log.Warn("You are currently setting the DD_API_KEY env variable, but as of dd-trace-go v1.30.0 this value is getting ignored by the profiler. Please verify that your integration is still working.")
}
cfg.targetURL = cfg.agentURL
}
Expand Down
28 changes: 20 additions & 8 deletions profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,26 @@ func TestStart(t *testing.T) {
})

t.Run("options/GoodAPIKey/Agent", func(t *testing.T) {
t.Setenv("DD_API_KEY", "12345678901234567890123456789012")
rl := &log.RecordLogger{}
defer log.UseLogger(rl)()

err := Start(WithAPIKey("12345678901234567890123456789012"))
err := Start()
defer Stop()
assert.Nil(t, err)
assert.Equal(t, activeProfiler.cfg.agentURL, activeProfiler.cfg.targetURL)
// The package should log a warning that using an API has no
// effect unless uploading directly to Datadog (i.e. agentless)
assert.LessOrEqual(t, 1, len(rl.Logs()))
assert.Contains(t, strings.Join(rl.Logs(), " "), "profiler.WithAPIKey")
assert.Contains(t, strings.Join(rl.Logs(), " "), "DD_API_KEY")
})

t.Run("options/GoodAPIKey/Agentless", func(t *testing.T) {
t.Setenv("DD_API_KEY", "12345678901234567890123456789012")
rl := &log.RecordLogger{}
defer log.UseLogger(rl)()

err := Start(
WithAPIKey("12345678901234567890123456789012"),
WithAgentlessUpload(),
)
err := Start(WithAgentlessUpload())
defer Stop()
assert.Nil(t, err)
assert.Equal(t, activeProfiler.cfg.apiURL, activeProfiler.cfg.targetURL)
Expand All @@ -117,10 +116,23 @@ func TestStart(t *testing.T) {
assert.Contains(t, strings.Join(rl.Logs(), " "), "profiler.WithAgentlessUpload")
})

t.Run("options/BadAPIKey", func(t *testing.T) {
err := Start(WithAPIKey("aaaa"), WithAgentlessUpload())
t.Run("options/NoAPIKey/Agentless", func(t *testing.T) {
err := Start(WithAgentlessUpload())
defer Stop()
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "profiler.WithAgentlessUpload requires a valid API key")

// Check that mu gets unlocked, even if newProfiler() returns an error.
mu.Lock()
mu.Unlock()
})

t.Run("options/BadAPIKey/Agentless", func(t *testing.T) {
t.Setenv("DD_API_KEY", "aaaa")
err := Start(WithAgentlessUpload())
defer Stop()
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "profiler.WithAgentlessUpload requires a valid API key")

// Check that mu gets unlocked, even if newProfiler() returns an error.
mu.Lock()
Expand Down
Loading