-
Notifications
You must be signed in to change notification settings - Fork 89
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 the cached value if it's not time to scan again yet #18
Return the cached value if it's not time to scan again yet #18
Conversation
This should ensure that if we have a valid value cached (which ought to be every time after the first scan), we return it as metrics. This fixes the crashes that would happen if queries happened earlier than the re-scan interval allowed.
Worked for me, thank you very much |
json, ok := readSMARTctl(device) | ||
if ok { | ||
jsonCache[device] = JSONCache{JSON: json, LastCollect: time.Now()} | ||
return jsonCache[device].JSON, nil | ||
} | ||
return gjson.Parse("{}"), fmt.Errorf("smartctl returned bad data for device %s", device) | ||
} | ||
return gjson.Parse("{}"), fmt.Errorf("Too early collect called for device %s", device) | ||
return cacheValue.JSON, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like originally not assumed to return already existent value from cache. Instead it supposed to return nothing and to me it seems more logical than return duplicated values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if the polling interval in smartctl_exporter
is e.g. 300s and prometheus scrapes it more often, or if there are multiple scrapers, only the first time a meaningful value is returned and everything next gets nothing until the 300s pass? That does not sound right either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also agree. Initially I was thinking that it should be managed by Prometheus only to reduce configurations. But at the end didn't want to be too rude and remove it completely. If the owner added it, perhaps he had some reasons?😁
I'm simply using 0s in my config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, removing caching may be the easiest / best thing to fix up this exporter.
Combines checks as [suggested](prometheus-community#18 (comment)) Add type cast
We can express this in a single if statement, so it takes fewer lines to do the "should we check again" check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Includes a rebased version of prometheus-community/smartctl_exporter#18 which collided with other patchsets.
Includes a rebased version of prometheus-community/smartctl_exporter#18 which collided with other patchsets. (cherry picked from commit 0f4340d)
This may need a rebase to fix the tests. |
I'm going to merge this and deal with the build after. |
This fixes #13: Since we have a value cached, we should return it to the collector if it gets queried before the interval to re-scan SMART data expires. This prevents the crash.