Changes needed before gokit/log to slog transition. (#39527)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #38889 PLEASE READ BELOW before looking at file changes Before converting individual files/packages to slog, we generally need to make these 2 changes to make the conversion easier: - Replace uses of `kitlog.With` since they are not fully compatible with our kitlog adapter - Directly use the kitlog adapter logger type instead of the kitlog interface, which will let us have direct access to the underlying slog logger: `*logging.Logger` Note: that I did not replace absolutely all uses of `kitlog.Logger`, but I did remove all uses of `kitlog.With` except for these due to complexity: - server/logging/filesystem.go and the other log writers (webhook, firehose, kinesis, lambda, pubsub, nats) - server/datastore/mysql/nanomdm_storage.go (adapter pattern) - server/vulnerabilities/nvd/* (cascades to CLI tools) - server/service/osquery_utils/queries.go (callback type signatures cascade broadly) - cmd/maintained-apps/ (standalone, so can be transitioned later all at once) Most of the changes in this PR follow these patterns: - `kitlog.Logger` type → `*logging.Logger` - `kitlog.With(logger, ...)` → `logger.With(...)` - `kitlog.NewNopLogger() → logging.NewNopLogger()`, including similar variations such as `logging.NewLogfmtLogger(w)` and `logging.NewJSONLogger(w)` - removed many now-unused kitlog imports Unique changes that the PR review should focus on: - server/platform/logging/kitlog_adapter.go: Core adapter changes - server/platform/logging/logging.go: New convenience functions - server/service/integration_logger_test.go: Test changes for slog # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. - Was added in previous PR ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Migrated the codebase to a unified internal structured logging system for more consistent, reliable logs and observability. * No user-facing functionality changed; runtime behavior and APIs remain compatible. * **Tests** * Updated tests to use the new logging helpers to ensure consistent test logging and validation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
|
||||
"github.com/fleetdm/fleet/v4/server/datastore/redis"
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/fleetdm/fleet/v4/server/platform/logging"
|
||||
"github.com/go-kit/log/level"
|
||||
redigo "github.com/gomodule/redigo/redis"
|
||||
)
|
||||
@@ -18,14 +18,14 @@ import (
|
||||
type redisQueryResults struct {
|
||||
pool fleet.RedisPool
|
||||
duplicateResults bool
|
||||
logger log.Logger
|
||||
logger *logging.Logger
|
||||
}
|
||||
|
||||
var _ fleet.QueryResultStore = &redisQueryResults{}
|
||||
|
||||
// NewRedisQueryResults creats a new Redis implementation of the
|
||||
// QueryResultStore interface using the provided Redis connection pool.
|
||||
func NewRedisQueryResults(pool fleet.RedisPool, duplicateResults bool, logger log.Logger) *redisQueryResults {
|
||||
func NewRedisQueryResults(pool fleet.RedisPool, duplicateResults bool, logger *logging.Logger) *redisQueryResults {
|
||||
return &redisQueryResults{
|
||||
pool: pool,
|
||||
duplicateResults: duplicateResults,
|
||||
@@ -86,7 +86,7 @@ func writeOrDone(ctx context.Context, ch chan<- interface{}, item interface{}) b
|
||||
// connection over the provided channel. This effectively allows a select
|
||||
// statement to run on conn.Receive() (by selecting on outChan that is
|
||||
// passed into this function)
|
||||
func receiveMessages(ctx context.Context, conn *redigo.PubSubConn, outChan chan<- interface{}, logger log.Logger) {
|
||||
func receiveMessages(ctx context.Context, conn *redigo.PubSubConn, outChan chan<- any, logger *logging.Logger) {
|
||||
defer close(outChan)
|
||||
|
||||
for {
|
||||
@@ -136,7 +136,7 @@ func (r *redisQueryResults) ReadChannel(ctx context.Context, query fleet.Distrib
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
logger := log.With(r.logger, "campaignID", query.ID)
|
||||
logger := r.logger.With("campaignID", query.ID)
|
||||
|
||||
// Run a separate goroutine feeding redis messages into msgChannel.
|
||||
wg.Add(+1)
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/server/datastore/redis/redistest"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/fleetdm/fleet/v4/server/platform/logging"
|
||||
)
|
||||
|
||||
func SetupRedisForTest(t *testing.T, cluster, readReplica bool) *redisQueryResults {
|
||||
const dupResults = false
|
||||
pool := redistest.SetupRedis(t, "zz", cluster, false, readReplica)
|
||||
return NewRedisQueryResults(pool, dupResults, log.NewNopLogger())
|
||||
return NewRedisQueryResults(pool, dupResults, logging.NewNopLogger())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user