Debian Codegraph @

third_party/rust/glean-core/src/metrics/remote_settings_config.rs

raw
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
5 use std::collections::HashMap;
6
7 use malloc_size_of_derive::MallocSizeOf;
8 use serde::{Deserialize, Serialize};
9
10 /// Represents a list of metrics and an associated boolean property
11 /// indicating if the metric is enabled from the remote-settings
12 /// configuration store.
13 ///
14 /// The expected format of this data is stringified JSON in the following format:
15 ///
16 /// ```json
17 /// {
18 /// "category.metric_name": true
19 /// }
20 /// ```
21 #[derive(Serialize, Deserialize, Debug, Clone, Default, MallocSizeOf)]
22 pub struct RemoteSettingsConfig {
23 /// This is a `HashMap` consisting of base_identifiers as keys
24 /// and bool values representing an override for the `disabled`
25 /// property of the metric, only inverted to reduce confusion.
26 /// If a particular metric has a value of `true` here, it means
27 /// the default of the metric will be overriden and set to the
28 /// enabled state.
29 #[serde(default)]
30 pub metrics_enabled: HashMap<String, bool>,
31
32 /// This is a `HashMap` consisting of ping names as keys and
33 /// boolean values representing on override for the default
34 /// enabled state of the ping of the same name.
35 #[serde(default)]
36 pub pings_enabled: HashMap<String, bool>,
37
38 /// The threshold of events that will be buffered before an events ping is
39 /// collected and submitted.
40 /// It overrides the value configured at initialization time.
41 #[serde(default)]
42 pub event_threshold: Option<u32>,
43 }
44
45 impl RemoteSettingsConfig {
46 /// Creates a new RemoteSettingsConfig
47 pub fn new() -> Self {
48 Default::default()
49 }
50 }
51
52 impl TryFrom<String> for RemoteSettingsConfig {
53 type Error = crate::ErrorKind;
54
55 fn try_from(json: String) -> Result<Self, Self::Error> {
56 match serde_json::from_str(json.as_str()) {
57 Ok(config) => Ok(config),
58 Err(e) => Err(crate::ErrorKind::Json(e)),
59 }
60 }
61 }