diff --git a/docs/dev/core/internal/payload.md b/docs/dev/core/internal/payload.md index 901910cb0..d274227de 100644 --- a/docs/dev/core/internal/payload.md +++ b/docs/dev/core/internal/payload.md @@ -101,7 +101,7 @@ sent: 1024: 2, 1116: 1, 1217: 0, 1327: 0, 1448: 1, 1579: 0 ```json { - "sum": 3, + "sum": 4612, "values": { "1024": 2, "1116": 1, diff --git a/glean-core/src/metrics/timing_distribution.rs b/glean-core/src/metrics/timing_distribution.rs index 912e486c6..cb982b868 100644 --- a/glean-core/src/metrics/timing_distribution.rs +++ b/glean-core/src/metrics/timing_distribution.rs @@ -349,4 +349,32 @@ mod test { assert_eq!(expected_json, json!(snap)); } + + #[test] + fn can_snapshot_sparse() { + use serde_json::json; + + let mut hist = Histogram::functional(2.0, 8.0); + + hist.accumulate(1024); + hist.accumulate(1024); + hist.accumulate(1116); + hist.accumulate(1448); + + let snap = snapshot(&hist); + + let expected_json = json!({ + "sum": 4612, + "values": { + "1024": 2, + "1116": 1, + "1217": 0, + "1327": 0, + "1448": 1, + "1579": 0, + }, + }); + + assert_eq!(expected_json, json!(snap)); + } }