Skip to content

Return the cached value if it's not time to scan again yet#18

Merged
SuperQ merged 2 commits intoprometheus-community:masterfrom
antifuchs:fix-initial-scan-error
Aug 5, 2022
Merged

Return the cached value if it's not time to scan again yet#18
SuperQ merged 2 commits intoprometheus-community:masterfrom
antifuchs:fix-initial-scan-error

Conversation

@antifuchs
Copy link
Copy Markdown
Contributor

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.

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.
@antifuchs antifuchs mentioned this pull request Feb 11, 2021
@radicalgeek
Copy link
Copy Markdown

Worked for me, thank you very much

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
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Contributor

@lahwaacz lahwaacz Oct 9, 2021

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.

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Contributor

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.

NiceGuyIT added a commit to NiceGuyIT/smartctl_exporter that referenced this pull request Oct 14, 2021
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.
Copy link
Copy Markdown

@vagifzeynalov vagifzeynalov left a comment

Choose a reason for hiding this comment

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

lgtm

mweinelt added a commit to mweinelt/nixpkgs that referenced this pull request Nov 23, 2021
Includes a rebased version of
prometheus-community/smartctl_exporter#18 which
collided with other patchsets.
github-actions bot pushed a commit to NixOS/nixpkgs that referenced this pull request Dec 5, 2021
Includes a rebased version of
prometheus-community/smartctl_exporter#18 which
collided with other patchsets.

(cherry picked from commit 0f4340d)
@lahwaacz lahwaacz mentioned this pull request Apr 8, 2022
@SuperQ SuperQ closed this Jul 17, 2022
@SuperQ SuperQ reopened this Jul 17, 2022
@SuperQ
Copy link
Copy Markdown
Contributor

SuperQ commented Jul 17, 2022

This may need a rebase to fix the tests.

@SuperQ
Copy link
Copy Markdown
Contributor

SuperQ commented Aug 5, 2022

I'm going to merge this and deal with the build after.

@SuperQ SuperQ merged commit d33d18e into prometheus-community:master Aug 5, 2022
@SuperQ SuperQ mentioned this pull request Aug 5, 2022
@lahwaacz lahwaacz mentioned this pull request Nov 6, 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.

0.6 issues

5 participants