-
Notifications
You must be signed in to change notification settings - Fork 438
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
profiler: add enable flag to control profiler activation #2840
base: main
Are you sure you want to change the base?
Changes from 1 commit
df7801c
ab2acd9
3aac285
f71e851
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ type config struct { | |
logStartup bool | ||
traceConfig executionTraceConfig | ||
endpointCountEnabled bool | ||
enable bool | ||
} | ||
|
||
// logStartup records the configuration to the configured logger in JSON format | ||
|
@@ -146,6 +147,7 @@ func logStartup(c *config) { | |
"execution_trace_size_limit": c.traceConfig.Limit, | ||
"endpoint_count_enabled": c.endpointCountEnabled, | ||
"custom_profiler_label_keys": c.customProfilerLabels, | ||
"enable": c.enable, | ||
} | ||
b, err := json.Marshal(info) | ||
if err != nil { | ||
|
@@ -208,6 +210,7 @@ func defaultConfig() (*config, error) { | |
} else { | ||
c.agentURL = url.String() + "/profiling/v1/input" | ||
} | ||
c.enable = internal.BoolEnv("DD_PROFILING_ENABLED", true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're going to support
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied suggested changes here |
||
if v := os.Getenv("DD_PROFILING_UPLOAD_TIMEOUT"); v != "" { | ||
d, err := time.ParseDuration(v) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,20 @@ func TestStart(t *testing.T) { | |
mu.Unlock() | ||
}) | ||
|
||
t.Run("dd_profiling_not_enabled", func(t *testing.T) { | ||
t.Setenv("DD_PROFILING_ENABLED", "false") | ||
if err := Start(); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer Stop() | ||
|
||
mu.Lock() | ||
// if DD_PROFILING_ENABLED is false, the profiler should not be started even if Start() is called | ||
// So we should not have an activeProfiler | ||
assert.Nil(t, activeProfiler) | ||
mu.Unlock() | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding this and the other test case. NIT: Some of the existing test suite has a lot of tests like this that assert on the internal state of things. However, in general we prefer tests that verify user-visible behavior these days. I.e. having a test that checks that a disabled profiler doesn't send data would be nice. In practice this might be a difficult test to write in a non-flaky manner, so I'm okay with keeping the testing as proposed in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, should we keep the test that checks activeProfiler, and additionally create a test that verifies no profiling data is sent when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a test for
Feel free to add it to the PR if it makes sense to you. We can keep the other tests for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've implemented additional changes in f71e851 (#2840). However, the tests you've already suggested seem sufficient, so I couldn't find any points to modify or add. If there are any areas that need improvement, please feel free to let me know! |
||
|
||
t.Run("options", func(t *testing.T) { | ||
if err := Start(); err != nil { | ||
t.Fatal(err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same change needs to be added to
profiler/telemetry.go
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, let's just remove this. If
enable
is false we won't send anything at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow. Having
enable
in the debug log is useful for debugging, e.g. when a customer reports that profiling isn't working.And having it in telemetry is useful for us to understand how our users use this flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think keeping this information in the debug log would make it easier to handle future reports about the profiler.
I'm fine with either option, so please feel free to share your thoughts and I'll implement them accordingly!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I added this comment too hastily and didn't notice that the startup log happens before the check for
DD_PROFILING_ENABLED
. Let's keep this after all.As this PR stands right now, the telemetry client won't start if
DD_PROFILING_ENABLED=false
. My gut feeling is that we shouldn't start telemetry if we don't start the profiler. IMO this is lower priority than making sureDD_PROFILING_ENABLED=false
works, and we can address telemetry in a followup. WDYT @felixge?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also added it to
profiler/telemetry.go
.3aac285
(#2840)