Skip to content

Commit

Permalink
Set slogger on rungroup after logshipping is set up, so that rungroup…
Browse files Browse the repository at this point in the history
… logs will be shipped
  • Loading branch information
RebeccaMahany committed Sep 17, 2024
1 parent fbecac9 commit 8b2bcb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cmd/launcher/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions pkg/rungroup/rungroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/kolide/launcher/ee/gowrapper"
"github.com/kolide/launcher/pkg/log/multislogger"
"golang.org/x/sync/semaphore"
)

Expand All @@ -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),
}
}
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/rungroup/rungroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ import (
"testing"
"time"

"github.com/kolide/launcher/pkg/log/multislogger"
"github.com/kolide/launcher/pkg/threadsafebuffer"
"github.com/stretchr/testify/require"
)

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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8b2bcb8

Please sign in to comment.