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