glean_core/traits/
dual_labeled_counter.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::{CounterMetric, ErrorType, TestGetValue};
6use std::collections::HashMap;
7
8/// A description for the [`DualLabeledCounterMetric`](crate::metrics::DualLabeledCounterMetric) type.
9///
10/// When changing this trait, make sure all the operations are
11/// implemented in the related type in `../metrics/`.
12pub trait DualLabeledCounter: TestGetValue<Output = HashMap<String, HashMap<String, i32>>> {
13    /// Gets a specific counter for a given key/category pair.
14    ///
15    /// If a set of acceptable keys or categorires were specified in the `metrics.yaml` file,
16    /// and the given label is not in the set, it will be recorded under the special `OTHER_LABEL` label.
17    ///
18    /// If a set of acceptable keys and/or categories was not specified in the `metrics.yaml` file,
19    /// only the first 16 unique labels will be used.
20    /// After that, any additional labels will be recorded under the special `OTHER_LABEL` label.
21    ///
22    /// Labels must have a maximum of 111 characters, and may comprise any printable ASCII characters.
23    /// If an invalid label is used, the metric will be recorded in the special `OTHER_LABEL` label.
24    fn get(&self, key: &str, category: &str) -> CounterMetric;
25
26    /// **Exported for test purposes.**
27    ///
28    /// Gets the number of recorded errors for the given metric and error type.
29    ///
30    /// # Arguments
31    ///
32    /// * `error` - The type of error
33    ///
34    /// # Returns
35    ///
36    /// The number of errors reported.
37    fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
38}