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