feat: pass NodeProvider to metricstore Init

Setting the provider after Init left the checkpoint restore inside Init
without job information and forced callers to pre-call InitMetrics and
SetNodeProvider in the right order. Init now receives the provider as a
parameter and injects it before the restore, so the ordering is enforced
by the signature. SetNodeProvider remains for callers that do not run
Init (tests, -cleanup-checkpoints).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Aditya Ujeniya
2026-07-08 15:44:54 +02:00
parent ea2bfbb6aa
commit dd2f5968b1
2 changed files with 14 additions and 12 deletions
+4 -9
View File
@@ -367,15 +367,10 @@ func runServer(ctx context.Context) error {
haveMetricstore := false
mscfg := ccconf.GetPackageConfig("metric-store")
if mscfg != nil {
metrics := metricstore.BuildMetricList()
// The NodeProvider MUST be set before Init: the checkpoint load inside
// Init consults it to load the full history for nodes with running
// jobs. InitMetrics is sync.Once-guarded, so the second call inside
// Init is a no-op. The repository is injected as NodeProvider to
// break the import cycle.
metricstore.InitMetrics(metrics)
metricstore.GetMemoryStore().SetNodeProvider(repository.GetJobRepository())
metricstore.Init(mscfg, metrics, &wg)
// The repository is injected as NodeProvider (breaking the import
// cycle) so the checkpoint load inside Init can fetch the full
// history for nodes with running jobs.
metricstore.Init(mscfg, metricstore.BuildMetricList(), repository.GetJobRepository(), &wg)
metricstore.MetricStoreHandle = &metricstore.InternalMetricStore{}
haveMetricstore = true