Treat vm meminfo total-used fallback as low-trust (#1319)

This commit is contained in:
rcourtman 2026-03-25 12:49:31 +00:00
parent fba1fadccd
commit b4e4f6b92d
2 changed files with 34 additions and 2 deletions

View file

@ -19,9 +19,9 @@ const (
func vmMemorySourceReliability(source string) int {
switch strings.TrimSpace(source) {
case "meminfo-available", "meminfo-derived", "guest-agent-meminfo",
"rrd-memavailable", "rrd-memused", "host-agent", "meminfo-total-minus-used":
"rrd-memavailable", "rrd-memused", "host-agent":
return vmMemorySourceReliabilityTrusted
case "previous-snapshot":
case "meminfo-total-minus-used", "previous-snapshot":
return vmMemorySourceReliabilityFallback
case "", "cluster-resources", "listing-mem", "status-mem", "status-freemem", "status-unavailable":
return vmMemorySourceReliabilityLow

View file

@ -132,6 +132,29 @@ func TestShouldCarryForwardPreviousVMMemory_WhenTrustedGuestAgentMeminfoDropsToS
}
}
func TestShouldCarryForwardPreviousVMMemory_WhenTrustedGuestAgentMeminfoDropsToMemInfoTotalMinusUsed(t *testing.T) {
const total = uint64(16 << 30)
const trustedUsed = uint64(4 << 30)
const fallbackUsed = uint64(15 << 30)
prev := models.VM{
Type: "qemu",
Status: "running",
MemorySource: "guest-agent-meminfo",
Memory: models.Memory{
Total: int64(total),
Used: int64(trustedUsed),
Free: int64(total - trustedUsed),
Usage: safePercentage(float64(trustedUsed), float64(total)),
},
LastSeen: time.Now(),
}
if !shouldCarryForwardPreviousVMMemory(prev, "running", "meminfo-total-minus-used", total, fallbackUsed, time.Now()) {
t.Fatal("expected guest-agent meminfo reading to be preserved for one cycle when VM falls back to meminfo-total-minus-used")
}
}
func TestShouldCarryForwardPreviousVMMemory(t *testing.T) {
now := time.Now()
const total = uint64(16 << 30)
@ -214,6 +237,15 @@ func TestShouldCarryForwardPreviousVMMemory(t *testing.T) {
currentUsed: 4476033511, // ~26.05% vs previous 25%, below the 5-point threshold
want: false,
},
{
name: "preserves trusted previous reading when current source is meminfo total-minus-used",
prev: makePrevVM("rrd-memavailable", 4<<30, now),
currentStatus: "running",
currentSource: "meminfo-total-minus-used",
currentTotal: total,
currentUsed: 15 << 30,
want: true,
},
}
for _, tt := range tests {