glean_core/traits/custom_distribution.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5use crate::ErrorType;
6
7/// A description for the
8/// [`CustomDistributionMetric`](crate::metrics::CustomDistributionMetric) type.
9///
10/// When changing this trait, make sure all the operations are
11/// implemented in the related type in `../metrics/`.
12pub trait CustomDistribution {
13 /// Accumulates the provided signed samples in the metric.
14 ///
15 /// This is required so that the platform-specific code can provide us with
16 /// 64 bit signed integers if no `u64` comparable type is available. This
17 /// will take care of filtering and reporting errors for any provided negative
18 /// sample.
19 ///
20 /// # Arguments
21 ///
22 /// - `samples` - The vector holding the samples to be recorded by the metric.
23 ///
24 /// ## Notes
25 ///
26 /// Discards any negative value in `samples` and report an
27 /// [`ErrorType::InvalidValue`](crate::ErrorType::InvalidValue) for each of
28 /// them.
29 fn accumulate_samples_signed(&self, samples: Vec<i64>);
30
31 /// Accumulates precisely one signed sample in the metric.
32 ///
33 /// This is required so that the platform-specific code can provide us with a
34 /// 64 bit signed integer if no `u64` comparable type is available. This
35 /// will take care of filtering and reporting errors.
36 ///
37 /// # Arguments
38 ///
39 /// - `sample` - The singular sample to be recorded by the metric.
40 ///
41 /// ## Notes
42 ///
43 /// Discards any negative value of `sample` and reports an
44 /// [`ErrorType::InvalidValue`](crate::ErrorType::InvalidValue).
45 fn accumulate_single_sample_signed(&self, sample: i64);
46
47 /// **Exported for test purposes.**
48 ///
49 /// Gets the currently stored histogram.
50 ///
51 /// This doesn't clear the stored value.
52 ///
53 /// # Arguments
54 ///
55 /// * `ping_name` - represents the optional name of the ping to retrieve the
56 /// metric for. Defaults to the first value in `send_in_pings`.
57 fn test_get_value<'a, S: Into<Option<&'a str>>>(
58 &self,
59 ping_name: S,
60 ) -> Option<crate::metrics::DistributionData>;
61
62 /// **Exported for test purposes.**
63 ///
64 /// Gets the number of recorded errors for the given error type.
65 ///
66 /// # Arguments
67 ///
68 /// * `error` - The type of error
69 ///
70 /// # Returns
71 ///
72 /// The number of errors recorded.
73 fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
74}