thermal_zone: Skip zones with per-zone read errors - #3807
Open
neoLsH wants to merge 1 commit into
Open
Conversation
procfs surfaces per-zone sysfs read failures via the ReadErrors field of ClassThermalZoneStats, following the original "skip failed zones" intent of prometheus/procfs#712 and the later error-handling refactor in prometheus/procfs#794. The thermal_zone collector ignored this field and unconditionally reported stats.Temp, so a zone whose temp file could not be read (offline zone, transient driver error, permission issue, etc.) was exported as a bogus 0 Celsius instead of being dropped. Such a fake reading can trigger false low-temperature alerts. Skip zones with a non-nil ReadErrors and log them at debug level, so only zones whose temperature was read successfully are exported. This is complementary to prometheus#3657 and does not change its behavior: procfs deliberately does not record EINVAL from a temp read in ReadErrors, so an EINVAL zone still has ReadErrors == nil and keeps being reported with Temp == 0, exactly as prometheus#3657 intended. Only genuine per-zone read failures that procfs flags in ReadErrors are affected here. Signed-off-by: neoLsH <43921685+neoLsH@users.noreply.github.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Makes the
thermal_zonecollector respect procfs' per-zoneReadErrors, so a thermal zone whose sysfs attributes could not be read is skipped instead of being exported as a bogus0°C.Background
procfs.ClassThermalZoneStatsreturns every globbedthermal_zone<N>and records per-zone sysfs read failures in theReadErrorsfield (anerrors.Joinof the type/policy/temp/mode/passive read errors). This is the outcome of prometheus/procfs#712 ("skip failed zones") and the later refactor in prometheus/procfs#794.The collector currently ignores
ReadErrorsand unconditionally emitsfloat64(stats.Temp)/1000.0. When a zone'stempread fails (offline zone, transient driver error, permission issue, etc.), procfs leavesTempat0, so node_exporter exportsnode_thermal_zone_temp 0— a silently wrong reading that can trigger false "low temperature" alerts.The fix
Only zones whose attributes were read successfully are exported.
Interaction with #3657
#3657 added
syscall.EINVALto the whole-collector error path. This PR is complementary and does not change that behavior: procfs deliberately does not recordEINVALfrom atempread inReadErrors(see the!errors.Is(err, os.ErrInvalid)guard inparseClassThermalZone), so an EINVAL zone still hasReadErrors == niland continues to be reported withTemp == 0, exactly as #3657 intended. This PR only affects zones with genuine read failures that procfs does flag inReadErrors.Testing
GOOS=linux go build ./... && go vet ./collector && go test -c ./collectorare clean.thermal_zone0, a healthy zone withReadErrors == nil) is unaffected: it still exportsnode_thermal_zone_temp{...} 12.376, so the e2e golden output does not change.thermal_zonehas no unit test today andprocfs/sysfsis Linux-only, so a macOS-local runtime test isn't possible; verification relies on Linux CI (build + e2e). I kept the change minimal and did not add a failed-zone fixture to the sharedfixtures/systree to avoid perturbing the e2e golden output. Happy to add a dedicated Linux unit test using a temp-dir sysfs fixture if reviewers prefer.Signed-off-by: neoLsH 43921685+neoLsH@users.noreply.github.com