Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace logger with slogger in log checkpointer #1624

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ 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(logger, k)
checkpointer := checkups.NewCheckupLogger(slogger, k)
go checkpointer.Once(ctx)
runGroup.Add("logcheckpoint", checkpointer.Run, checkpointer.Interrupt)

Expand Down
21 changes: 9 additions & 12 deletions ee/debug/checkups/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,24 @@ package checkups
import (
"context"
"io"
"log/slog"
"time"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/launcher/ee/agent/types"
)

// logger is an interface that allows mocking of logger
type (
logger interface {
Log(keyvals ...interface{}) error
}

logCheckPointer struct {
logger logger
slogger *slog.Logger
knapsack types.Knapsack
interrupt chan struct{}
interrupted bool
}
)

func NewCheckupLogger(logger logger, k types.Knapsack) *logCheckPointer {
func NewCheckupLogger(slogger *slog.Logger, k types.Knapsack) *logCheckPointer {
return &logCheckPointer{
logger: log.With(logger, "component", "log checkpoint"),
slogger: slogger.With("component", "log_checkpoint"),
knapsack: k,
interrupt: make(chan struct{}, 1),
}
Expand All @@ -45,7 +39,9 @@ func (c *logCheckPointer) Run() error {
case <-ticker.C:
continue
case <-c.interrupt:
level.Debug(c.logger).Log("msg", "interrupt received, exiting execute loop")
c.slogger.Log(context.TODO(), slog.LevelDebug,
"interrupt received, exiting execute loop",
)
return nil
}
}
Expand All @@ -68,7 +64,8 @@ func (c *logCheckPointer) Once(ctx context.Context) {
for _, checkup := range checkups {
checkup.Run(ctx, io.Discard)

level.Debug(c.logger).Log(
c.slogger.Log(ctx, slog.LevelDebug,
"ran checkup",
"checkup", checkup.Name(),
"summary", checkup.Summary(),
"data", checkup.Data(),
Expand Down
4 changes: 2 additions & 2 deletions ee/debug/checkups/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"github.com/go-kit/kit/log"
storageci "github.com/kolide/launcher/ee/agent/storage/ci"
typesmocks "github.com/kolide/launcher/ee/agent/types/mocks"
"github.com/kolide/launcher/pkg/log/multislogger"
"github.com/stretchr/testify/require"
)

Expand All @@ -29,7 +29,7 @@ func TestInterrupt_Multiple(t *testing.T) {
mockKnapsack.On("Autoupdate").Return(true).Maybe()
mockKnapsack.On("LatestOsquerydPath").Return("").Maybe()
mockKnapsack.On("ServerProvidedDataStore").Return(nil).Maybe()
checkupLogger := NewCheckupLogger(log.NewNopLogger(), mockKnapsack)
checkupLogger := NewCheckupLogger(multislogger.New().Logger, mockKnapsack)
mockKnapsack.AssertExpectations(t)

// Start and then interrupt
Expand Down
12 changes: 6 additions & 6 deletions ee/debug/checkups/checkups.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"path"
"runtime"
"strings"
"time"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/version"
"github.com/kolide/launcher/ee/agent/types"
)
Expand Down Expand Up @@ -201,18 +200,19 @@ func flareCheckup(ctx context.Context, c checkupInt, combinedSummary io.Writer,
}
}

func logCheckup(ctx context.Context, c checkupInt, logger log.Logger) { // nolint:unused
func logCheckup(ctx context.Context, c checkupInt, slogger *slog.Logger) { // nolint:unused
if err := c.Run(ctx, io.Discard); err != nil {
level.Debug(logger).Log(
slogger.Log(ctx, slog.LevelDebug,
"error running checkup",
"name", c.Name(),
"msg", "error running checkup",
"err", err,
"status", Erroring,
)
return
}

level.Debug(logger).Log(
slogger.Log(ctx, slog.LevelDebug,
"ran checkup",
"name", c.Name(),
"msg", c.Summary(),
"status", c.Status(),
Expand Down