Skip to content
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

return error if cpufreq's are empty #426

Merged
merged 1 commit into from
Dec 22, 2022

Conversation

binjip978
Copy link
Contributor

Signed-off-by: Sergei Semenchuk [email protected]

@binjip978
Copy link
Contributor Author

fixes prometheus/node_exporter#2198 when collector successful but empty

@@ -178,6 +180,10 @@ func (fs FS) SystemCpufreq() ([]SystemCPUCpufreqStats, error) {
return nil, err
}

if len(systemCpufreq) == 0 {
return nil, fmt.Errorf("could not find any cpufreq files")
Copy link
Member

Choose a reason for hiding this comment

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

Two issues. We need to make an identifiable error so that downstream can tell a "not found" vs a parsing error.

For example, we could return os.ErrNotExist.

Or we make a new procfs error var with errors.New().

This way we can use errors.Is().

Copy link
Member

Choose a reason for hiding this comment

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

Maybe return fmt.Errorf("could not find any cpufreq files: %w", os.ErrNotExist)?

Signed-off-by: Sergei Semenchuk <[email protected]>
@binjip978 binjip978 force-pushed the return-error-on-empty-cpu-freq branch from 24c58f6 to b9fa528 Compare December 21, 2022 17:58
@binjip978 binjip978 requested a review from SuperQ December 21, 2022 17:59
@SuperQ SuperQ merged commit 0c4b3aa into prometheus:master Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants