fix(agent): handle 32-bit wrap of disk I/O time counters (#2407)

This commit is contained in:
Ludwig J. Marx
2026-09-24 23:39:53 +02:00
committed by GitHub
parent 6141b15f03
commit b5ef015451
3 changed files with 115 additions and 6 deletions

View File

@@ -3,7 +3,9 @@
package agent
import (
"math"
"os"
"runtime"
"strings"
"testing"
"time"
@@ -1041,3 +1043,17 @@ func TestInitializeDiskIoStatsResetsTrackedDevices(t *testing.T) {
assert.Equal(t, uint64(50), agent.fsStats["sdb"].TotalRead)
assert.Equal(t, uint64(60), agent.fsStats["sdb"].TotalWrite)
}
func TestIoTimeDelta(t *testing.T) {
assert.Equal(t, uint64(300), ioTimeDelta(1200, 900))
// A lower value is a 32-bit wrap only on Linux. Other platforms
// report 64-bit counters, so there it is a reset.
var want uint64
if runtime.GOOS == "linux" {
want = 1200
}
assert.Equal(t, want, ioTimeDelta(200, math.MaxUint32+1-1000))
assert.Equal(t, uint64(0), ioTimeDelta(200, math.MaxUint32+1000))
}