From 0da0f7655929139f68d0659a95f4a186fde32b06 Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Tue, 17 Sep 2024 12:21:53 -0400 Subject: [PATCH] Set slogger on rungroup after logshipping is set up, so that rungroup logs will be shipped --- cmd/launcher/desktop.go | 3 ++- cmd/launcher/launcher.go | 6 +++++- ee/watchdog/watchdog_service_windows.go | 3 ++- pkg/rungroup/rungroup.go | 9 +++++++-- pkg/rungroup/rungroup_test.go | 12 ++++++------ 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cmd/launcher/desktop.go b/cmd/launcher/desktop.go index a397fadb0..7e05bd08f 100644 --- a/cmd/launcher/desktop.go +++ b/cmd/launcher/desktop.go @@ -111,7 +111,8 @@ func runDesktop(_ *multislogger.MultiSlogger, args []string) error { ) } - runGroup := rungroup.NewRunGroup(slogger) + runGroup := rungroup.NewRunGroup() + runGroup.SetSlogger(slogger) // listen for signals runGroup.Add("desktopSignalListener", func() error { diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go index 9d39daa44..c67a1c6f7 100644 --- a/cmd/launcher/launcher.go +++ b/cmd/launcher/launcher.go @@ -206,7 +206,7 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl } // create a rungroup for all the actors we create to allow for easy start/stop - runGroup := rungroup.NewRunGroup(slogger) + runGroup := rungroup.NewRunGroup() // Need to set up the log shipper so that we can get the logger early // and pass it to the various systems. @@ -246,6 +246,10 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl startupSpan.AddEvent("log_shipper_init_completed") } + // Now that log shipping is set up, set the slogger on the rungroup so that rungroup logs + // will also be shipped. + runGroup.SetSlogger(k.Slogger()) + startupSettingsWriter, err := startupsettings.OpenWriter(ctx, k) if err != nil { return fmt.Errorf("creating startup db: %w", err) diff --git a/ee/watchdog/watchdog_service_windows.go b/ee/watchdog/watchdog_service_windows.go index d3e670974..de2cfb780 100644 --- a/ee/watchdog/watchdog_service_windows.go +++ b/ee/watchdog/watchdog_service_windows.go @@ -227,7 +227,8 @@ func (w *winWatchdogSvc) checkLauncherStatus(ctx context.Context) error { func runLauncherWatchdogService(ctx context.Context, w *winWatchdogSvc) error { // create a rungroup for all the actors we create to allow for easy start/stop - runGroup := rungroup.NewRunGroup(w.slogger.Logger) + runGroup := rungroup.NewRunGroup() + runGroup.SetSlogger(w.slogger.Logger) powerEventWatcher, err := powereventwatcher.New(ctx, w.slogger.Logger, w.sleepStateUpdater) if err != nil { w.slogger.Log(ctx, slog.LevelDebug, diff --git a/pkg/rungroup/rungroup.go b/pkg/rungroup/rungroup.go index 16a92d747..6da0a58ff 100644 --- a/pkg/rungroup/rungroup.go +++ b/pkg/rungroup/rungroup.go @@ -12,6 +12,7 @@ import ( "time" "github.com/kolide/launcher/ee/gowrapper" + "github.com/kolide/launcher/pkg/log/multislogger" "golang.org/x/sync/semaphore" ) @@ -38,9 +39,9 @@ const ( executeReturnTimeout = 5 * time.Second // After interrupted, how long for all actors to exit their `execute` functions ) -func NewRunGroup(slogger *slog.Logger) *Group { +func NewRunGroup() *Group { return &Group{ - slogger: slogger.With("component", "run_group"), + slogger: multislogger.NewNopLogger(), actors: make([]rungroupActor, 0), } } @@ -49,6 +50,10 @@ func (g *Group) Add(name string, execute func() error, interrupt func(error)) { g.actors = append(g.actors, rungroupActor{name, execute, interrupt}) } +func (g *Group) SetSlogger(slogger *slog.Logger) { + g.slogger = slogger.With("component", "run_group") +} + func (g *Group) Run() error { if len(g.actors) == 0 { return nil diff --git a/pkg/rungroup/rungroup_test.go b/pkg/rungroup/rungroup_test.go index 942fa83dc..6ec4b4bfa 100644 --- a/pkg/rungroup/rungroup_test.go +++ b/pkg/rungroup/rungroup_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - "github.com/kolide/launcher/pkg/log/multislogger" "github.com/kolide/launcher/pkg/threadsafebuffer" "github.com/stretchr/testify/require" ) @@ -15,14 +14,14 @@ import ( func TestRun_NoActors(t *testing.T) { t.Parallel() - testRunGroup := NewRunGroup(multislogger.NewNopLogger()) + testRunGroup := NewRunGroup() require.NoError(t, testRunGroup.Run()) } func TestRun_MultipleActors(t *testing.T) { t.Parallel() - testRunGroup := NewRunGroup(multislogger.NewNopLogger()) + testRunGroup := NewRunGroup() groupReceivedInterrupts := make(chan struct{}, 3) @@ -93,7 +92,7 @@ func TestRun_MultipleActors(t *testing.T) { func TestRun_MultipleActors_InterruptTimeout(t *testing.T) { t.Parallel() - testRunGroup := NewRunGroup(multislogger.NewNopLogger()) + testRunGroup := NewRunGroup() groupReceivedInterrupts := make(chan struct{}, 3) @@ -166,7 +165,7 @@ func TestRun_MultipleActors_InterruptTimeout(t *testing.T) { func TestRun_MultipleActors_ExecuteReturnTimeout(t *testing.T) { t.Parallel() - testRunGroup := NewRunGroup(multislogger.NewNopLogger()) + testRunGroup := NewRunGroup() groupReceivedInterrupts := make(chan struct{}, 3) // Keep track of when `execute`s return so we give testRunGroup.Run enough time to do its thing @@ -250,7 +249,8 @@ func TestRun_RecoversAndLogsPanic(t *testing.T) { Level: slog.LevelDebug, })) - testRunGroup := NewRunGroup(slogger) + testRunGroup := NewRunGroup() + testRunGroup.SetSlogger(slogger) // Actor that will panic in its execute function testRunGroup.Add("panickingActor", func() error {