Skip to content

Commit aebc4bc

Browse files
doehyunbaekackintosh
authored andcommitted
src/metrics/histogram.rs: Document no default buckets (prometheus#63)
As suggested and discussed in prometheus#61, this commit adds a comment that describes unavailability of default values for buckets. Signed-off-by: Doehyun Baek <[email protected]> Signed-off-by: ackintosh <[email protected]>
1 parent 626e695 commit aebc4bc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/metrics/histogram.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ use std::sync::{Arc, Mutex, MutexGuard};
1414
/// let histogram = Histogram::new(exponential_buckets(1.0, 2.0, 10));
1515
/// histogram.observe(4.2);
1616
/// ```
17+
///
18+
/// [`Histogram`] does not implement [`Default`], given that the choice of
19+
/// bucket values depends on the situation [`Histogram`] is used in. As an
20+
/// example, to measure HTTP request latency, the values suggested in the
21+
/// Golang implementation might work for you:
22+
///
23+
/// ```
24+
/// # use prometheus_client::metrics::histogram::Histogram;
25+
/// // Default values from go client(https://github.com/prometheus/client_golang/blob/5d584e2717ef525673736d72cd1d12e304f243d7/prometheus/histogram.go#L68)
26+
/// let histogram = Histogram::new(IntoIterator::into_iter([
27+
/// 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0,
28+
/// ]));
29+
/// histogram.observe(4.2);
30+
/// ```
1731
// TODO: Consider using atomics. See
1832
// https://github.com/tikv/rust-prometheus/pull/314.
1933
pub struct Histogram {

0 commit comments

Comments
 (0)