-
Notifications
You must be signed in to change notification settings - Fork 197
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
Make log_level
centrally configurable
#859
Conversation
Expose the concrete LevelLogger type, so we can add a means of updating the level via central config.
Also expose the default level as a constant, and the level constants.
$ELASTIC_APM_LOG_LEVEL now defines the local value, and this can be overridden via central config. If central config is updated and then removed, we'll revert back to the local value like with other config. If a custom logger is defined, the log_level attribute is ignored regardless of whether central config is used.
Codecov Report
@@ Coverage Diff @@
## master #859 +/- ##
==========================================
- Coverage 83.82% 83.72% -0.11%
==========================================
Files 142 142
Lines 7888 7913 +25
==========================================
+ Hits 6612 6625 +13
- Misses 868 879 +11
- Partials 408 409 +1
Continue to review full report at Codecov.
|
return "warn" | ||
case errorLevel: | ||
case ErrorLevel: |
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.
CriticalLevel
is missing
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.
Nice catch, thanks!
@@ -426,6 +426,14 @@ func newTracer(opts TracerOptions) *Tracer { | |||
t.setLocalInstrumentationConfig(envSanitizeFieldNames, func(cfg *instrumentationConfigValues) { | |||
cfg.sanitizedFieldNames = opts.sanitizedFieldNames | |||
}) | |||
if apmlog.DefaultLogger != nil { | |||
defaultLogLevel := apmlog.DefaultLogger.Level() |
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.
Hasn't this already potentially changed from the local ENV to the remote config? I don't see how this falls back to the original value in case a remote config value was provided but isn't any longer.
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 100% sure I follow your question.
apmlog.DefaultLogger.Level()
is called when constructing the Tracer, so there's no remote config yet received. We're just capturing the initial (default/environment variable) value.- the function literal passed into
t.setLocalInstrumentationConfig
below will be invoked immediately (having no effect, since it's just setting the level to the same value), and also when remote config is set and later removed. The latter bit is taken care of byLines 407 to 417 in 879c34a
for k := range old { if _, ok := attrs[k]; ok { continue } updates = append(updates, func(cfg *instrumentationConfig) { if f, ok := cfg.local[envName(k)]; ok { f(&cfg.instrumentationConfigValues) } }) debugf("central config update: reverted %s to local config", k) }
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 missed defaultLogLevel := apmlog.DefaultLogger.Level()
in https://github.com/elastic/apm-agent-go/pull/859/files#diff-4e84387cbc4fa01c5f9e572c02575e6c8536608159891072d2fbfa69af83a86fR430 - all good then, thanks.
@@ -97,9 +100,31 @@ func TestTracerCentralConfigUpdate(t *testing.T) { | |||
assert.Len(t, payloads.Transactions[0].Context.Request.Cookies, 1) | |||
return payloads.Transactions[0].Context.Request.Cookies[0].Value == "[REDACTED]" | |||
}) | |||
t.Run("log_level", func(t *testing.T) { |
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 might be missing something - but are there any tests for actually applying the remote log level and also falling back to the local config if a remote config is no longer provided?
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.
testTracerCentralConfigUpdate
(which this test calls) does that in
Lines 142 to 165 in 879c34a
tracer.SetLogger(apmtest.NewTestLogger(t)) | |
assert.False(t, isRemote(tracer)) | |
timeout := time.After(10 * time.Second) | |
// We each response payload twice, which causes us to block until | |
// the first one is fully consumed. | |
for i := 0; i < 2; i++ { | |
select { | |
case responses <- response{etag: "foo", body: serverResponse}: | |
case <-timeout: | |
t.Fatal("timed out waiting for config update") | |
} | |
} | |
assert.True(t, isRemote(tracer)) | |
for i := 0; i < 2; i++ { | |
select { | |
case responses <- response{etag: "bar", body: "{}"}: | |
case <-timeout: | |
t.Fatal("timed out waiting for config update") | |
} | |
} | |
assert.False(t, isRemote(tracer)) |
Each of these sub-tests defines a config key, value to set remotely, and a predicate that indicates whether the remote config has been applied. The code block I pointed to first checks that with the initial tracer config the predicate returns false; then sets the remote config and checks the predicate returns true; then clears out all remote config and again checks that the predicate returns false.
case "info": | ||
return infoLevel, nil | ||
return InfoLevel, nil | ||
case "warn": |
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.
(This is my first time looking at the go agent, and really reviewing much Go code at all, so feel free to ignore if I'm missing something obvious.)
The spec uses "warning" rather than "warn". Is this function parsing level strings from central config?
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.
@trentm Thanks, nice pick up! You're quite right, I missed that. I'll open another PR to fix it.
elastic/apm-agent-go#859 adds central config support for 'log_level' to the Go agent, so we can now enable it in the UI too. Co-authored-by: Kibana Machine <[email protected]>
elastic/apm-agent-go#859 adds central config support for 'log_level' to the Go agent, so we can now enable it in the UI too. Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
$ELASTIC_APM_LOG_LEVEL
now defines the local value, and this can be overridden via central config. If central config is updated and then removed, we'll revert back to the local value like with other config.If a custom logger is defined, or no log file is specified, the
log_level
attribute is ignored regardless of whether central config is used. If a custom logger is defined we will log a warning to it about the central config change being ineffective.Closes #829