Skip to content

Commit d78150f

Browse files
committed
fix: pass logger through so it can be discarded in benchmarks
1 parent 25b1d10 commit d78150f

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

internal/indexer/document_change.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (idx *Indexer) decodeModule(modHandle document.DirHandle, dependsOn job.IDs
8282
eSchemaId, err := idx.jobStore.EnqueueJob(job.Job{
8383
Dir: modHandle,
8484
Func: func(ctx context.Context) error {
85-
return module.PreloadEmbeddedSchema(ctx, schemas.FS, idx.modStore, idx.schemaStore, modHandle.Path())
85+
return module.PreloadEmbeddedSchema(ctx, idx.logger, schemas.FS, idx.modStore, idx.schemaStore, modHandle.Path())
8686
},
8787
DependsOn: job.IDs{metaId},
8888
Type: op.OpTypePreloadEmbeddedSchema.String(),

internal/indexer/module_calls.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (idx *Indexer) decodeInstalledModuleCalls(modHandle document.DirHandle, ign
7777
eSchemaId, err := idx.jobStore.EnqueueJob(job.Job{
7878
Dir: mcHandle,
7979
Func: func(ctx context.Context) error {
80-
return module.PreloadEmbeddedSchema(ctx, schemas.FS, idx.modStore, idx.schemaStore, mcPath)
80+
return module.PreloadEmbeddedSchema(ctx, idx.logger, schemas.FS, idx.modStore, idx.schemaStore, mcPath)
8181
},
8282
Type: op.OpTypePreloadEmbeddedSchema.String(),
8383
DependsOn: job.IDs{metaId},

internal/indexer/walker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (idx *Indexer) WalkedModule(ctx context.Context, modHandle document.DirHand
149149
eSchemaId, err := idx.jobStore.EnqueueJob(job.Job{
150150
Dir: modHandle,
151151
Func: func(ctx context.Context) error {
152-
return module.PreloadEmbeddedSchema(ctx, schemas.FS, idx.modStore, idx.schemaStore, modHandle.Path())
152+
return module.PreloadEmbeddedSchema(ctx, idx.logger, schemas.FS, idx.modStore, idx.schemaStore, modHandle.Path())
153153
},
154154
// This could theoretically also depend on ObtainSchema to avoid
155155
// attempt to preload the same schema twice but we avoid that dependency

internal/terraform/module/module_ops.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func ObtainSchema(ctx context.Context, modStore *state.ModuleStore, schemaStore
188188
return nil
189189
}
190190

191-
func PreloadEmbeddedSchema(ctx context.Context, fs fs.ReadDirFS, modStore *state.ModuleStore, schemaStore *state.ProviderSchemaStore, modPath string) error {
191+
func PreloadEmbeddedSchema(ctx context.Context, logger *log.Logger, fs fs.ReadDirFS, modStore *state.ModuleStore, schemaStore *state.ProviderSchemaStore, modPath string) error {
192192
mod, err := modStore.ModuleByPath(modPath)
193193
if err != nil {
194194
return err
@@ -236,14 +236,14 @@ func PreloadEmbeddedSchema(ctx context.Context, fs fs.ReadDirFS, modStore *state
236236
// of all recent (0.14+) Terraform versions.
237237
originalAddr := pAddr
238238
pAddr.Namespace = "hashicorp"
239-
log.Printf("preloading schema for %s (implying %s)",
239+
logger.Printf("preloading schema for %s (implying %s)",
240240
originalAddr.ForDisplay(), pAddr.ForDisplay())
241241
}
242242

243243
pSchemaFile, err := schemas.FindProviderSchemaFile(fs, pAddr)
244244
if err != nil {
245245
if errors.Is(err, schemas.SchemaNotAvailable{Addr: pAddr}) {
246-
log.Printf("preloaded schema not available for %s", pAddr)
246+
logger.Printf("preloaded schema not available for %s", pAddr)
247247
continue
248248
}
249249
return err
@@ -273,13 +273,13 @@ func PreloadEmbeddedSchema(ctx context.Context, fs fs.ReadDirFS, modStore *state
273273
// This accounts for a possible race condition
274274
// where we may be preloading the same schema
275275
// for different providers at the same time
276-
log.Printf("schema for %s is already loaded", pAddr)
276+
logger.Printf("schema for %s is already loaded", pAddr)
277277
continue
278278
}
279279
return err
280280
}
281281
elapsedTime := time.Now().Sub(startTime)
282-
log.Printf("preloaded schema for %s %s in %s", pAddr, pSchemaFile.Version, elapsedTime)
282+
logger.Printf("preloaded schema for %s %s in %s", pAddr, pSchemaFile.Version, elapsedTime)
283283
}
284284

285285
return nil

internal/terraform/module/module_ops_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ func TestPreloadEmbeddedSchema_basic(t *testing.T) {
676676
t.Fatal(err)
677677
}
678678

679-
err = PreloadEmbeddedSchema(ctx, schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
679+
err = PreloadEmbeddedSchema(ctx, log.Default(), schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
680680
if err != nil {
681681
t.Fatal(err)
682682
}
@@ -746,7 +746,7 @@ func TestPreloadEmbeddedSchema_unknownProviderOnly(t *testing.T) {
746746
t.Fatal(err)
747747
}
748748

749-
err = PreloadEmbeddedSchema(ctx, schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
749+
err = PreloadEmbeddedSchema(ctx, log.Default(), schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
750750
if err != nil {
751751
t.Fatal(err)
752752
}
@@ -810,13 +810,13 @@ func TestPreloadEmbeddedSchema_idempotency(t *testing.T) {
810810
}
811811

812812
// first
813-
err = PreloadEmbeddedSchema(ctx, schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
813+
err = PreloadEmbeddedSchema(ctx, log.Default(), schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
814814
if err != nil {
815815
t.Fatal(err)
816816
}
817817

818818
// second - testing module state
819-
err = PreloadEmbeddedSchema(ctx, schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
819+
err = PreloadEmbeddedSchema(ctx, log.Default(), schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
820820
if err != nil {
821821
if !errors.Is(err, job.StateNotChangedErr{Dir: document.DirHandleFromPath(modPath)}) {
822822
t.Fatal(err)
@@ -825,7 +825,7 @@ func TestPreloadEmbeddedSchema_idempotency(t *testing.T) {
825825

826826
ctx = job.WithIgnoreState(ctx, true)
827827
// third - testing requirement matching
828-
err = PreloadEmbeddedSchema(ctx, schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
828+
err = PreloadEmbeddedSchema(ctx, log.Default(), schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
829829
if err != nil {
830830
t.Fatal(err)
831831
}
@@ -892,14 +892,14 @@ func TestPreloadEmbeddedSchema_raceCondition(t *testing.T) {
892892
wg.Add(2)
893893
go func() {
894894
defer wg.Done()
895-
err := PreloadEmbeddedSchema(ctx, schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
895+
err := PreloadEmbeddedSchema(ctx, log.Default(), schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
896896
if err != nil && !errors.Is(err, job.StateNotChangedErr{Dir: document.DirHandleFromPath(modPath)}) {
897897
t.Error(err)
898898
}
899899
}()
900900
go func() {
901901
defer wg.Done()
902-
err := PreloadEmbeddedSchema(ctx, schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
902+
err := PreloadEmbeddedSchema(ctx, log.Default(), schemasFS, ss.Modules, ss.ProviderSchemas, modPath)
903903
if err != nil && !errors.Is(err, job.StateNotChangedErr{Dir: document.DirHandleFromPath(modPath)}) {
904904
t.Error(err)
905905
}

0 commit comments

Comments
 (0)