Skip to content

Commit fe88861

Browse files
committed
docs: add comment
1 parent fbf3cdc commit fe88861

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/metrics/src/sample_collection.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ pub struct SampleCollection<T> {
1515
}
1616

1717
impl<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
}

0 commit comments

Comments
 (0)