From 0ee14f9bd3eed64651f037e68676add2ca00cbfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Tue, 11 Feb 2025 15:46:53 +0100 Subject: [PATCH] Fix runtime error reporting in Otel manager (#6793) (cherry picked from commit 371399ccb683b7211509078ca9f27e59f889b90f) --- internal/pkg/otel/manager/manager.go | 2 +- internal/pkg/otel/manager/manager_test.go | 41 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/internal/pkg/otel/manager/manager.go b/internal/pkg/otel/manager/manager.go index af5a8052cec..8d9bc649753 100644 --- a/internal/pkg/otel/manager/manager.go +++ b/internal/pkg/otel/manager/manager.go @@ -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(): } } diff --git a/internal/pkg/otel/manager/manager_test.go b/internal/pkg/otel/manager/manager_test.go index c0d8bfd4309..f4f9b422dde 100644 --- a/internal/pkg/otel/manager/manager_test.go +++ b/internal/pkg/otel/manager/manager_test.go @@ -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") +}