diff --git a/pkg/epp/scheduling/framework/plugins/multi/prefix/indexer.go b/pkg/epp/scheduling/framework/plugins/multi/prefix/indexer.go index 0a209a8d4..bd9e2c96e 100644 --- a/pkg/epp/scheduling/framework/plugins/multi/prefix/indexer.go +++ b/pkg/epp/scheduling/framework/plugins/multi/prefix/indexer.go @@ -38,15 +38,15 @@ type indexer struct { } // newIndexer initializes an indexer with size limits and starts cache size reporting. -func newIndexer(maxLRUSize int) *indexer { - ix := &indexer{ +func newIndexer(ctx context.Context, maxLRUSize int) *indexer { + indexer := &indexer{ hashToPods: make(map[BlockHash]podSet), podToLRU: make(map[ServerID]*lru.Cache[BlockHash, struct{}]), maxLRUSize: maxLRUSize, } - go ix.ReportLRUSize(time.Second) - return ix + go indexer.reportLRUSize(ctx, time.Second) + return indexer } // Add adds a list of prefix hashes to the cache, tied to the server. @@ -111,8 +111,8 @@ func (i *indexer) makeEvictionFn(pod ServerID) func(BlockHash, struct{}) { } } -// ReportLRUSize starts a goroutine that periodically reports the LRU cache size metric. -func (i *indexer) ReportLRUSize(interval time.Duration) { +// reportLRUSize starts a goroutine that periodically reports the LRU cache size metric. +func (i *indexer) reportLRUSize(ctx context.Context, interval time.Duration) { ticker := time.NewTicker(interval) defer ticker.Stop() for range ticker.C { @@ -137,7 +137,7 @@ func (i *indexer) ReportLRUSize(interval time.Duration) { } metrics.RecordPrefixCacheSize(int64(totalEntries)) - log.FromContext(context.TODO()).V(logutil.TRACE).Info("Prefix cache state", + log.FromContext(ctx).V(logutil.TRACE).Info("Prefix cache state", "total entries", totalEntries, "# pods", numPods, "avg entries per pod", avg, diff --git a/pkg/epp/scheduling/framework/plugins/multi/prefix/indexer_test.go b/pkg/epp/scheduling/framework/plugins/multi/prefix/indexer_test.go index a15112182..6d4fcc5f4 100644 --- a/pkg/epp/scheduling/framework/plugins/multi/prefix/indexer_test.go +++ b/pkg/epp/scheduling/framework/plugins/multi/prefix/indexer_test.go @@ -16,13 +16,14 @@ limitations under the License. package prefix import ( + "context" "testing" "github.com/stretchr/testify/assert" ) func TestIndexer_AddAndGet(t *testing.T) { - i := newIndexer(2) + i := newIndexer(context.Background(), 2) hash1 := BlockHash(1) server := ServerID{Namespace: "default", Name: "server1"} diff --git a/pkg/epp/scheduling/framework/plugins/multi/prefix/plugin.go b/pkg/epp/scheduling/framework/plugins/multi/prefix/plugin.go index 8c7b52cec..ef33521b4 100644 --- a/pkg/epp/scheduling/framework/plugins/multi/prefix/plugin.go +++ b/pkg/epp/scheduling/framework/plugins/multi/prefix/plugin.go @@ -148,7 +148,7 @@ func New(ctx context.Context, config Config) *Plugin { capacity := config.LRUCapacityPerServer if capacity <= 0 { capacity = DefaultLRUCapacityPerServer - log.FromContext(context.TODO()).V(logutil.DEFAULT).Info( + log.FromContext(ctx).V(logutil.DEFAULT).Info( "LRUCapacityPerServer is not positive, using default value", "defaultCapacity", DefaultLRUCapacityPerServer, ) @@ -158,7 +158,7 @@ func New(ctx context.Context, config Config) *Plugin { typedName: plugins.TypedName{Type: PrefixCachePluginType, Name: PrefixCachePluginType}, config: config, pluginState: plugins.NewPluginState(ctx), - indexer: newIndexer(capacity), + indexer: newIndexer(ctx, capacity), } }