mirror of
https://github.com/pgsty/minio.git
synced 2026-11-11 01:55:30 +03:00
fix(replication): handle absent pool in worker metrics
Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
request validation and AWS FIPS endpoint signing fixes.
|
request validation and AWS FIPS endpoint signing fixes.
|
||||||
- Bundle verified mcli 20261109 archives in source container builds and use
|
- Bundle verified mcli 20261109 archives in source container builds and use
|
||||||
that release by default in the integration-test client installer.
|
that release by default in the integration-test client installer.
|
||||||
|
- Prevent replication worker metrics from panicking when the replication
|
||||||
|
pool is absent, while retaining historical averages and peak counts.
|
||||||
|
|
||||||
## RELEASE.2026-10-26T00-00-00Z
|
## RELEASE.2026-10-26T00-00-00Z
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,10 @@ func (a *ActiveWorkerStat) update() {
|
|||||||
if a == nil {
|
if a == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
a.Curr = globalReplicationPool.Get().ActiveWorkers()
|
a.Curr = 0
|
||||||
|
if pool := globalReplicationPool.Get(); pool != nil {
|
||||||
|
a.Curr = pool.ActiveWorkers()
|
||||||
|
}
|
||||||
a.hist.Update(int64(a.Curr))
|
a.hist.Update(int64(a.Curr))
|
||||||
a.Avg = float32(a.hist.Mean())
|
a.Avg = float32(a.hist.Mean())
|
||||||
a.Max = int(a.hist.Max())
|
a.Max = int(a.hist.Max())
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (c) 2026 PGSTY
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/minio/minio/internal/once"
|
||||||
|
"github.com/rcrowley/go-metrics"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReplicationWorkerMetricsWithoutPool(t *testing.T) {
|
||||||
|
previous := globalReplicationPool
|
||||||
|
t.Cleanup(func() { globalReplicationPool = previous })
|
||||||
|
|
||||||
|
globalReplicationPool = once.NewSingleton[ReplicationPool]()
|
||||||
|
globalReplicationPool.Set(&ReplicationPool{activeWorkers: 8})
|
||||||
|
stat := newActiveWorkerStat(metrics.NewRegistry())
|
||||||
|
stat.update()
|
||||||
|
if got := stat.get(); got.Curr != 8 || got.Avg != 8 || got.Max != 8 {
|
||||||
|
t.Fatalf("active pool metrics = %+v, want current/average/maximum 8", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A collector may still run after replication has been disabled.
|
||||||
|
globalReplicationPool = once.NewSingleton[ReplicationPool]()
|
||||||
|
globalReplicationPool.Set(nil)
|
||||||
|
stat.update()
|
||||||
|
if got := stat.get(); got.Curr != 0 || got.Avg != 4 || got.Max != 8 {
|
||||||
|
t.Fatalf("disabled pool metrics = %+v, want current 0, average 4, maximum 8", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user