Skip to content

Commit

Permalink
fix: handle when the arg is nil on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
kyungeunni committed Jul 2, 2024
1 parent efa0e99 commit 4880854
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions internal/beatcmd/reloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ func (r *Reloader) reloadOutput(cfg *reload.ConfigWithMeta) error {
func (r *Reloader) reloadAPMTracing(cfg *reload.ConfigWithMeta) error {
r.mu.Lock()
defer r.mu.Unlock()
if err := r.reload(r.inputConfig, r.outputConfig, cfg.Config); err != nil {
var c *config.C
if cfg != nil {
c = cfg.Config
}
if err := r.reload(r.inputConfig, r.outputConfig, c); err != nil {
return fmt.Errorf("failed to load apm tracing config: %w", err)
}
r.apmTracingConfig = cfg.Config
r.apmTracingConfig = c
r.logger.Info("loaded apm tracing config")
return nil
}
Expand Down Expand Up @@ -196,9 +200,8 @@ func (r *Reloader) reload(inputConfig, outputConfig, apmTracingConfig *config.C)
"instrumentation": c,
})
} else {
wrappedApmTracingConfig = config.MustNewConfigFrom(map[string]interface{}{
"instrumentation.enabled": false,
})
// empty instrumentation config
wrappedApmTracingConfig = config.NewConfig()
}
mergedConfig, err := config.MergeConfigs(inputConfig, wrappedOutputConfig, wrappedApmTracingConfig)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/beatcmd/reloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestReloader(t *testing.T) {
expectNoEvent(t, r2.stopped, "new runner should not have been stopped")

err = reload.RegisterV2.GetReloadableAPM().Reload(&reload.ConfigWithMeta{
Config: config.MustNewConfigFrom(`{"revision": "4"}`),
Config: config.MustNewConfigFrom(`{"elastic.enabled": true, "elastic.api_key": "boo"}`),
})
assert.NoError(t, err)
r3 := assertReload()
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestReloaderNewRunnerParams(t *testing.T) {
args := <-calls
assert.NotNil(t, args.Logger)
assert.Equal(t, info, args.Info)
assert.Equal(t, config.MustNewConfigFrom(`{"revision": 1, "input": 123, "output.console.enabled": true, "instrumentation.environment":"test"}`), args.Config)
assert.Equal(t, config.MustNewConfigFrom(`{"revision": 1, "input": 123, "output.console.enabled": true, "instrumentation.enabled":true, "instrumentation.environment":"test"}`), args.Config)
}

func expectNoEvent(t testing.TB, ch <-chan struct{}, message string) {
Expand Down

0 comments on commit 4880854

Please sign in to comment.