Skip to content

Dont check for temperatures in /thermal_zone where mode=disabled #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions sysfs/class_thermal.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ func (fs FS) ClassThermalZoneStats() ([]ClassThermalZoneStats, error) {
}

func parseClassThermalZone(zone string) (ClassThermalZoneStats, error) {

// Optional attributes.
modeContent, err := util.SysReadFile(filepath.Join(zone, "mode"))
if err != nil && !os.IsNotExist(err) && !os.IsPermission(err) {
return ClassThermalZoneStats{}, err
}

if strings.TrimSpace(modeContent) == "disabled" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically we avoid making decisions like this in the library. Rather, we simply expose the mode as a raw attribute and allow the downstream consumer to decide what to do.

Copy link
Author

@Saumya40-codes Saumya40-codes Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohkk

Maybe thats something which can be handled from node exporter itself only?

here, as was stated in main issue, we check while reading the Zone temp and if the error turns out to be of type os.ErrInvalid then we can return an empty struct (and return an error when necessary (i.e. in the case of os.IsNotExist(err) && os.IsPermission(err)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we may need to refactor that error handling.

return ClassThermalZoneStats{}, syscall.ENODATA
}

zoneMode := util.ParseBool(modeContent)

// Required attributes.
zoneType, err := util.SysReadFile(filepath.Join(zone, "type"))
if err != nil {
Expand All @@ -77,13 +90,6 @@ func parseClassThermalZone(zone string) (ClassThermalZoneStats, error) {
return ClassThermalZoneStats{}, err
}

// Optional attributes.
mode, err := util.SysReadFile(filepath.Join(zone, "mode"))
if err != nil && !os.IsNotExist(err) && !os.IsPermission(err) {
return ClassThermalZoneStats{}, err
}
zoneMode := util.ParseBool(mode)

var zonePassive *uint64
passive, err := util.ReadUintFromFile(filepath.Join(zone, "passive"))
if os.IsNotExist(err) || os.IsPermission(err) {
Expand Down
Loading