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