File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ pub struct SampleCollection<T> {
1515}
1616
1717impl < T > SampleCollection < T > {
18+ // IMPORTANT: It should never allow mutation of the samples because it would
19+ // break the invariants. If the sample's `LabelSet` is changed, it can
20+ // create duplicate `LabelSet`s even if the `LabelSet` in the `HashMap` key
21+ // is unique.
22+
1823 /// # Panics
1924 ///
2025 /// Panics if there are duplicate `LabelSets` in the provided samples.
@@ -43,7 +48,7 @@ impl SampleCollection<Counter> {
4348 let sample = self
4449 . samples
4550 . entry ( labels. clone ( ) )
46- . or_insert_with ( || Sample :: new ( Counter :: new ( 0 ) , time, labels. clone ( ) ) ) ;
51+ . or_insert_with ( || Sample :: new ( Counter :: default ( ) , time, labels. clone ( ) ) ) ;
4752
4853 sample. increment ( time) ;
4954 }
@@ -54,7 +59,7 @@ impl SampleCollection<Gauge> {
5459 let sample = self
5560 . samples
5661 . entry ( labels. clone ( ) )
57- . or_insert_with ( || Sample :: new ( Gauge :: new ( 0.0 ) , time, labels. clone ( ) ) ) ;
62+ . or_insert_with ( || Sample :: new ( Gauge :: default ( ) , time, labels. clone ( ) ) ) ;
5863
5964 sample. set ( value, time) ;
6065 }
You can’t perform that action at this time.
0 commit comments