mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-02 10:09:02 +01:00
A guest-agent command caught by a freeze can time out in Proxmox and leave a stale reply that the thaw then reads (#2439). The lock and replication checks cannot stop a read already running when a freeze starts, so exposure scales with how often commands go out, and get-fsinfo was the only one sent on every poll. Metadata is cached for 5 minutes and meminfo for 60 seconds. Reuse a completed reply for 55 seconds, so 10-second polls read about every minute. This lowers the odds of that collision. It does not remove the race. A reused reading stays current, so disk alerts keep evaluating it, but it never passes for a new read: its observation and evidence times stay with the original read, so retention still ends ten minutes after it, and without a status reply a reuse does not report the agent as available. A stopped guest, an unavailable agent or falling uptime drops the reply. History keeps a point per poll, as cached meminfo does. Writing only fresh reads would break the drawer's disk line into dots, because it breaks a series wherever another series in its panel has a reading and it does not. Contract-Neutral: agent-lifecycle only hosts the monitor field and cache cleanup here; Pulse agent lifecycle is unchanged
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package monitoring
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
)
|
|
|
|
// Cancellation is not completion. The obsolete owner remains in the map until
|
|
// its call returns; neither a janitor nor a new lifecycle releases its fence.
|
|
// Guarded by rrdCacheMu, including publication in getVMAgentMemoryAvailability.
|
|
type guestMemoryFetch struct {
|
|
cancel context.CancelFunc
|
|
invalidated bool
|
|
}
|
|
|
|
func (m *Monitor) invalidateGuestMemoryFetchLocked(key string) {
|
|
if fetch := m.vmAgentMemInFlight[key]; fetch != nil {
|
|
fetch.invalidated = true
|
|
fetch.cancel()
|
|
}
|
|
}
|
|
|
|
func (m *Monitor) clearGuestMemoryCache(instanceName, node string, vmid int) {
|
|
if m == nil {
|
|
return
|
|
}
|
|
key := guestMemoryCacheKey(instanceName, node, vmid)
|
|
m.rrdCacheMu.Lock()
|
|
m.invalidateGuestMemoryFetchLocked(key)
|
|
delete(m.vmAgentMemCache, key)
|
|
m.rrdCacheMu.Unlock()
|
|
}
|
|
|
|
// PVE node names do not contain '/'. Split the last two components, not an
|
|
// instance prefix: a connection named "site/other" is not owned by "site".
|
|
func guestMemoryCacheBelongsToInstance(key, instanceName string) bool {
|
|
end := strings.LastIndexByte(key, '/')
|
|
if end < 0 {
|
|
return false
|
|
}
|
|
end = strings.LastIndexByte(key[:end], '/')
|
|
return end >= 0 && key[:end] == instanceName
|
|
}
|
|
|
|
func (m *Monitor) retireGuestMemoryCache(instanceName string) {
|
|
m.rrdCacheMu.Lock()
|
|
defer m.rrdCacheMu.Unlock()
|
|
for key := range m.vmAgentMemInFlight {
|
|
if guestMemoryCacheBelongsToInstance(key, instanceName) {
|
|
m.invalidateGuestMemoryFetchLocked(key)
|
|
}
|
|
}
|
|
for key := range m.vmAgentMemCache {
|
|
if guestMemoryCacheBelongsToInstance(key, instanceName) {
|
|
delete(m.vmAgentMemCache, key)
|
|
}
|
|
}
|
|
for key := range m.vmFSInfoCache {
|
|
if guestMemoryCacheBelongsToInstance(key, instanceName) {
|
|
delete(m.vmFSInfoCache, key)
|
|
}
|
|
}
|
|
}
|