Skip to content

Commit

Permalink
Clean up a couple places not yet using gowrapper (#2033)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored Jan 7, 2025
1 parent 9cb1528 commit 70fc468
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
13 changes: 10 additions & 3 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/kolide/launcher/ee/control/consumers/uninstallconsumer"
"github.com/kolide/launcher/ee/debug/checkups"
desktopRunner "github.com/kolide/launcher/ee/desktop/runner"
"github.com/kolide/launcher/ee/gowrapper"
"github.com/kolide/launcher/ee/localserver"
"github.com/kolide/launcher/ee/powereventwatcher"
"github.com/kolide/launcher/ee/tuf"
Expand Down Expand Up @@ -206,8 +207,12 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl

k.LauncherHistoryStore().Set([]byte("process_start_time"), []byte(processStartTime.Format(time.RFC3339)))

go runOsqueryVersionCheckAndAddToKnapsack(ctx, slogger, k, k.LatestOsquerydPath(ctx))
go timemachine.AddExclusions(ctx, k)
gowrapper.Go(ctx, slogger, func() {
runOsqueryVersionCheckAndAddToKnapsack(ctx, slogger, k, k.LatestOsquerydPath(ctx))
})
gowrapper.Go(ctx, slogger, func() {
timemachine.AddExclusions(ctx, k)
})

if k.Debug() && runtime.GOOS != "windows" {
// If we're in debug mode, then we assume we want to echo _all_ logs to stderr.
Expand Down Expand Up @@ -299,7 +304,9 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl
// Add the log checkpoints to the rungroup, and run it once early, to try to get data into the logs.
// The checkpointer can take up to 5 seconds to run, so do this in the background.
checkpointer := checkups.NewCheckupLogger(slogger, k)
go checkpointer.Once(ctx)
gowrapper.Go(ctx, slogger, func() {
checkpointer.Once(ctx)
})
runGroup.Add("logcheckpoint", checkpointer.Run, checkpointer.Interrupt)

watchdogController, err := watchdog.NewController(ctx, k, opts.ConfigFilePath)
Expand Down
4 changes: 3 additions & 1 deletion cmd/launcher/svc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ func (w *winSvc) Execute(args []string, r <-chan svc.ChangeRequest, changes chan
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}

// Confirm that service configuration is up-to-date
go checkServiceConfiguration(w.slogger.Logger, w.opts)
gowrapper.Go(ctx, w.systemSlogger.Logger, func() {
checkServiceConfiguration(w.slogger.Logger, w.opts)
})

ctx = ctxlog.NewContext(ctx, w.logger)
runLauncherResults := make(chan struct{})
Expand Down
4 changes: 3 additions & 1 deletion ee/desktop/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,9 @@ func (r *DesktopUsersProcessesRunner) desktopCommand(executablePath, uid, socket
return nil, fmt.Errorf("getting stdout pipe: %w", err)
}

go r.processLogs(uid, stdErr, stdOut)
gowrapper.Go(context.TODO(), r.slogger, func() {
r.processLogs(uid, stdErr, stdOut)
})

return cmd, nil
}
Expand Down
5 changes: 4 additions & 1 deletion ee/localserver/krypto-ec-middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/kolide/krypto"
"github.com/kolide/krypto/pkg/challenge"
"github.com/kolide/launcher/ee/agent"
"github.com/kolide/launcher/ee/gowrapper"
"github.com/kolide/launcher/pkg/log/multislogger"
"github.com/kolide/launcher/pkg/traces"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -222,7 +223,9 @@ func (e *kryptoEcMiddleware) Wrap(next http.Handler) http.Handler {
context.WithValue(callbackReq.Context(), multislogger.KolideSessionIdKey, kolideSessionId[0]),
)
}
go e.sendCallback(callbackReq, callbackData)
gowrapper.Go(r.Context(), e.slogger, func() {
e.sendCallback(callbackReq, callbackData)
})
}()
}

Expand Down
13 changes: 9 additions & 4 deletions ee/log/osquerylogs/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"strings"
"time"

"github.com/kolide/launcher/ee/gowrapper"
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/process"
)

// OsqueryLogAdapater creates an io.Writer implementation useful for attaching
// to the osquery stdout/stderr
type OsqueryLogAdapter struct {
slogger slog.Logger
slogger *slog.Logger
level slog.Level
rootDirectory string
lastLockfileLogTime time.Time
Expand All @@ -44,7 +45,7 @@ func extractOsqueryCaller(msg string) string {

func NewOsqueryLogAdapter(slogger *slog.Logger, rootDirectory string, opts ...Option) *OsqueryLogAdapter {
l := &OsqueryLogAdapter{
slogger: *slogger,
slogger: slogger,
level: slog.LevelInfo,
rootDirectory: rootDirectory,
}
Expand Down Expand Up @@ -79,7 +80,9 @@ func (l *OsqueryLogAdapter) Write(p []byte) (int, error) {
l.slogger.Log(context.TODO(), slog.LevelError,
"detected non-osqueryd process using pidfile, logging info about process",
)
go l.logInfoAboutUnrecognizedProcessLockingPidfile(p)
gowrapper.Go(context.TODO(), l.slogger, func() {
l.logInfoAboutUnrecognizedProcessLockingPidfile(p)
})
}

// We have noticed the lock file occasionally locked when it shouldn't be -- we think this can happen
Expand All @@ -94,7 +97,9 @@ func (l *OsqueryLogAdapter) Write(p []byte) (int, error) {
l.slogger.Log(context.TODO(), slog.LevelError,
"detected stale lockfile, logging info about file",
)
go l.logInfoAboutProcessHoldingLockfile(context.TODO(), p)
gowrapper.Go(context.TODO(), l.slogger, func() {
l.logInfoAboutProcessHoldingLockfile(context.TODO(), p)
})
}
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/traces/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/kolide/launcher/ee/agent/flags/keys"
"github.com/kolide/launcher/ee/agent/storage"
"github.com/kolide/launcher/ee/agent/types"
"github.com/kolide/launcher/ee/gowrapper"
"github.com/kolide/launcher/pkg/traces"
"github.com/kolide/launcher/pkg/traces/bufspanprocessor"
osquerygotraces "github.com/osquery/osquery-go/traces"
Expand Down Expand Up @@ -118,7 +119,9 @@ func NewTraceExporter(ctx context.Context, k types.Knapsack, initialTraceBuffer
func (t *TraceExporter) SetOsqueryClient(client querier) {
t.osqueryClient = client

go t.addAttributesFromOsquery()
gowrapper.Go(context.TODO(), t.slogger, func() {
t.addAttributesFromOsquery()
})
}

// addDeviceIdentifyingAttributes gets device identifiers from the server-provided
Expand Down

0 comments on commit 70fc468

Please sign in to comment.