-
Notifications
You must be signed in to change notification settings - Fork 149
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
Fix with labels
bug reported in issue #225
#227
Merged
Merged
Conversation
This file contains 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
dmagliola
force-pushed
the
fix_with_labels
branch
from
June 12, 2021 18:00
6627a5d
to
316faf7
Compare
3 similar comments
Sinjo
reviewed
Jun 16, 2021
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.
Few comments, mostly looks good!
dmagliola
force-pushed
the
fix_with_labels
branch
2 times, most recently
from
June 18, 2021 20:19
52b301c
to
25f0d1e
Compare
This reproduces the error reported in issue #225, where `with_labels` doesn't work at all the way it is intended, and in addition to that, if you're using DirectFileStore, it can very easily corrupt your files. The problem is the new metric received after calling `with_labels` is a copy of the original, with the labels pre-set, but it has **its own internal store**, so it doesn't actually impact the values of the original metric, which is what gets exported by the registry. Signed-off-by: Daniel Magliola <dmagliola@crystalgears.com>
When calling `with_labels` on a metric object (let's call it "the original"), we instantiate a new metric (the "clone") that is identical except that it has some more pre-set labels, that allow the caller to observe it without having to specify the labels every time. "currying", if you will. The problem with the existing code (as exemplified by issue #225, and by the tests introduced in the previous commit), is that as part of making this new metric, we end up instantiating a new store for this metric. With in-memory stores, the new one will be empty. With file stores, it'll bring over the data from the original metric until the point the clone gets observed once, at which point they fork, while pointing at the same file and keeping separate internal state. An almost sure recipe for file corruption. And when exporting, only the data in the "original" metric's store will be exported, the clone's will be ignored, assuming files didn't get corrupted. The fix is not particularly elegant, but I don't see any way around it: we replace the internal store of the "clone" metric with the one from the "original", through the use of a protected method. The only real alternative is getting rid of `with_labels`, which is a nice-to-have for convenience and performance, but not a necessity. Signed-off-by: Daniel Magliola <dmagliola@crystalgears.com>
The test that reproduces our file corruption issue follows a very specific set of steps to actually corrupt the files, and it's probably impossible to figure out why. Explaining those specific steps, however, requires explaining a lot about the internals of `FileMappedDict`, of the files we store, and how corruption happens in the first place, before we can understand why we need those specific steps to reproduce it. I hope this explanation makes sense. Signed-off-by: Daniel Magliola <dmagliola@crystalgears.com>
dmagliola
force-pushed
the
fix_with_labels
branch
from
June 20, 2021 16:27
25f0d1e
to
097cb04
Compare
Sinjo
approved these changes
Jan 9, 2022
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.
When calling
with_labels
on a metric object (let's call it "the original"), we instantiate a new metric (the "clone") that is identical except that it has some more pre-set labels, that allow the caller to observe it without having to specify the labels every time."currying", if you will.
The problem with the existing code (as exemplified by issue #225), is that as part of making this new metric, we end up instantiating a new store for this metric.
With in-memory stores, the new one will be empty. With file stores, it'll bring over the data from the original metric until the
gets observed once, at which point they fork, while pointing at the same file and keeping separate internal state. An almost sure recipe for file corruption.
And when exporting, only the data in the "original" metric's store will be exported, the clone's will be ignored, assuming files didn't get corrupted.
The fix is not particularly elegant, but I don't see any way around it: we replace the internal store of the "clone" metric with the
the "original", through the use of a protected method.
The only real alternative is getting rid of
with_labels
, which is a nice-to-have for convenience and performance, but not a necessity.This PR is a "patch" version bump, and we should cherry-pick it out of master and cut a new patch version (as
master
contains breaking changes intended for3.0
at the moment)