From c87f380e2e85741fc274d9ee2b1fec58dbd8b5bd Mon Sep 17 00:00:00 2001 From: Moby von Briesen Date: Tue, 5 Dec 2023 16:17:49 -0500 Subject: [PATCH] satellite/repair: Fix flaky test Don't use global monkit.Default in Queue Stat test, or it can fail due to concurrently-executing tests. Change-Id: I061d626f26220705c8dd0de17ac7e14c81831d7f --- satellite/core.go | 2 +- satellite/repair/repairer/queue_stat.go | 8 +++++--- satellite/repair/repairer/queue_stat_test.go | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/satellite/core.go b/satellite/core.go index 09ad3839c..9f4c4032f 100644 --- a/satellite/core.go +++ b/satellite/core.go @@ -594,7 +594,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, { if config.RepairQueueCheck.Interval.Seconds() > 0 { - peer.RepairQueueStat.Chore = repairer.NewQueueStat(log, placement.SupportedPlacements(), db.RepairQueue(), config.RepairQueueCheck.Interval) + peer.RepairQueueStat.Chore = repairer.NewQueueStat(log, monkit.Default, placement.SupportedPlacements(), db.RepairQueue(), config.RepairQueueCheck.Interval) peer.Services.Add(lifecycle.Item{ Name: "queue-stat", diff --git a/satellite/repair/repairer/queue_stat.go b/satellite/repair/repairer/queue_stat.go index a82fc40af..02a54e8c7 100644 --- a/satellite/repair/repairer/queue_stat.go +++ b/satellite/repair/repairer/queue_stat.go @@ -27,6 +27,7 @@ type QueueStatConfig struct { type QueueStat struct { db queue.RepairQueue log *zap.Logger + mon *monkit.Scope Loop *sync2.Cycle mu sync.Mutex stats map[string]queue.Stat @@ -37,21 +38,22 @@ type QueueStat struct { var _ monkit.StatSource = &QueueStat{} // NewQueueStat creates a chore to stat repair queue statistics. -func NewQueueStat(log *zap.Logger, placements []storj.PlacementConstraint, db queue.RepairQueue, checkInterval time.Duration) *QueueStat { +func NewQueueStat(log *zap.Logger, registry *monkit.Registry, placements []storj.PlacementConstraint, db queue.RepairQueue, checkInterval time.Duration) *QueueStat { chore := &QueueStat{ db: db, log: log, + mon: registry.Package(), Loop: sync2.NewCycle(checkInterval), placements: placements, } - mon.Chain(chore) + chore.mon.Chain(chore) return chore } // Run logs the current version information. func (c *QueueStat) Run(ctx context.Context) (err error) { - defer mon.Task()(&ctx)(&err) + defer c.mon.Task()(&ctx)(&err) return c.Loop.Run(ctx, func(ctx context.Context) error { c.RunOnce(ctx) return nil diff --git a/satellite/repair/repairer/queue_stat_test.go b/satellite/repair/repairer/queue_stat_test.go index 644e651a6..0837b8143 100644 --- a/satellite/repair/repairer/queue_stat_test.go +++ b/satellite/repair/repairer/queue_stat_test.go @@ -41,11 +41,12 @@ func TestStatChore(t *testing.T) { }) require.NoError(t, err) - chore := repairer.NewQueueStat(zaptest.NewLogger(t), []storj.PlacementConstraint{0, 1, 2}, db.RepairQueue(), 100*time.Hour) + registry := monkit.NewRegistry() + chore := repairer.NewQueueStat(zaptest.NewLogger(t), registry, []storj.PlacementConstraint{0, 1, 2}, db.RepairQueue(), 100*time.Hour) collectMonkitStat := func() map[string]float64 { monkitValues := map[string]float64{} - monkit.Default.Stats(func(key monkit.SeriesKey, field string, val float64) { + registry.Stats(func(key monkit.SeriesKey, field string, val float64) { if key.Measurement != "repair_queue" { return }