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::{DistributionData, ErrorType, TestGetValue};
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: TestGetValue<DistributionData> {
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 number of recorded errors for the given error type.
50    ///
51    /// # Arguments
52    ///
53    /// * `error` - The type of error
54    ///
55    /// # Returns
56    ///
57    /// The number of errors recorded.
58    fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
59}