@cryptotaxi247 / kubo / commits / ae8667296

fix(provider/stats): number format (#11045)

* fix: reprovide alert bug * number formatting * show full number for peer count

Guillaume Michel committed Nov 1, 2025 at 08:20 UTC ae86672964ee93497c61de2fd82f17e2d97adba4
2 files changed +25 -21
core/commands/provide.go
+22 -18
@@ -373,8 +373,8 @@ NOTES:
373 // Queues
374 if all || queues || brief {
375 sectionTitle(1, "Queues")
376 - formatLine(1, "%sProvide queue: %s CIDs, %s regions", indent, humanNumber(s.Sweep.Queues.PendingKeyProvides), humanNumber(s.Sweep.Queues.PendingRegionProvides))
377 - formatLine(1, "%sReprovide queue: %s regions", indent, humanNumber(s.Sweep.Queues.PendingRegionReprovides))
376 + formatLine(1, "%sProvide queue: %s CIDs, %s regions", indent, humanSI(s.Sweep.Queues.PendingKeyProvides, 1), humanSI(s.Sweep.Queues.PendingRegionProvides, 1))
377 + formatLine(1, "%sReprovide queue: %s regions", indent, humanSI(s.Sweep.Queues.PendingRegionReprovides, 1))
378 addBlankLine(1)
379 }
380
@@ -414,12 +414,12 @@ NOTES:
414 sectionTitle(0, "Network")
415 formatLine(0, "%sAvg record holders: %s", indent, humanFloatOrNA(s.Sweep.Network.AvgHolders))
416 if !brief {
417 - formatLine(0, "%sPeers swept: %s", indent, humanNumber(s.Sweep.Network.Peers))
417 + formatLine(0, "%sPeers swept: %s", indent, humanInt(s.Sweep.Network.Peers))
418 formatLine(0, "%sFull keyspace coverage: %t", indent, s.Sweep.Network.CompleteKeyspaceCoverage)
419 if s.Sweep.Network.Peers > 0 {
420 - formatLine(0, "%sReachable peers: %s (%s%%)", indent, humanNumber(s.Sweep.Network.Reachable), humanNumber(100*s.Sweep.Network.Reachable/s.Sweep.Network.Peers))
420 + formatLine(0, "%sReachable peers: %s (%s%%)", indent, humanInt(s.Sweep.Network.Reachable), humanNumber(100*s.Sweep.Network.Reachable/s.Sweep.Network.Peers))
421 } else {
422 - formatLine(0, "%sReachable peers: %s", indent, humanNumber(s.Sweep.Network.Reachable))
422 + formatLine(0, "%sReachable peers: %s", indent, humanInt(s.Sweep.Network.Reachable))
423 }
424 formatLine(0, "%sAvg region size: %s", indent, humanFloatOrNA(s.Sweep.Network.AvgRegionSize))
425 formatLine(0, "%sReplication factor: %s", indent, humanNumber(s.Sweep.Network.ReplicationFactor))
@@ -431,8 +431,8 @@ NOTES:
431 if all || operations || brief {
432 sectionTitle(1, "Operations")
433 // Ongoing operations
434 - formatLine(1, "%sOngoing provides: %s CIDs, %s regions", indent, humanNumber(s.Sweep.Operations.Ongoing.KeyProvides), humanNumber(s.Sweep.Operations.Ongoing.RegionProvides))
435 - formatLine(1, "%sOngoing reprovides: %s CIDs, %s regions", indent, humanNumber(s.Sweep.Operations.Ongoing.KeyReprovides), humanNumber(s.Sweep.Operations.Ongoing.RegionReprovides))
434 + formatLine(1, "%sOngoing provides: %s CIDs, %s regions", indent, humanSI(s.Sweep.Operations.Ongoing.KeyProvides, 1), humanSI(s.Sweep.Operations.Ongoing.RegionProvides, 1))
435 + formatLine(1, "%sOngoing reprovides: %s CIDs, %s regions", indent, humanSI(s.Sweep.Operations.Ongoing.KeyReprovides, 1), humanSI(s.Sweep.Operations.Ongoing.RegionReprovides, 1))
436 // Past operations summary
437 formatLine(1, "%sTotal CIDs provided: %s", indent, humanNumber(s.Sweep.Operations.Past.KeysProvided))
438 if !brief {
@@ -464,21 +464,21 @@ NOTES:
464 if compactMode {
465 specifyWorkers = ""
466 }
467 - formatLine(0, "%sActive%s: %s / %s (max)", indent, specifyWorkers, humanNumber(s.Sweep.Workers.Active), humanFull(float64(s.Sweep.Workers.Max), 0))
467 + formatLine(0, "%sActive%s: %s / %s (max)", indent, specifyWorkers, humanInt(s.Sweep.Workers.Active), humanInt(s.Sweep.Workers.Max))
468 if brief {
469 // Brief mode - show condensed worker info
470 formatLine(0, "%sPeriodic%s: %s active, %s available, %s queued", indent, specifyWorkers,
471 - humanNumber(s.Sweep.Workers.ActivePeriodic), humanNumber(availablePeriodic), humanNumber(s.Sweep.Workers.QueuedPeriodic))
471 + humanInt(s.Sweep.Workers.ActivePeriodic), humanInt(availablePeriodic), humanInt(s.Sweep.Workers.QueuedPeriodic))
472 formatLine(0, "%sBurst%s: %s active, %s available, %s queued\n", indent, specifyWorkers,
473 - humanNumber(s.Sweep.Workers.ActiveBurst), humanNumber(availableBurst), humanNumber(s.Sweep.Workers.QueuedBurst))
473 + humanInt(s.Sweep.Workers.ActiveBurst), humanInt(availableBurst), humanInt(s.Sweep.Workers.QueuedBurst))
474 } else {
475 - formatLine(0, "%sFree%s: %s", indent, specifyWorkers, humanNumber(availableFreeWorkers))
475 + formatLine(0, "%sFree%s: %s", indent, specifyWorkers, humanInt(availableFreeWorkers))
476 formatLine(0, "%s %-14s %-9s %s", indent, "Workers stats:", "Periodic", "Burst")
477 - formatLine(0, "%s %-14s %-9s %s", indent, "Active:", humanNumber(s.Sweep.Workers.ActivePeriodic), humanNumber(s.Sweep.Workers.ActiveBurst))
478 - formatLine(0, "%s %-14s %-9s %s", indent, "Dedicated:", humanNumber(s.Sweep.Workers.DedicatedPeriodic), humanNumber(s.Sweep.Workers.DedicatedBurst))
479 - formatLine(0, "%s %-14s %-9s %s", indent, "Available:", humanNumber(availablePeriodic), humanNumber(availableBurst))
480 - formatLine(0, "%s %-14s %-9s %s", indent, "Queued:", humanNumber(s.Sweep.Workers.QueuedPeriodic), humanNumber(s.Sweep.Workers.QueuedBurst))
481 - formatLine(0, "%sMax connections/worker: %s", indent, humanNumber(s.Sweep.Workers.MaxProvideConnsPerWorker))
477 + formatLine(0, "%s %-14s %-9s %s", indent, "Active:", humanInt(s.Sweep.Workers.ActivePeriodic), humanInt(s.Sweep.Workers.ActiveBurst))
478 + formatLine(0, "%s %-14s %-9s %s", indent, "Dedicated:", humanInt(s.Sweep.Workers.DedicatedPeriodic), humanInt(s.Sweep.Workers.DedicatedBurst))
479 + formatLine(0, "%s %-14s %-9s %s", indent, "Available:", humanInt(availablePeriodic), humanInt(availableBurst))
480 + formatLine(0, "%s %-14s %-9s %s", indent, "Queued:", humanInt(s.Sweep.Workers.QueuedPeriodic), humanInt(s.Sweep.Workers.QueuedBurst))
481 + formatLine(0, "%sMax connections/worker: %s", indent, humanInt(s.Sweep.Workers.MaxProvideConnsPerWorker))
482 addBlankLine(0)
483 }
484 }
@@ -563,11 +563,15 @@ func humanFloatOrNA(val float64) string {
563 return humanFull(val, 1)
564 }
565
566 -func humanSI(val float64, decimals int) string {
567 - v, unit := humanize.ComputeSI(val)
566 +func humanSI[T constraints.Float | constraints.Integer](val T, decimals int) string {
567 + v, unit := humanize.ComputeSI(float64(val))
568 return fmt.Sprintf("%s%s", humanFull(v, decimals), unit)
569 }
570
571 +func humanInt[T constraints.Integer](val T) string {
572 + return humanFull(float64(val), 0)
573 +}
574 +
575 func humanFull(val float64, decimals int) string {
576 return humanize.CommafWithDigits(val, decimals)
577 }
core/node/provider.go
+3 -3
@@ -554,6 +554,9 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
554 }
555 reprovideAlert := fx.Invoke(func(lc fx.Lifecycle, in alertInput) {
556 prov := extractSweepingProvider(in.Provider)
557 + if prov == nil {
558 + return
559 + }
560
561 var (
562 cancel context.CancelFunc
@@ -562,9 +565,6 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
565
566 lc.Append(fx.Hook{
567 OnStart: func(ctx context.Context) error {
565 - if prov == nil {
566 - return nil
567 - }
568 gcCtx, c := context.WithCancel(context.Background())
569 cancel = c
570 go func() {