Commit adf63e8
committed
Use the original metric's store in
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>with_labels clone1 parent c8ad029 commit adf63e8
2 files changed
Lines changed: 30 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
51 | 58 | | |
52 | 59 | | |
53 | 60 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
59 | 72 | | |
60 | 73 | | |
61 | 74 | | |
| |||
0 commit comments