glean_core/traits/
rate.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// When changing this trait, ensure all operations are implemented in the
8// related type in `../metrics`. (Except test_get_num_errors)
9/// A description for the [`RateMetric`](crate::metrics::RateMetric) type.
10pub trait Rate {
11    /// Increases the numerator by `amount`.
12    ///
13    /// # Arguments
14    ///
15    /// * `amount` - The amount to increase by. Should be non-negative.
16    ///
17    /// ## Notes
18    ///
19    /// Logs an error if the `amount` is negative.
20    fn add_to_numerator(&self, amount: i32);
21
22    /// Increases the denominator by `amount`.
23    ///
24    /// # Arguments
25    ///
26    /// * `amount` - The amount to increase by. Should be non-negative.
27    ///
28    /// ## Notes
29    ///
30    /// Logs an error if the `amount` is negative.
31    fn add_to_denominator(&self, amount: i32);
32
33    /// **Exported for test purposes.**
34    ///
35    /// Gets the currently stored value as a pair of integers.
36    ///
37    /// # Arguments
38    ///
39    /// * `ping_name` - the optional name of the ping to retrieve the metric
40    ///                 for. Defaults to the first value in `send_in_pings`.
41    ///
42    /// This doesn't clear the stored value.
43    fn test_get_value<'a, S: Into<Option<&'a str>>>(&self, ping_name: S) -> Option<crate::Rate>;
44
45    /// **Exported for test purposes.**
46    ///
47    /// Gets the number of recorded errors for the given metric and error type.
48    ///
49    /// # Arguments
50    ///
51    /// * `error` - The type of error
52    ///
53    /// # Returns
54    ///
55    /// The number of errors reported.
56    fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
57}