Create metrics slice when necessary (#17809)

This commit is contained in:
Yang Wu 2023-08-07 17:21:22 +08:00 committed by GitHub
parent 8666c55ca6
commit 23e4895dfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1214,7 +1214,7 @@ func getMinioProcMetrics() *MetricsGroup {
if runtime.GOOS == "windows" {
return nil
}
metrics = make([]Metric, 0, 20)
p, err := procfs.Self()
if err != nil {
logger.LogOnceIf(ctx, err, string(nodeMetricNamespace))
@ -1227,6 +1227,8 @@ func getMinioProcMetrics() *MetricsGroup {
stat, _ := p.Stat()
startTime, _ := stat.StartTime()
metrics = make([]Metric, 0, 20)
if openFDs > 0 {
metrics = append(metrics,
Metric{
@ -1794,7 +1796,6 @@ func getMinioHealingMetrics() *MetricsGroup {
cacheInterval: 10 * time.Second,
}
mg.RegisterRead(func(_ context.Context) (metrics []Metric) {
metrics = make([]Metric, 0, 5)
bgSeq, exists := globalBackgroundHealState.getHealSequenceByToken(bgHealingUUID)
if !exists {
return
@ -1804,6 +1805,7 @@ func getMinioHealingMetrics() *MetricsGroup {
return
}
metrics = make([]Metric, 0, 5)
metrics = append(metrics, Metric{
Description: getHealLastActivityTimeMD(),
Value: float64(time.Since(bgSeq.lastHealActivity)),