Skip to content

Commit 13d8841

Browse files
QuerthDPwprzytula
authored andcommitted
metrics: unpub Metrics::new()
As the user should not be able to create metrics instance otherwise than by `get_metrics()` function, the `Metrics::new()` method shall be set to pub(crate) visibility to support only internal usage. To prevent user from constructing Metrics using Default::default(), Default implementation for Metrics was made #[cfg(test)].
1 parent 7b03c0f commit 13d8841

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

scylla/src/observability/metrics.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,31 @@ pub struct Metrics {
215215
}
216216

217217
impl Metrics {
218-
pub fn new() -> Self {
219-
Metrics::default()
218+
pub(crate) fn new() -> Self {
219+
// Configuration:
220+
// - exponent of max value: n = 16
221+
// - inverse exponent of relative error: p = 12,
222+
// - max value: N = 65535,
223+
// - relative error: e = 0.000244,
224+
// - total number of buckets: (n - p + 1) * 2^p = 20480,
225+
// - histogram size: 1.7 MiB.
226+
// Reference for calculating these values:
227+
// - https://observablehq.com/@iopsystems/h2histogram
228+
let max_value_power = 16;
229+
let grouping_power = 12;
230+
231+
Self {
232+
errors_num: AtomicU64::new(0),
233+
queries_num: AtomicU64::new(0),
234+
errors_iter_num: AtomicU64::new(0),
235+
queries_iter_num: AtomicU64::new(0),
236+
retries_num: AtomicU64::new(0),
237+
histogram: Arc::new(AtomicHistogram::new(grouping_power, max_value_power).unwrap()),
238+
meter: Arc::new(RequestRateMeter::new()),
239+
total_connections: AtomicU64::new(0),
240+
connection_timeouts: AtomicU64::new(0),
241+
request_timeouts: AtomicU64::new(0),
242+
}
220243
}
221244

222245
/// Increments counter for errors that occurred in nonpaged queries.
@@ -484,32 +507,10 @@ impl Metrics {
484507
}
485508
}
486509

510+
#[cfg(test)]
487511
impl Default for Metrics {
488512
fn default() -> Self {
489-
// Configuration:
490-
// - exponent of max value: n = 16
491-
// - inverse exponent of relative error: p = 12,
492-
// - max value: N = 65535,
493-
// - relative error: e = 0.000244,
494-
// - total number of buckets: (n - p + 1) * 2^p = 20480,
495-
// - histogram size: 1.7 MiB.
496-
// Reference for calculating these values:
497-
// - https://observablehq.com/@iopsystems/h2histogram
498-
let max_value_power = 16;
499-
let grouping_power = 12;
500-
501-
Self {
502-
errors_num: AtomicU64::new(0),
503-
queries_num: AtomicU64::new(0),
504-
errors_iter_num: AtomicU64::new(0),
505-
queries_iter_num: AtomicU64::new(0),
506-
retries_num: AtomicU64::new(0),
507-
histogram: Arc::new(AtomicHistogram::new(grouping_power, max_value_power).unwrap()),
508-
meter: Arc::new(RequestRateMeter::new()),
509-
total_connections: AtomicU64::new(0),
510-
connection_timeouts: AtomicU64::new(0),
511-
request_timeouts: AtomicU64::new(0),
512-
}
513+
Self::new()
513514
}
514515
}
515516

0 commit comments

Comments
 (0)