From 8ebfe0fb27ae7490f1cdcf1722b61d949be31ad5 Mon Sep 17 00:00:00 2001 From: Neha Sherpa Date: Tue, 24 Feb 2026 13:16:50 -0800 Subject: [PATCH 1/2] feat: Make changing log level dynamic --- cmd/cachew/main.go | 2 +- cmd/cachewd/main.go | 21 ++++++++++++++++++--- internal/cache/disk_eviction_test.go | 4 ++-- internal/cache/disk_test.go | 4 ++-- internal/cache/http_test.go | 4 ++-- internal/cache/memory_test.go | 4 ++-- internal/cache/remote_test.go | 4 ++-- internal/cache/s3_test.go | 4 ++-- internal/cache/tiered_test.go | 4 ++-- internal/gitclone/manager_test.go | 14 +++++++------- internal/jobscheduler/jobs_test.go | 22 +++++++++++----------- internal/jobscheduler/store_test.go | 8 ++++---- internal/logging/logging.go | 13 +++++++++---- internal/metrics/metrics_test.go | 10 +++++----- internal/reaper/reaper_test.go | 2 +- internal/strategy/artifactory_test.go | 6 +++--- internal/strategy/git/git_test.go | 12 ++++++------ internal/strategy/git/integration_test.go | 8 ++++---- internal/strategy/git/repack_test.go | 4 ++-- internal/strategy/git/snapshot_test.go | 4 ++-- internal/strategy/github_releases_test.go | 8 ++++---- internal/strategy/gomod/gomod_test.go | 4 ++-- internal/strategy/handler/handler_test.go | 2 +- internal/strategy/hermit_test.go | 2 +- internal/strategy/host_test.go | 8 ++++---- 25 files changed, 99 insertions(+), 79 deletions(-) diff --git a/cmd/cachew/main.go b/cmd/cachew/main.go index b454b2f..06fcd24 100644 --- a/cmd/cachew/main.go +++ b/cmd/cachew/main.go @@ -40,7 +40,7 @@ func main() { cli := CLI{} kctx := kong.Parse(&cli, kong.UsageOnError(), kong.HelpOptions{Compact: true}, kong.DefaultEnvars("CACHEW"), kong.Bind(&cli)) ctx := context.Background() - _, ctx = logging.Configure(ctx, cli.LoggingConfig) + _, _, ctx = logging.Configure(ctx, cli.LoggingConfig) remote := cache.NewRemote(cli.URL) defer remote.Close() diff --git a/cmd/cachewd/main.go b/cmd/cachewd/main.go index 47d2ce4..53a55e1 100644 --- a/cmd/cachewd/main.go +++ b/cmd/cachewd/main.go @@ -63,7 +63,7 @@ func main() { kctx.FatalIfErrorf(err) ctx := context.Background() - logger, ctx := logging.Configure(ctx, globalConfig.LoggingConfig) + logger, levelVar, ctx := logging.Configure(ctx, globalConfig.LoggingConfig) reaper.Start(ctx) @@ -84,7 +84,7 @@ func main() { return } - mux, err := newMux(ctx, cr, sr, providersConfigHCL, envars) + mux, err := newMux(ctx, cr, sr, providersConfigHCL, envars, levelVar) kctx.FatalIfErrorf(err) metricsClient, err := metrics.New(ctx, globalConfig.MetricsConfig) @@ -137,7 +137,7 @@ func printSchema(kctx *kong.Context, cr *cache.Registry, sr *strategy.Registry) } } -func newMux(ctx context.Context, cr *cache.Registry, sr *strategy.Registry, providersConfigHCL *hcl.AST, vars map[string]string) (*http.ServeMux, error) { +func newMux(ctx context.Context, cr *cache.Registry, sr *strategy.Registry, providersConfigHCL *hcl.AST, vars map[string]string, levelVar *slog.LevelVar) (*http.ServeMux, error) { mux := http.NewServeMux() mux.HandleFunc("GET /_liveness", func(w http.ResponseWriter, _ *http.Request) { @@ -150,6 +150,21 @@ func newMux(ctx context.Context, cr *cache.Registry, sr *strategy.Registry, prov _, _ = w.Write([]byte("OK")) //nolint:errcheck }) + mux.HandleFunc("GET /admin/log/level", func(w http.ResponseWriter, _ *http.Request) { + _, _ = fmt.Fprintln(w, levelVar.Level().String()) + }) + + mux.HandleFunc("PUT /admin/log/level", func(w http.ResponseWriter, r *http.Request) { + var level slog.Level + if err := level.UnmarshalText([]byte(strings.TrimSpace(r.FormValue("level")))); err != nil { + http.Error(w, fmt.Sprintf("invalid level: %s", err), http.StatusBadRequest) + return + } + levelVar.Set(level) + logging.FromContext(r.Context()).Info("Log level changed", "level", level) + _, _ = fmt.Fprintln(w, levelVar.Level().String()) + }) + if err := config.Load(ctx, cr, sr, providersConfigHCL, mux, vars); err != nil { return nil, errors.Errorf("load config: %w", err) } diff --git a/internal/cache/disk_eviction_test.go b/internal/cache/disk_eviction_test.go index 5a6409d..7917f16 100644 --- a/internal/cache/disk_eviction_test.go +++ b/internal/cache/disk_eviction_test.go @@ -13,7 +13,7 @@ import ( func TestDiskEvictionBySize(t *testing.T) { dir := t.TempDir() - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) // Create cache with 1MB limit and fast eviction c, err := cache.NewDisk(ctx, cache.DiskConfig{ @@ -61,7 +61,7 @@ func TestDiskEvictionBySize(t *testing.T) { func TestDiskEvictionAcrossNamespaces(t *testing.T) { dir := t.TempDir() - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) // Create cache with 1MB limit baseCache, err := cache.NewDisk(ctx, cache.DiskConfig{ diff --git a/internal/cache/disk_test.go b/internal/cache/disk_test.go index 2e7b12a..5250045 100644 --- a/internal/cache/disk_test.go +++ b/internal/cache/disk_test.go @@ -16,7 +16,7 @@ import ( func TestDiskCache(t *testing.T) { cachetest.Suite(t, func(t *testing.T) cache.Cache { dir := t.TempDir() - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) c, err := cache.NewDisk(ctx, cache.DiskConfig{ Root: dir, MaxTTL: 100 * time.Millisecond, @@ -32,7 +32,7 @@ func TestDiskCacheSoak(t *testing.T) { } dir := t.TempDir() - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) c, err := cache.NewDisk(ctx, cache.DiskConfig{ Root: dir, LimitMB: 50, diff --git a/internal/cache/http_test.go b/internal/cache/http_test.go index 407381f..bccdcdf 100644 --- a/internal/cache/http_test.go +++ b/internal/cache/http_test.go @@ -16,7 +16,7 @@ import ( ) func TestCachedFetch(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -60,7 +60,7 @@ func TestCachedFetch(t *testing.T) { } func TestCachedFetchNonOKStatus(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() diff --git a/internal/cache/memory_test.go b/internal/cache/memory_test.go index c0a8fff..39b3873 100644 --- a/internal/cache/memory_test.go +++ b/internal/cache/memory_test.go @@ -15,7 +15,7 @@ import ( func TestMemoryCache(t *testing.T) { cachetest.Suite(t, func(t *testing.T) cache.Cache { - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) c, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: 100 * time.Millisecond}) assert.NoError(t, err) return c @@ -27,7 +27,7 @@ func TestMemoryCacheSoak(t *testing.T) { t.Skip("Skipping soak test; set SOAK_TEST=1 to run") } - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) c, err := cache.NewMemory(ctx, cache.MemoryConfig{ LimitMB: 50, MaxTTL: 10 * time.Minute, diff --git a/internal/cache/remote_test.go b/internal/cache/remote_test.go index 4b27fa2..8b10373 100644 --- a/internal/cache/remote_test.go +++ b/internal/cache/remote_test.go @@ -19,7 +19,7 @@ import ( func TestRemoteCache(t *testing.T) { cachetest.Suite(t, func(t *testing.T) cache.Cache { ctx := t.Context() - _, ctx = logging.Configure(ctx, logging.Config{Level: slog.LevelError}) + _, _, ctx = logging.Configure(ctx, logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{ MaxTTL: 100 * time.Millisecond, }) @@ -43,7 +43,7 @@ func TestRemoteCacheSoak(t *testing.T) { } ctx := t.Context() - _, ctx = logging.Configure(ctx, logging.Config{Level: slog.LevelError}) + _, _, ctx = logging.Configure(ctx, logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{ LimitMB: 50, MaxTTL: 10 * time.Minute, diff --git a/internal/cache/s3_test.go b/internal/cache/s3_test.go index 1486fa1..47babf8 100644 --- a/internal/cache/s3_test.go +++ b/internal/cache/s3_test.go @@ -125,7 +125,7 @@ func TestS3Cache(t *testing.T) { startMinio(t) cachetest.Suite(t, func(t *testing.T) cache.Cache { - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) // Clean bucket to ensure test isolation cleanBucket(t) @@ -154,7 +154,7 @@ func TestS3CacheSoak(t *testing.T) { startMinio(t) - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) // Clean bucket to ensure test isolation cleanBucket(t) diff --git a/internal/cache/tiered_test.go b/internal/cache/tiered_test.go index d6ae52f..303a9cb 100644 --- a/internal/cache/tiered_test.go +++ b/internal/cache/tiered_test.go @@ -15,7 +15,7 @@ import ( func TestTieredCache(t *testing.T) { cachetest.Suite(t, func(t *testing.T) cache.Cache { - _, ctx := logging.Configure(t.Context(), logging.Config{}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{}) memory, err := cache.NewMemory(ctx, cache.MemoryConfig{LimitMB: 1024, MaxTTL: time.Hour}) assert.NoError(t, err) disk, err := cache.NewDisk(ctx, cache.DiskConfig{Root: t.TempDir(), LimitMB: 1024, MaxTTL: time.Hour}) @@ -29,7 +29,7 @@ func TestTieredCacheSoak(t *testing.T) { t.Skip("Skipping soak test; set SOAK_TEST=1 to run") } - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) memory, err := cache.NewMemory(ctx, cache.MemoryConfig{ LimitMB: 25, MaxTTL: 10 * time.Minute, diff --git a/internal/gitclone/manager_test.go b/internal/gitclone/manager_test.go index 2578e99..1d82031 100644 --- a/internal/gitclone/manager_test.go +++ b/internal/gitclone/manager_test.go @@ -42,7 +42,7 @@ func createBareRepo(t *testing.T, dir string) string { } func TestNewManager(t *testing.T) { - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ @@ -58,7 +58,7 @@ func TestNewManager(t *testing.T) { } func TestNewManager_RequiresRootDir(t *testing.T) { - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) config := Config{ FetchInterval: 15 * time.Minute, RefCheckInterval: 10 * time.Second, @@ -70,7 +70,7 @@ func TestNewManager_RequiresRootDir(t *testing.T) { } func TestManager_GetOrCreate(t *testing.T) { - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ MirrorRoot: tmpDir, @@ -96,7 +96,7 @@ func TestManager_GetOrCreate(t *testing.T) { } func TestManager_GetOrCreate_ExistingClone(t *testing.T) { - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ MirrorRoot: tmpDir, @@ -120,7 +120,7 @@ func TestManager_GetOrCreate_ExistingClone(t *testing.T) { } func TestManager_Get(t *testing.T) { - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ MirrorRoot: tmpDir, @@ -145,7 +145,7 @@ func TestManager_Get(t *testing.T) { } func TestManager_DiscoverExisting(t *testing.T) { - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ MirrorRoot: tmpDir, @@ -325,7 +325,7 @@ func TestRepository_CloneSetsMirrorConfig(t *testing.T) { } func TestRepository_Repack(t *testing.T) { - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() upstreamPath := createBareRepo(t, tmpDir) diff --git a/internal/jobscheduler/jobs_test.go b/internal/jobscheduler/jobs_test.go index 12df2dd..8958fff 100644 --- a/internal/jobscheduler/jobs_test.go +++ b/internal/jobscheduler/jobs_test.go @@ -44,7 +44,7 @@ func eventually(t *testing.T, timeout time.Duration, condition func() bool, msgA } func TestJobSchedulerBasic(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -60,7 +60,7 @@ func TestJobSchedulerBasic(t *testing.T) { } func TestJobSchedulerConcurrency(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -107,7 +107,7 @@ func TestJobSchedulerConcurrency(t *testing.T) { } func TestJobSchedulerQueueIsolation(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -159,7 +159,7 @@ func TestJobSchedulerQueueIsolation(t *testing.T) { } func TestJobSchedulerJobOrdering(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -197,7 +197,7 @@ func TestJobSchedulerJobOrdering(t *testing.T) { } func TestJobSchedulerErrorHandling(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -224,7 +224,7 @@ func TestJobSchedulerErrorHandling(t *testing.T) { } func TestJobSchedulerContextCancellation(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) scheduler := newTestScheduler(ctx, t, jobscheduler.Config{Concurrency: 2}) @@ -245,7 +245,7 @@ func TestJobSchedulerContextCancellation(t *testing.T) { } func TestJobSchedulerPeriodicJob(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -264,7 +264,7 @@ func TestJobSchedulerPeriodicJob(t *testing.T) { } func TestJobSchedulerPeriodicJobWithError(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -283,7 +283,7 @@ func TestJobSchedulerPeriodicJobWithError(t *testing.T) { } func TestJobSchedulerMultipleQueues(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -323,7 +323,7 @@ func TestJobSchedulerMultipleQueues(t *testing.T) { } func TestJobSchedulerHighConcurrency(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -375,7 +375,7 @@ func FuzzJobScheduler(f *testing.F) { queueCount = 50 } - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithTimeout(ctx, 10*time.Second) defer cancel() diff --git a/internal/jobscheduler/store_test.go b/internal/jobscheduler/store_test.go index c3ed72b..fab4392 100644 --- a/internal/jobscheduler/store_test.go +++ b/internal/jobscheduler/store_test.go @@ -81,7 +81,7 @@ func TestScheduleStoreInvalidPath(t *testing.T) { } func TestPeriodicJobDelaysWhenRecentlyRun(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -109,7 +109,7 @@ func TestPeriodicJobDelaysWhenRecentlyRun(t *testing.T) { } func TestPeriodicJobRunsImmediatelyWhenNeverRun(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -128,7 +128,7 @@ func TestPeriodicJobRunsImmediatelyWhenNeverRun(t *testing.T) { } func TestPeriodicJobRunsImmediatelyWhenIntervalElapsed(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -154,7 +154,7 @@ func TestPeriodicJobRunsImmediatelyWhenIntervalElapsed(t *testing.T) { } func TestPeriodicJobRecordsLastRun(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() diff --git a/internal/logging/logging.go b/internal/logging/logging.go index 45a9bbd..1ac58be 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -17,10 +17,15 @@ type Config struct { type logKey struct{} -func Configure(ctx context.Context, config Config) (*slog.Logger, context.Context) { +// Configure sets up logging with the given config and returns a logger, a LevelVar +// that can be used to dynamically change the log level at runtime, and the updated context. +func Configure(ctx context.Context, config Config) (*slog.Logger, *slog.LevelVar, context.Context) { + levelVar := &slog.LevelVar{} + levelVar.Set(config.Level) + var handler slog.Handler if config.JSON { - options := &slog.HandlerOptions{Level: config.Level} + options := &slog.HandlerOptions{Level: levelVar} if len(config.Remap) > 0 { options.ReplaceAttr = func(groups []string, a slog.Attr) slog.Attr { if len(groups) > 0 { @@ -35,7 +40,7 @@ func Configure(ctx context.Context, config Config) (*slog.Logger, context.Contex handler = &messageHandler{inner: slog.NewJSONHandler(os.Stdout, options)} } else { handler = tint.NewHandler(os.Stderr, &tint.Options{ - Level: config.Level, + Level: levelVar, ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { if a.Key == slog.TimeKey && len(groups) == 0 { return slog.Attr{} @@ -45,7 +50,7 @@ func Configure(ctx context.Context, config Config) (*slog.Logger, context.Contex }) } logger := slog.New(handler) - return logger, context.WithValue(ctx, logKey{}, logger) + return logger, levelVar, context.WithValue(ctx, logKey{}, logger) } func FromContext(ctx context.Context) *slog.Logger { diff --git a/internal/metrics/metrics_test.go b/internal/metrics/metrics_test.go index f7df530..f0733c6 100644 --- a/internal/metrics/metrics_test.go +++ b/internal/metrics/metrics_test.go @@ -15,7 +15,7 @@ import ( func TestMetricsClient(t *testing.T) { ctx := context.Background() - logger, ctx := logging.Configure(ctx, logging.Config{}) + logger, _, ctx := logging.Configure(ctx, logging.Config{}) _ = logger client, err := metrics.New(ctx, metrics.Config{ @@ -39,7 +39,7 @@ func TestMetricsDedicatedServer(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - logger, ctx := logging.Configure(ctx, logging.Config{}) + logger, _, ctx := logging.Configure(ctx, logging.Config{}) _ = logger client, err := metrics.New(ctx, metrics.Config{ @@ -58,7 +58,7 @@ func TestMetricsDedicatedServer(t *testing.T) { func TestMetricsOTLPOnly(t *testing.T) { ctx := context.Background() - logger, ctx := logging.Configure(ctx, logging.Config{}) + logger, _, ctx := logging.Configure(ctx, logging.Config{}) _ = logger // OTLP-only configuration @@ -79,7 +79,7 @@ func TestMetricsOTLPOnly(t *testing.T) { func TestMetricsBothExporters(t *testing.T) { ctx := context.Background() - logger, ctx := logging.Configure(ctx, logging.Config{}) + logger, _, ctx := logging.Configure(ctx, logging.Config{}) _ = logger // Both exporters enabled @@ -103,7 +103,7 @@ func TestMetricsBothExporters(t *testing.T) { func TestMetricsNoExportersError(t *testing.T) { ctx := context.Background() - logger, ctx := logging.Configure(ctx, logging.Config{}) + logger, _, ctx := logging.Configure(ctx, logging.Config{}) _ = logger // Should error when no exporters are enabled diff --git a/internal/reaper/reaper_test.go b/internal/reaper/reaper_test.go index c14c7fa..4c9284b 100644 --- a/internal/reaper/reaper_test.go +++ b/internal/reaper/reaper_test.go @@ -18,7 +18,7 @@ import ( func testContext(t *testing.T) context.Context { t.Helper() - _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) return ctx } diff --git a/internal/strategy/artifactory_test.go b/internal/strategy/artifactory_test.go index 363c941..e697e07 100644 --- a/internal/strategy/artifactory_test.go +++ b/internal/strategy/artifactory_test.go @@ -57,7 +57,7 @@ func setupArtifactoryTest(t *testing.T, config strategy.ArtifactoryConfig) (*moc // Point config to mock server config.Target = mock.server.URL - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: 24 * time.Hour}) assert.NoError(t, err) t.Cleanup(func() { memCache.Close() }) @@ -204,7 +204,7 @@ func TestArtifactoryNonOKResponse(t *testing.T) { } func TestArtifactoryString(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -219,7 +219,7 @@ func TestArtifactoryString(t *testing.T) { } func TestArtifactoryInvalidTargetURL(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() diff --git a/internal/strategy/git/git_test.go b/internal/strategy/git/git_test.go index aa8e1ba..fe61860 100644 --- a/internal/strategy/git/git_test.go +++ b/internal/strategy/git/git_test.go @@ -40,7 +40,7 @@ func newTestScheduler(ctx context.Context, t *testing.T) jobscheduler.Provider { } func TestNew(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() tests := []struct { @@ -138,7 +138,7 @@ func TestExtractRepoPath(t *testing.T) { } func TestNewWithExistingCloneOnDisk(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() // Create a fake bare clone directory on disk before initializing strategy @@ -162,7 +162,7 @@ func TestNewWithExistingCloneOnDisk(t *testing.T) { } func TestIntegrationWithMockUpstream(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) // Create a mock upstream server upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -200,7 +200,7 @@ func TestNewMissingGitBinary(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("PATH manipulation for binary checks not supported on Windows") } - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() t.Setenv("PATH", t.TempDir()) @@ -220,7 +220,7 @@ func TestNewMissingSnapshotBinaries(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("PATH manipulation for binary checks not supported on Windows") } - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() t.Run("MissingTar", func(t *testing.T) { @@ -256,7 +256,7 @@ func TestNewMissingSnapshotBinaries(t *testing.T) { } func TestParseGitRefs(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) _ = ctx tests := []struct { diff --git a/internal/strategy/git/integration_test.go b/internal/strategy/git/integration_test.go index 02507aa..6f2575a 100644 --- a/internal/strategy/git/integration_test.go +++ b/internal/strategy/git/integration_test.go @@ -48,7 +48,7 @@ func TestIntegrationGitCloneViaProxy(t *testing.T) { t.Skip("git not found in PATH") } - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() clonesDir := filepath.Join(tmpDir, "clones") workDir := filepath.Join(tmpDir, "work") @@ -127,7 +127,7 @@ func TestIntegrationGitFetchViaProxy(t *testing.T) { t.Skip("git not found in PATH") } - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() clonesDir := filepath.Join(tmpDir, "clones") workDir := filepath.Join(tmpDir, "work") @@ -182,7 +182,7 @@ func TestIntegrationPushForwardsToUpstream(t *testing.T) { t.Skip("git not found in PATH") } - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() clonesDir := filepath.Join(tmpDir, "clones") upstreamDir := filepath.Join(tmpDir, "upstream") @@ -300,7 +300,7 @@ func TestIntegrationSpoolReusesDuringClone(t *testing.T) { t.Skip("git not found in PATH") } - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelDebug}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelDebug}) tmpDir := t.TempDir() clonesDir := filepath.Join(tmpDir, "clones") workDir := filepath.Join(tmpDir, "work") diff --git a/internal/strategy/git/repack_test.go b/internal/strategy/git/repack_test.go index f77e1d6..e91abc3 100644 --- a/internal/strategy/git/repack_test.go +++ b/internal/strategy/git/repack_test.go @@ -16,7 +16,7 @@ import ( ) func TestRepackInterval(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() tests := []struct { @@ -49,7 +49,7 @@ func TestRepackInterval(t *testing.T) { } func TestRepackScheduledForExistingRepos(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() // Create a fake bare clone directory on disk before initializing strategy. diff --git a/internal/strategy/git/snapshot_test.go b/internal/strategy/git/snapshot_test.go index d59566e..6e17129 100644 --- a/internal/strategy/git/snapshot_test.go +++ b/internal/strategy/git/snapshot_test.go @@ -21,7 +21,7 @@ import ( ) func TestSnapshotHTTPEndpoint(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{}) @@ -111,7 +111,7 @@ func TestSnapshotGenerationViaLocalClone(t *testing.T) { t.Skip("git not found in PATH") } - _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() mirrorRoot := filepath.Join(tmpDir, "mirrors") upstreamURL := "https://github.com/org/repo" diff --git a/internal/strategy/github_releases_test.go b/internal/strategy/github_releases_test.go index ef8e795..ded5472 100644 --- a/internal/strategy/github_releases_test.go +++ b/internal/strategy/github_releases_test.go @@ -121,7 +121,7 @@ func setupTest(t *testing.T, config strategy.GitHubReleasesConfig) (*mockGitHubS originalTransport: originalTransport, } - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) t.Cleanup(func() { memCache.Close() }) @@ -226,7 +226,7 @@ func TestGitHubReleasesPublicRepoNotFound(t *testing.T) { assert.Equal(t, 1, mock.publicCallCount) key := cache.NewKey("https://github.com/publicorg/repo/releases/download/v1.0.0/missing.tar.gz") - _, ctx2 := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx2 := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx2, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -236,7 +236,7 @@ func TestGitHubReleasesPublicRepoNotFound(t *testing.T) { } func TestGitHubReleasesNoToken(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -248,7 +248,7 @@ func TestGitHubReleasesNoToken(t *testing.T) { } func TestGitHubReleasesString(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() diff --git a/internal/strategy/gomod/gomod_test.go b/internal/strategy/gomod/gomod_test.go index 1f3a3d7..c8a187c 100644 --- a/internal/strategy/gomod/gomod_test.go +++ b/internal/strategy/gomod/gomod_test.go @@ -170,7 +170,7 @@ func setupGoModTest(t *testing.T) (*mockGoModServer, *http.ServeMux, context.Con mock := newMockGoModServer(t) t.Cleanup(mock.close) - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: 24 * time.Hour}) assert.NoError(t, err) @@ -378,7 +378,7 @@ func TestNewMissingGitBinaryForPrivatePaths(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("PATH manipulation for binary checks not supported on Windows") } - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: 24 * time.Hour}) assert.NoError(t, err) diff --git a/internal/strategy/handler/handler_test.go b/internal/strategy/handler/handler_test.go index 52d25f7..4931c58 100644 --- a/internal/strategy/handler/handler_test.go +++ b/internal/strategy/handler/handler_test.go @@ -296,7 +296,7 @@ func TestHandlerMethodChaining(t *testing.T) { } func mustNewMemoryCache() cache.Cache { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) c, err := cache.NewMemory(ctx, cache.MemoryConfig{ MaxTTL: time.Hour, }) diff --git a/internal/strategy/hermit_test.go b/internal/strategy/hermit_test.go index e815f28..6abb729 100644 --- a/internal/strategy/hermit_test.go +++ b/internal/strategy/hermit_test.go @@ -24,7 +24,7 @@ var httpTransportMutexHermit sync.Mutex //nolint:gochecknoglobals func setupHermitTest(t *testing.T) (*http.ServeMux, context.Context, cache.Cache) { t.Helper() - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) t.Cleanup(func() { memCache.Close() }) diff --git a/internal/strategy/host_test.go b/internal/strategy/host_test.go index 1f8442b..efe02d8 100644 --- a/internal/strategy/host_test.go +++ b/internal/strategy/host_test.go @@ -25,7 +25,7 @@ func TestHostCaching(t *testing.T) { })) defer backend.Close() - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -62,7 +62,7 @@ func TestHostNonOKStatus(t *testing.T) { })) defer backend.Close() - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -88,7 +88,7 @@ func TestHostNonOKStatus(t *testing.T) { } func TestHostInvalidTargetURL(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -99,7 +99,7 @@ func TestHostInvalidTargetURL(t *testing.T) { } func TestHostString(t *testing.T) { - _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() From 6ca1fab31772166b8c2f8f24502ee59b692ab525 Mon Sep 17 00:00:00 2001 From: Neha Sherpa Date: Tue, 24 Feb 2026 15:27:39 -0800 Subject: [PATCH 2/2] fix: Address comments --- cmd/cachew/main.go | 2 +- cmd/cachewd/main.go | 12 ++++++------ internal/cache/disk_eviction_test.go | 4 ++-- internal/cache/disk_test.go | 4 ++-- internal/cache/http_test.go | 4 ++-- internal/cache/memory_test.go | 4 ++-- internal/cache/remote_test.go | 4 ++-- internal/cache/s3_test.go | 4 ++-- internal/cache/tiered_test.go | 4 ++-- internal/gitclone/manager_test.go | 14 +++++++------- internal/jobscheduler/jobs_test.go | 22 +++++++++++----------- internal/jobscheduler/store_test.go | 8 ++++---- internal/logging/logging.go | 16 +++++++++++----- internal/metrics/metrics_test.go | 10 +++++----- internal/reaper/reaper_test.go | 2 +- internal/strategy/artifactory_test.go | 6 +++--- internal/strategy/git/git_test.go | 12 ++++++------ internal/strategy/git/integration_test.go | 8 ++++---- internal/strategy/git/repack_test.go | 4 ++-- internal/strategy/git/snapshot_test.go | 4 ++-- internal/strategy/github_releases_test.go | 8 ++++---- internal/strategy/gomod/gomod_test.go | 4 ++-- internal/strategy/handler/handler_test.go | 2 +- internal/strategy/hermit_test.go | 2 +- internal/strategy/host_test.go | 8 ++++---- 25 files changed, 89 insertions(+), 83 deletions(-) diff --git a/cmd/cachew/main.go b/cmd/cachew/main.go index 06fcd24..b454b2f 100644 --- a/cmd/cachew/main.go +++ b/cmd/cachew/main.go @@ -40,7 +40,7 @@ func main() { cli := CLI{} kctx := kong.Parse(&cli, kong.UsageOnError(), kong.HelpOptions{Compact: true}, kong.DefaultEnvars("CACHEW"), kong.Bind(&cli)) ctx := context.Background() - _, _, ctx = logging.Configure(ctx, cli.LoggingConfig) + _, ctx = logging.Configure(ctx, cli.LoggingConfig) remote := cache.NewRemote(cli.URL) defer remote.Close() diff --git a/cmd/cachewd/main.go b/cmd/cachewd/main.go index 53a55e1..3a71fad 100644 --- a/cmd/cachewd/main.go +++ b/cmd/cachewd/main.go @@ -63,7 +63,7 @@ func main() { kctx.FatalIfErrorf(err) ctx := context.Background() - logger, levelVar, ctx := logging.Configure(ctx, globalConfig.LoggingConfig) + logger, ctx := logging.Configure(ctx, globalConfig.LoggingConfig) reaper.Start(ctx) @@ -84,7 +84,7 @@ func main() { return } - mux, err := newMux(ctx, cr, sr, providersConfigHCL, envars, levelVar) + mux, err := newMux(ctx, cr, sr, providersConfigHCL, envars) kctx.FatalIfErrorf(err) metricsClient, err := metrics.New(ctx, globalConfig.MetricsConfig) @@ -137,7 +137,7 @@ func printSchema(kctx *kong.Context, cr *cache.Registry, sr *strategy.Registry) } } -func newMux(ctx context.Context, cr *cache.Registry, sr *strategy.Registry, providersConfigHCL *hcl.AST, vars map[string]string, levelVar *slog.LevelVar) (*http.ServeMux, error) { +func newMux(ctx context.Context, cr *cache.Registry, sr *strategy.Registry, providersConfigHCL *hcl.AST, vars map[string]string) (*http.ServeMux, error) { mux := http.NewServeMux() mux.HandleFunc("GET /_liveness", func(w http.ResponseWriter, _ *http.Request) { @@ -151,7 +151,7 @@ func newMux(ctx context.Context, cr *cache.Registry, sr *strategy.Registry, prov }) mux.HandleFunc("GET /admin/log/level", func(w http.ResponseWriter, _ *http.Request) { - _, _ = fmt.Fprintln(w, levelVar.Level().String()) + _, _ = fmt.Fprintln(w, logging.GetLevel().String()) }) mux.HandleFunc("PUT /admin/log/level", func(w http.ResponseWriter, r *http.Request) { @@ -160,9 +160,9 @@ func newMux(ctx context.Context, cr *cache.Registry, sr *strategy.Registry, prov http.Error(w, fmt.Sprintf("invalid level: %s", err), http.StatusBadRequest) return } - levelVar.Set(level) + logging.SetLevel(level) logging.FromContext(r.Context()).Info("Log level changed", "level", level) - _, _ = fmt.Fprintln(w, levelVar.Level().String()) + _, _ = fmt.Fprintln(w, logging.GetLevel().String()) }) if err := config.Load(ctx, cr, sr, providersConfigHCL, mux, vars); err != nil { diff --git a/internal/cache/disk_eviction_test.go b/internal/cache/disk_eviction_test.go index 7917f16..5a6409d 100644 --- a/internal/cache/disk_eviction_test.go +++ b/internal/cache/disk_eviction_test.go @@ -13,7 +13,7 @@ import ( func TestDiskEvictionBySize(t *testing.T) { dir := t.TempDir() - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) // Create cache with 1MB limit and fast eviction c, err := cache.NewDisk(ctx, cache.DiskConfig{ @@ -61,7 +61,7 @@ func TestDiskEvictionBySize(t *testing.T) { func TestDiskEvictionAcrossNamespaces(t *testing.T) { dir := t.TempDir() - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) // Create cache with 1MB limit baseCache, err := cache.NewDisk(ctx, cache.DiskConfig{ diff --git a/internal/cache/disk_test.go b/internal/cache/disk_test.go index 5250045..2e7b12a 100644 --- a/internal/cache/disk_test.go +++ b/internal/cache/disk_test.go @@ -16,7 +16,7 @@ import ( func TestDiskCache(t *testing.T) { cachetest.Suite(t, func(t *testing.T) cache.Cache { dir := t.TempDir() - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) c, err := cache.NewDisk(ctx, cache.DiskConfig{ Root: dir, MaxTTL: 100 * time.Millisecond, @@ -32,7 +32,7 @@ func TestDiskCacheSoak(t *testing.T) { } dir := t.TempDir() - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) c, err := cache.NewDisk(ctx, cache.DiskConfig{ Root: dir, LimitMB: 50, diff --git a/internal/cache/http_test.go b/internal/cache/http_test.go index bccdcdf..407381f 100644 --- a/internal/cache/http_test.go +++ b/internal/cache/http_test.go @@ -16,7 +16,7 @@ import ( ) func TestCachedFetch(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -60,7 +60,7 @@ func TestCachedFetch(t *testing.T) { } func TestCachedFetchNonOKStatus(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() diff --git a/internal/cache/memory_test.go b/internal/cache/memory_test.go index 39b3873..c0a8fff 100644 --- a/internal/cache/memory_test.go +++ b/internal/cache/memory_test.go @@ -15,7 +15,7 @@ import ( func TestMemoryCache(t *testing.T) { cachetest.Suite(t, func(t *testing.T) cache.Cache { - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) c, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: 100 * time.Millisecond}) assert.NoError(t, err) return c @@ -27,7 +27,7 @@ func TestMemoryCacheSoak(t *testing.T) { t.Skip("Skipping soak test; set SOAK_TEST=1 to run") } - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) c, err := cache.NewMemory(ctx, cache.MemoryConfig{ LimitMB: 50, MaxTTL: 10 * time.Minute, diff --git a/internal/cache/remote_test.go b/internal/cache/remote_test.go index 8b10373..4b27fa2 100644 --- a/internal/cache/remote_test.go +++ b/internal/cache/remote_test.go @@ -19,7 +19,7 @@ import ( func TestRemoteCache(t *testing.T) { cachetest.Suite(t, func(t *testing.T) cache.Cache { ctx := t.Context() - _, _, ctx = logging.Configure(ctx, logging.Config{Level: slog.LevelError}) + _, ctx = logging.Configure(ctx, logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{ MaxTTL: 100 * time.Millisecond, }) @@ -43,7 +43,7 @@ func TestRemoteCacheSoak(t *testing.T) { } ctx := t.Context() - _, _, ctx = logging.Configure(ctx, logging.Config{Level: slog.LevelError}) + _, ctx = logging.Configure(ctx, logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{ LimitMB: 50, MaxTTL: 10 * time.Minute, diff --git a/internal/cache/s3_test.go b/internal/cache/s3_test.go index 47babf8..1486fa1 100644 --- a/internal/cache/s3_test.go +++ b/internal/cache/s3_test.go @@ -125,7 +125,7 @@ func TestS3Cache(t *testing.T) { startMinio(t) cachetest.Suite(t, func(t *testing.T) cache.Cache { - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) // Clean bucket to ensure test isolation cleanBucket(t) @@ -154,7 +154,7 @@ func TestS3CacheSoak(t *testing.T) { startMinio(t) - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) // Clean bucket to ensure test isolation cleanBucket(t) diff --git a/internal/cache/tiered_test.go b/internal/cache/tiered_test.go index 303a9cb..d6ae52f 100644 --- a/internal/cache/tiered_test.go +++ b/internal/cache/tiered_test.go @@ -15,7 +15,7 @@ import ( func TestTieredCache(t *testing.T) { cachetest.Suite(t, func(t *testing.T) cache.Cache { - _, _, ctx := logging.Configure(t.Context(), logging.Config{}) + _, ctx := logging.Configure(t.Context(), logging.Config{}) memory, err := cache.NewMemory(ctx, cache.MemoryConfig{LimitMB: 1024, MaxTTL: time.Hour}) assert.NoError(t, err) disk, err := cache.NewDisk(ctx, cache.DiskConfig{Root: t.TempDir(), LimitMB: 1024, MaxTTL: time.Hour}) @@ -29,7 +29,7 @@ func TestTieredCacheSoak(t *testing.T) { t.Skip("Skipping soak test; set SOAK_TEST=1 to run") } - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) memory, err := cache.NewMemory(ctx, cache.MemoryConfig{ LimitMB: 25, MaxTTL: 10 * time.Minute, diff --git a/internal/gitclone/manager_test.go b/internal/gitclone/manager_test.go index 1d82031..2578e99 100644 --- a/internal/gitclone/manager_test.go +++ b/internal/gitclone/manager_test.go @@ -42,7 +42,7 @@ func createBareRepo(t *testing.T, dir string) string { } func TestNewManager(t *testing.T) { - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ @@ -58,7 +58,7 @@ func TestNewManager(t *testing.T) { } func TestNewManager_RequiresRootDir(t *testing.T) { - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) config := Config{ FetchInterval: 15 * time.Minute, RefCheckInterval: 10 * time.Second, @@ -70,7 +70,7 @@ func TestNewManager_RequiresRootDir(t *testing.T) { } func TestManager_GetOrCreate(t *testing.T) { - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ MirrorRoot: tmpDir, @@ -96,7 +96,7 @@ func TestManager_GetOrCreate(t *testing.T) { } func TestManager_GetOrCreate_ExistingClone(t *testing.T) { - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ MirrorRoot: tmpDir, @@ -120,7 +120,7 @@ func TestManager_GetOrCreate_ExistingClone(t *testing.T) { } func TestManager_Get(t *testing.T) { - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ MirrorRoot: tmpDir, @@ -145,7 +145,7 @@ func TestManager_Get(t *testing.T) { } func TestManager_DiscoverExisting(t *testing.T) { - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() config := Config{ MirrorRoot: tmpDir, @@ -325,7 +325,7 @@ func TestRepository_CloneSetsMirrorConfig(t *testing.T) { } func TestRepository_Repack(t *testing.T) { - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelError}) tmpDir := t.TempDir() upstreamPath := createBareRepo(t, tmpDir) diff --git a/internal/jobscheduler/jobs_test.go b/internal/jobscheduler/jobs_test.go index 8958fff..12df2dd 100644 --- a/internal/jobscheduler/jobs_test.go +++ b/internal/jobscheduler/jobs_test.go @@ -44,7 +44,7 @@ func eventually(t *testing.T, timeout time.Duration, condition func() bool, msgA } func TestJobSchedulerBasic(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -60,7 +60,7 @@ func TestJobSchedulerBasic(t *testing.T) { } func TestJobSchedulerConcurrency(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -107,7 +107,7 @@ func TestJobSchedulerConcurrency(t *testing.T) { } func TestJobSchedulerQueueIsolation(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -159,7 +159,7 @@ func TestJobSchedulerQueueIsolation(t *testing.T) { } func TestJobSchedulerJobOrdering(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -197,7 +197,7 @@ func TestJobSchedulerJobOrdering(t *testing.T) { } func TestJobSchedulerErrorHandling(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -224,7 +224,7 @@ func TestJobSchedulerErrorHandling(t *testing.T) { } func TestJobSchedulerContextCancellation(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) scheduler := newTestScheduler(ctx, t, jobscheduler.Config{Concurrency: 2}) @@ -245,7 +245,7 @@ func TestJobSchedulerContextCancellation(t *testing.T) { } func TestJobSchedulerPeriodicJob(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -264,7 +264,7 @@ func TestJobSchedulerPeriodicJob(t *testing.T) { } func TestJobSchedulerPeriodicJobWithError(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -283,7 +283,7 @@ func TestJobSchedulerPeriodicJobWithError(t *testing.T) { } func TestJobSchedulerMultipleQueues(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -323,7 +323,7 @@ func TestJobSchedulerMultipleQueues(t *testing.T) { } func TestJobSchedulerHighConcurrency(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -375,7 +375,7 @@ func FuzzJobScheduler(f *testing.F) { queueCount = 50 } - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithTimeout(ctx, 10*time.Second) defer cancel() diff --git a/internal/jobscheduler/store_test.go b/internal/jobscheduler/store_test.go index fab4392..c3ed72b 100644 --- a/internal/jobscheduler/store_test.go +++ b/internal/jobscheduler/store_test.go @@ -81,7 +81,7 @@ func TestScheduleStoreInvalidPath(t *testing.T) { } func TestPeriodicJobDelaysWhenRecentlyRun(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -109,7 +109,7 @@ func TestPeriodicJobDelaysWhenRecentlyRun(t *testing.T) { } func TestPeriodicJobRunsImmediatelyWhenNeverRun(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -128,7 +128,7 @@ func TestPeriodicJobRunsImmediatelyWhenNeverRun(t *testing.T) { } func TestPeriodicJobRunsImmediatelyWhenIntervalElapsed(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -154,7 +154,7 @@ func TestPeriodicJobRunsImmediatelyWhenIntervalElapsed(t *testing.T) { } func TestPeriodicJobRecordsLastRun(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) ctx, cancel := context.WithCancel(ctx) defer cancel() diff --git a/internal/logging/logging.go b/internal/logging/logging.go index 1ac58be..20a1796 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -15,12 +15,18 @@ type Config struct { Remap map[string]string `hcl:"remap,optional" help:"Remap field names from old to new (e.g., msg=message, time=timestamp)."` } +var levelVar = &slog.LevelVar{} //nolint:gochecknoglobals + type logKey struct{} -// Configure sets up logging with the given config and returns a logger, a LevelVar -// that can be used to dynamically change the log level at runtime, and the updated context. -func Configure(ctx context.Context, config Config) (*slog.Logger, *slog.LevelVar, context.Context) { - levelVar := &slog.LevelVar{} +// SetLevel sets the global log level at runtime. +func SetLevel(level slog.Level) { levelVar.Set(level) } + +// GetLevel returns the current global log level. +func GetLevel() slog.Level { return levelVar.Level() } + +// Configure sets up logging with the given config and returns the logger and updated context. +func Configure(ctx context.Context, config Config) (*slog.Logger, context.Context) { levelVar.Set(config.Level) var handler slog.Handler @@ -50,7 +56,7 @@ func Configure(ctx context.Context, config Config) (*slog.Logger, *slog.LevelVar }) } logger := slog.New(handler) - return logger, levelVar, context.WithValue(ctx, logKey{}, logger) + return logger, context.WithValue(ctx, logKey{}, logger) } func FromContext(ctx context.Context) *slog.Logger { diff --git a/internal/metrics/metrics_test.go b/internal/metrics/metrics_test.go index f0733c6..f7df530 100644 --- a/internal/metrics/metrics_test.go +++ b/internal/metrics/metrics_test.go @@ -15,7 +15,7 @@ import ( func TestMetricsClient(t *testing.T) { ctx := context.Background() - logger, _, ctx := logging.Configure(ctx, logging.Config{}) + logger, ctx := logging.Configure(ctx, logging.Config{}) _ = logger client, err := metrics.New(ctx, metrics.Config{ @@ -39,7 +39,7 @@ func TestMetricsDedicatedServer(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - logger, _, ctx := logging.Configure(ctx, logging.Config{}) + logger, ctx := logging.Configure(ctx, logging.Config{}) _ = logger client, err := metrics.New(ctx, metrics.Config{ @@ -58,7 +58,7 @@ func TestMetricsDedicatedServer(t *testing.T) { func TestMetricsOTLPOnly(t *testing.T) { ctx := context.Background() - logger, _, ctx := logging.Configure(ctx, logging.Config{}) + logger, ctx := logging.Configure(ctx, logging.Config{}) _ = logger // OTLP-only configuration @@ -79,7 +79,7 @@ func TestMetricsOTLPOnly(t *testing.T) { func TestMetricsBothExporters(t *testing.T) { ctx := context.Background() - logger, _, ctx := logging.Configure(ctx, logging.Config{}) + logger, ctx := logging.Configure(ctx, logging.Config{}) _ = logger // Both exporters enabled @@ -103,7 +103,7 @@ func TestMetricsBothExporters(t *testing.T) { func TestMetricsNoExportersError(t *testing.T) { ctx := context.Background() - logger, _, ctx := logging.Configure(ctx, logging.Config{}) + logger, ctx := logging.Configure(ctx, logging.Config{}) _ = logger // Should error when no exporters are enabled diff --git a/internal/reaper/reaper_test.go b/internal/reaper/reaper_test.go index 4c9284b..c14c7fa 100644 --- a/internal/reaper/reaper_test.go +++ b/internal/reaper/reaper_test.go @@ -18,7 +18,7 @@ import ( func testContext(t *testing.T) context.Context { t.Helper() - _, _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) + _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) return ctx } diff --git a/internal/strategy/artifactory_test.go b/internal/strategy/artifactory_test.go index e697e07..363c941 100644 --- a/internal/strategy/artifactory_test.go +++ b/internal/strategy/artifactory_test.go @@ -57,7 +57,7 @@ func setupArtifactoryTest(t *testing.T, config strategy.ArtifactoryConfig) (*moc // Point config to mock server config.Target = mock.server.URL - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: 24 * time.Hour}) assert.NoError(t, err) t.Cleanup(func() { memCache.Close() }) @@ -204,7 +204,7 @@ func TestArtifactoryNonOKResponse(t *testing.T) { } func TestArtifactoryString(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -219,7 +219,7 @@ func TestArtifactoryString(t *testing.T) { } func TestArtifactoryInvalidTargetURL(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() diff --git a/internal/strategy/git/git_test.go b/internal/strategy/git/git_test.go index fe61860..aa8e1ba 100644 --- a/internal/strategy/git/git_test.go +++ b/internal/strategy/git/git_test.go @@ -40,7 +40,7 @@ func newTestScheduler(ctx context.Context, t *testing.T) jobscheduler.Provider { } func TestNew(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() tests := []struct { @@ -138,7 +138,7 @@ func TestExtractRepoPath(t *testing.T) { } func TestNewWithExistingCloneOnDisk(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() // Create a fake bare clone directory on disk before initializing strategy @@ -162,7 +162,7 @@ func TestNewWithExistingCloneOnDisk(t *testing.T) { } func TestIntegrationWithMockUpstream(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) // Create a mock upstream server upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -200,7 +200,7 @@ func TestNewMissingGitBinary(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("PATH manipulation for binary checks not supported on Windows") } - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() t.Setenv("PATH", t.TempDir()) @@ -220,7 +220,7 @@ func TestNewMissingSnapshotBinaries(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("PATH manipulation for binary checks not supported on Windows") } - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() t.Run("MissingTar", func(t *testing.T) { @@ -256,7 +256,7 @@ func TestNewMissingSnapshotBinaries(t *testing.T) { } func TestParseGitRefs(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) _ = ctx tests := []struct { diff --git a/internal/strategy/git/integration_test.go b/internal/strategy/git/integration_test.go index 6f2575a..02507aa 100644 --- a/internal/strategy/git/integration_test.go +++ b/internal/strategy/git/integration_test.go @@ -48,7 +48,7 @@ func TestIntegrationGitCloneViaProxy(t *testing.T) { t.Skip("git not found in PATH") } - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() clonesDir := filepath.Join(tmpDir, "clones") workDir := filepath.Join(tmpDir, "work") @@ -127,7 +127,7 @@ func TestIntegrationGitFetchViaProxy(t *testing.T) { t.Skip("git not found in PATH") } - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() clonesDir := filepath.Join(tmpDir, "clones") workDir := filepath.Join(tmpDir, "work") @@ -182,7 +182,7 @@ func TestIntegrationPushForwardsToUpstream(t *testing.T) { t.Skip("git not found in PATH") } - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() clonesDir := filepath.Join(tmpDir, "clones") upstreamDir := filepath.Join(tmpDir, "upstream") @@ -300,7 +300,7 @@ func TestIntegrationSpoolReusesDuringClone(t *testing.T) { t.Skip("git not found in PATH") } - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelDebug}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelDebug}) tmpDir := t.TempDir() clonesDir := filepath.Join(tmpDir, "clones") workDir := filepath.Join(tmpDir, "work") diff --git a/internal/strategy/git/repack_test.go b/internal/strategy/git/repack_test.go index e91abc3..f77e1d6 100644 --- a/internal/strategy/git/repack_test.go +++ b/internal/strategy/git/repack_test.go @@ -16,7 +16,7 @@ import ( ) func TestRepackInterval(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() tests := []struct { @@ -49,7 +49,7 @@ func TestRepackInterval(t *testing.T) { } func TestRepackScheduledForExistingRepos(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() // Create a fake bare clone directory on disk before initializing strategy. diff --git a/internal/strategy/git/snapshot_test.go b/internal/strategy/git/snapshot_test.go index 6e17129..d59566e 100644 --- a/internal/strategy/git/snapshot_test.go +++ b/internal/strategy/git/snapshot_test.go @@ -21,7 +21,7 @@ import ( ) func TestSnapshotHTTPEndpoint(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{}) @@ -111,7 +111,7 @@ func TestSnapshotGenerationViaLocalClone(t *testing.T) { t.Skip("git not found in PATH") } - _, _, ctx := logging.Configure(context.Background(), logging.Config{}) + _, ctx := logging.Configure(context.Background(), logging.Config{}) tmpDir := t.TempDir() mirrorRoot := filepath.Join(tmpDir, "mirrors") upstreamURL := "https://github.com/org/repo" diff --git a/internal/strategy/github_releases_test.go b/internal/strategy/github_releases_test.go index ded5472..ef8e795 100644 --- a/internal/strategy/github_releases_test.go +++ b/internal/strategy/github_releases_test.go @@ -121,7 +121,7 @@ func setupTest(t *testing.T, config strategy.GitHubReleasesConfig) (*mockGitHubS originalTransport: originalTransport, } - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) t.Cleanup(func() { memCache.Close() }) @@ -226,7 +226,7 @@ func TestGitHubReleasesPublicRepoNotFound(t *testing.T) { assert.Equal(t, 1, mock.publicCallCount) key := cache.NewKey("https://github.com/publicorg/repo/releases/download/v1.0.0/missing.tar.gz") - _, _, ctx2 := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx2 := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx2, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -236,7 +236,7 @@ func TestGitHubReleasesPublicRepoNotFound(t *testing.T) { } func TestGitHubReleasesNoToken(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -248,7 +248,7 @@ func TestGitHubReleasesNoToken(t *testing.T) { } func TestGitHubReleasesString(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() diff --git a/internal/strategy/gomod/gomod_test.go b/internal/strategy/gomod/gomod_test.go index c8a187c..1f3a3d7 100644 --- a/internal/strategy/gomod/gomod_test.go +++ b/internal/strategy/gomod/gomod_test.go @@ -170,7 +170,7 @@ func setupGoModTest(t *testing.T) (*mockGoModServer, *http.ServeMux, context.Con mock := newMockGoModServer(t) t.Cleanup(mock.close) - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: 24 * time.Hour}) assert.NoError(t, err) @@ -378,7 +378,7 @@ func TestNewMissingGitBinaryForPrivatePaths(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("PATH manipulation for binary checks not supported on Windows") } - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: 24 * time.Hour}) assert.NoError(t, err) diff --git a/internal/strategy/handler/handler_test.go b/internal/strategy/handler/handler_test.go index 4931c58..52d25f7 100644 --- a/internal/strategy/handler/handler_test.go +++ b/internal/strategy/handler/handler_test.go @@ -296,7 +296,7 @@ func TestHandlerMethodChaining(t *testing.T) { } func mustNewMemoryCache() cache.Cache { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) c, err := cache.NewMemory(ctx, cache.MemoryConfig{ MaxTTL: time.Hour, }) diff --git a/internal/strategy/hermit_test.go b/internal/strategy/hermit_test.go index 6abb729..e815f28 100644 --- a/internal/strategy/hermit_test.go +++ b/internal/strategy/hermit_test.go @@ -24,7 +24,7 @@ var httpTransportMutexHermit sync.Mutex //nolint:gochecknoglobals func setupHermitTest(t *testing.T) (*http.ServeMux, context.Context, cache.Cache) { t.Helper() - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) t.Cleanup(func() { memCache.Close() }) diff --git a/internal/strategy/host_test.go b/internal/strategy/host_test.go index efe02d8..1f8442b 100644 --- a/internal/strategy/host_test.go +++ b/internal/strategy/host_test.go @@ -25,7 +25,7 @@ func TestHostCaching(t *testing.T) { })) defer backend.Close() - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -62,7 +62,7 @@ func TestHostNonOKStatus(t *testing.T) { })) defer backend.Close() - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -88,7 +88,7 @@ func TestHostNonOKStatus(t *testing.T) { } func TestHostInvalidTargetURL(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close() @@ -99,7 +99,7 @@ func TestHostInvalidTargetURL(t *testing.T) { } func TestHostString(t *testing.T) { - _, _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) + _, ctx := logging.Configure(context.Background(), logging.Config{Level: slog.LevelError}) memCache, err := cache.NewMemory(ctx, cache.MemoryConfig{MaxTTL: time.Hour}) assert.NoError(t, err) defer memCache.Close()