Skip to content

Commit

Permalink
Fix runtime error reporting in Otel manager (#6793)
Browse files Browse the repository at this point in the history
(cherry picked from commit 371399c)
  • Loading branch information
swiatekm committed Feb 12, 2025
1 parent aa81784 commit e0a3322
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/pkg/otel/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (m *OTelManager) Run(ctx context.Context) error {
// pass the error to the errCh so the coordinator, unless it's a cancel error
if !errors.Is(err, context.Canceled) {
select {
case m.errCh <- nil:
case m.errCh <- err:
case <-ctx.Done():
}
}
Expand Down
41 changes: 41 additions & 0 deletions internal/pkg/otel/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,44 @@ func TestOTelManager_Run(t *testing.T) {
t.Errorf("otel manager returned unexpected error: %v", runErr)
}
}

func TestOTelManager_ConfigError(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
l, _ := loggertest.New("otel")
m := NewOTelManager(l)

go func() {
err := m.Run(ctx)
require.ErrorIs(t, err, context.Canceled, "otel manager should be cancelled")
}()

// watch is synchronous, so we need to read from it to avoid blocking the manager
go func() {
for {
select {
case <-m.Watch():
case <-ctx.Done():
return
}
}
}()

cfg := confmap.New() // invalid config
m.Update(cfg)
timeoutCh := time.After(time.Second * 5)
var err error
outer:
for {
select {
case e := <-m.Errors():
if e != nil {
err = e
break outer
}
case <-timeoutCh:
break outer
}
}
assert.Error(t, err, "otel manager should have returned an error")
}

0 comments on commit e0a3322

Please sign in to comment.