fix: Make parseNVMeTemps deterministic by checking Composite before Sensor 1

Go map iteration order is non-deterministic, causing flaky test failures.
This fix ensures "Composite" sensor is always preferred over "Sensor 1"
by checking them in separate loops rather than relying on iteration order.
This commit is contained in:
rcourtman 2025-12-01 20:03:05 +00:00
parent f79d20296b
commit 2fdc051c11

View file

@ -675,21 +675,39 @@ func (tc *TemperatureCollector) parseNVMeTemps(chipName string, chipMap map[stri
// Extract device name from chip name (e.g., "nvme-pci-0400" -> "nvme0") // Extract device name from chip name (e.g., "nvme-pci-0400" -> "nvme0")
device := "nvme" + strings.TrimPrefix(chipName, "nvme-pci-") device := "nvme" + strings.TrimPrefix(chipName, "nvme-pci-")
// Try "Composite" first (preferred sensor name for NVMe temps)
for sensorName, sensorData := range chipMap { for sensorName, sensorData := range chipMap {
if !strings.Contains(sensorName, "Composite") {
continue
}
sensorMap, ok := sensorData.(map[string]interface{}) sensorMap, ok := sensorData.(map[string]interface{})
if !ok { if !ok {
continue continue
} }
if tempVal := extractTempInput(sensorMap); !math.IsNaN(tempVal) && tempVal > 0 {
temp.NVMe = append(temp.NVMe, models.NVMeTemp{
Device: device,
Temp: tempVal,
})
return
}
}
// Look for Composite temperature (main NVMe temp) // Fall back to "Sensor 1" if no valid Composite found
if strings.Contains(sensorName, "Composite") || strings.Contains(sensorName, "Sensor 1") { for sensorName, sensorData := range chipMap {
if tempVal := extractTempInput(sensorMap); !math.IsNaN(tempVal) && tempVal > 0 { if !strings.Contains(sensorName, "Sensor 1") {
temp.NVMe = append(temp.NVMe, models.NVMeTemp{ continue
Device: device, }
Temp: tempVal, sensorMap, ok := sensorData.(map[string]interface{})
}) if !ok {
break // Only one temp per NVMe device continue
} }
if tempVal := extractTempInput(sensorMap); !math.IsNaN(tempVal) && tempVal > 0 {
temp.NVMe = append(temp.NVMe, models.NVMeTemp{
Device: device,
Temp: tempVal,
})
return
} }
} }
} }