summaryrefslogtreecommitdiffstats
path: root/third_party/rust/glean-core/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /third_party/rust/glean-core/src
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/glean-core/src')
-rw-r--r--third_party/rust/glean-core/src/common_metric_data.rs1
-rw-r--r--third_party/rust/glean-core/src/core/mod.rs9
-rw-r--r--third_party/rust/glean-core/src/database/mod.rs1
-rw-r--r--third_party/rust/glean-core/src/debug.rs1
-rw-r--r--third_party/rust/glean-core/src/dispatcher/mod.rs5
-rw-r--r--third_party/rust/glean-core/src/error_recording.rs1
-rw-r--r--third_party/rust/glean-core/src/event_database/mod.rs3
-rw-r--r--third_party/rust/glean-core/src/glean.udl1
-rw-r--r--third_party/rust/glean-core/src/histogram/mod.rs1
-rw-r--r--third_party/rust/glean-core/src/internal_pings.rs11
-rw-r--r--third_party/rust/glean-core/src/lib.rs5
-rw-r--r--third_party/rust/glean-core/src/lib_unit_tests.rs82
-rw-r--r--third_party/rust/glean-core/src/metrics/event.rs16
-rw-r--r--third_party/rust/glean-core/src/metrics/memory_unit.rs2
-rw-r--r--third_party/rust/glean-core/src/metrics/metrics_enabled_config.rs2
-rw-r--r--third_party/rust/glean-core/src/metrics/ping.rs31
-rw-r--r--third_party/rust/glean-core/src/metrics/string.rs2
-rw-r--r--third_party/rust/glean-core/src/metrics/text.rs2
-rw-r--r--third_party/rust/glean-core/src/metrics/time_unit.rs1
-rw-r--r--third_party/rust/glean-core/src/metrics/timespan.rs1
-rw-r--r--third_party/rust/glean-core/src/metrics/timing_distribution.rs2
-rw-r--r--third_party/rust/glean-core/src/metrics/url.rs2
-rw-r--r--third_party/rust/glean-core/src/storage/mod.rs4
-rw-r--r--third_party/rust/glean-core/src/traits/event.rs1
-rw-r--r--third_party/rust/glean-core/src/upload/directory.rs2
-rw-r--r--third_party/rust/glean-core/src/upload/mod.rs4
-rw-r--r--third_party/rust/glean-core/src/upload/request.rs2
27 files changed, 133 insertions, 62 deletions
diff --git a/third_party/rust/glean-core/src/common_metric_data.rs b/third_party/rust/glean-core/src/common_metric_data.rs
index 033cbe1472..9bda9bb462 100644
--- a/third_party/rust/glean-core/src/common_metric_data.rs
+++ b/third_party/rust/glean-core/src/common_metric_data.rs
@@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-use std::convert::TryFrom;
use std::sync::atomic::{AtomicU8, Ordering};
use crate::error::{Error, ErrorKind};
diff --git a/third_party/rust/glean-core/src/core/mod.rs b/third_party/rust/glean-core/src/core/mod.rs
index 30f9a34f11..f69f0c3868 100644
--- a/third_party/rust/glean-core/src/core/mod.rs
+++ b/third_party/rust/glean-core/src/core/mod.rs
@@ -120,6 +120,7 @@ where
/// rate_limit: None,
/// enable_event_timestamps: true,
/// experimentation_id: None,
+/// enable_internal_pings: true,
/// };
/// let mut glean = Glean::new(cfg).unwrap();
/// let ping = PingType::new("sample", true, false, true, true, vec![]);
@@ -208,7 +209,7 @@ impl Glean {
core_metrics: CoreMetrics::new(),
additional_metrics: AdditionalMetrics::new(),
database_metrics: DatabaseMetrics::new(),
- internal_pings: InternalPings::new(),
+ internal_pings: InternalPings::new(cfg.enable_internal_pings),
upload_manager,
data_path: PathBuf::from(&cfg.data_path),
application_id,
@@ -288,7 +289,9 @@ impl Glean {
}
// We set this only for non-subprocess situations.
- glean.schedule_metrics_pings = cfg.use_core_mps;
+ // If internal pings are disabled, we don't set up the MPS either,
+ // it wouldn't send any data anyway.
+ glean.schedule_metrics_pings = cfg.enable_internal_pings && cfg.use_core_mps;
// We only scan the pendings pings directories **after** dealing with the upload state.
// If upload is disabled, we delete all pending pings files
@@ -305,6 +308,7 @@ impl Glean {
data_path: &str,
application_id: &str,
upload_enabled: bool,
+ enable_internal_pings: bool,
) -> Self {
let cfg = InternalConfiguration {
data_path: data_path.into(),
@@ -320,6 +324,7 @@ impl Glean {
rate_limit: None,
enable_event_timestamps: true,
experimentation_id: None,
+ enable_internal_pings,
};
let mut glean = Self::new(cfg).unwrap();
diff --git a/third_party/rust/glean-core/src/database/mod.rs b/third_party/rust/glean-core/src/database/mod.rs
index af473c98d9..0dbf0220bc 100644
--- a/third_party/rust/glean-core/src/database/mod.rs
+++ b/third_party/rust/glean-core/src/database/mod.rs
@@ -824,7 +824,6 @@ mod test {
use super::*;
use crate::tests::new_glean;
use std::collections::HashMap;
- use std::path::Path;
use tempfile::tempdir;
#[test]
diff --git a/third_party/rust/glean-core/src/debug.rs b/third_party/rust/glean-core/src/debug.rs
index a572a02b8f..88f807bd88 100644
--- a/third_party/rust/glean-core/src/debug.rs
+++ b/third_party/rust/glean-core/src/debug.rs
@@ -240,7 +240,6 @@ fn validate_source_tags(tags: &Vec<String>) -> bool {
#[cfg(test)]
mod test {
use super::*;
- use std::env;
#[test]
fn debug_option_is_correctly_loaded_from_env() {
diff --git a/third_party/rust/glean-core/src/dispatcher/mod.rs b/third_party/rust/glean-core/src/dispatcher/mod.rs
index 48efa4ef96..ead58fb867 100644
--- a/third_party/rust/glean-core/src/dispatcher/mod.rs
+++ b/third_party/rust/glean-core/src/dispatcher/mod.rs
@@ -360,9 +360,8 @@ impl Dispatcher {
#[cfg(test)]
mod test {
use super::*;
- use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
- use std::sync::{Arc, Mutex};
- use std::{thread, time::Duration};
+ use std::sync::atomic::AtomicU8;
+ use std::sync::Mutex;
fn enable_test_logging() {
// When testing we want all logs to go to stdout/stderr by default,
diff --git a/third_party/rust/glean-core/src/error_recording.rs b/third_party/rust/glean-core/src/error_recording.rs
index aaf850d019..fa828242f1 100644
--- a/third_party/rust/glean-core/src/error_recording.rs
+++ b/third_party/rust/glean-core/src/error_recording.rs
@@ -12,7 +12,6 @@
//! but are not actually used directly, since the `send_in_pings` value needs to match the pings of the metric that is erroring (plus the "metrics" ping),
//! not some constant value that we could define in `metrics.yaml`.
-use std::convert::TryFrom;
use std::fmt::Display;
use crate::common_metric_data::CommonMetricDataInternal;
diff --git a/third_party/rust/glean-core/src/event_database/mod.rs b/third_party/rust/glean-core/src/event_database/mod.rs
index d83e56fbec..50b2488a4c 100644
--- a/third_party/rust/glean-core/src/event_database/mod.rs
+++ b/third_party/rust/glean-core/src/event_database/mod.rs
@@ -4,7 +4,6 @@
use std::cmp::Ordering;
use std::collections::HashMap;
-use std::convert::TryFrom;
use std::fs;
use std::fs::{create_dir_all, File, OpenOptions};
use std::io::BufRead;
@@ -638,8 +637,8 @@ impl EventDatabase {
#[cfg(test)]
mod test {
use super::*;
+ use crate::test_get_num_recorded_errors;
use crate::tests::new_glean;
- use crate::{test_get_num_recorded_errors, CommonMetricData};
use chrono::{TimeZone, Timelike};
#[test]
diff --git a/third_party/rust/glean-core/src/glean.udl b/third_party/rust/glean-core/src/glean.udl
index e68a57ea4c..dc71fea594 100644
--- a/third_party/rust/glean-core/src/glean.udl
+++ b/third_party/rust/glean-core/src/glean.udl
@@ -90,6 +90,7 @@ dictionary InternalConfiguration {
PingRateLimit? rate_limit;
boolean enable_event_timestamps;
string? experimentation_id;
+ boolean enable_internal_pings;
};
// How to specify the rate pings may be uploaded before they are throttled.
diff --git a/third_party/rust/glean-core/src/histogram/mod.rs b/third_party/rust/glean-core/src/histogram/mod.rs
index 282b02e0ab..6e2880dffa 100644
--- a/third_party/rust/glean-core/src/histogram/mod.rs
+++ b/third_party/rust/glean-core/src/histogram/mod.rs
@@ -5,7 +5,6 @@
//! A simple histogram implementation for exponential histograms.
use std::collections::HashMap;
-use std::convert::TryFrom;
use serde::{Deserialize, Serialize};
diff --git a/third_party/rust/glean-core/src/internal_pings.rs b/third_party/rust/glean-core/src/internal_pings.rs
index 07c3849006..1cf32feb60 100644
--- a/third_party/rust/glean-core/src/internal_pings.rs
+++ b/third_party/rust/glean-core/src/internal_pings.rs
@@ -19,9 +19,9 @@ pub struct InternalPings {
}
impl InternalPings {
- pub fn new() -> InternalPings {
+ pub fn new(enabled: bool) -> InternalPings {
InternalPings {
- baseline: PingType::new(
+ baseline: PingType::new_internal(
"baseline",
true,
true,
@@ -32,8 +32,9 @@ impl InternalPings {
"dirty_startup".to_string(),
"inactive".to_string(),
],
+ enabled,
),
- metrics: PingType::new(
+ metrics: PingType::new_internal(
"metrics",
true,
false,
@@ -46,8 +47,9 @@ impl InternalPings {
"tomorrow".to_string(),
"upgrade".to_string(),
],
+ enabled,
),
- events: PingType::new(
+ events: PingType::new_internal(
"events",
true,
false,
@@ -58,6 +60,7 @@ impl InternalPings {
"inactive".to_string(),
"max_capacity".to_string(),
],
+ enabled,
),
deletion_request: PingType::new(
"deletion-request",
diff --git a/third_party/rust/glean-core/src/lib.rs b/third_party/rust/glean-core/src/lib.rs
index b7f9d73beb..af68fde264 100644
--- a/third_party/rust/glean-core/src/lib.rs
+++ b/third_party/rust/glean-core/src/lib.rs
@@ -17,7 +17,6 @@
use std::borrow::Cow;
use std::collections::HashMap;
-use std::convert::TryFrom;
use std::fmt;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
@@ -25,7 +24,7 @@ use std::thread;
use std::time::Duration;
use crossbeam_channel::unbounded;
-use log::{self, LevelFilter};
+use log::LevelFilter;
use once_cell::sync::{Lazy, OnceCell};
use uuid::Uuid;
@@ -136,6 +135,8 @@ pub struct InternalConfiguration {
/// be noted that this has an underlying StringMetric and so should conform to the limitations that
/// StringMetric places on length, etc.
pub experimentation_id: Option<String>,
+ /// Whether to enable internal pings. Default: true
+ pub enable_internal_pings: bool,
}
/// How to specify the rate at which pings may be uploaded before they are throttled.
diff --git a/third_party/rust/glean-core/src/lib_unit_tests.rs b/third_party/rust/glean-core/src/lib_unit_tests.rs
index cb1e4129d8..14d3b98417 100644
--- a/third_party/rust/glean-core/src/lib_unit_tests.rs
+++ b/third_party/rust/glean-core/src/lib_unit_tests.rs
@@ -6,12 +6,10 @@
// the lib.rs file.
use std::collections::HashSet;
-use std::iter::FromIterator;
use serde_json::json;
use super::*;
-use crate::metrics::{StringMetric, TimeUnit, TimespanMetric, TimingDistributionMetric};
const GLOBAL_APPLICATION_ID: &str = "org.mozilla.glean.test.app";
pub fn new_glean(tempdir: Option<tempfile::TempDir>) -> (Glean, tempfile::TempDir) {
@@ -21,7 +19,7 @@ pub fn new_glean(tempdir: Option<tempfile::TempDir>) -> (Glean, tempfile::TempDi
None => tempfile::tempdir().unwrap(),
};
let tmpname = dir.path().display().to_string();
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
(glean, dir)
}
@@ -41,7 +39,7 @@ fn path_is_constructed_from_data() {
fn experiment_id_and_branch_get_truncated_if_too_long() {
let t = tempfile::tempdir().unwrap();
let name = t.path().display().to_string();
- let glean = Glean::with_options(&name, "org.mozilla.glean.tests", true);
+ let glean = Glean::with_options(&name, "org.mozilla.glean.tests", true, true);
// Generate long strings for the used ids.
let very_long_id = "test-experiment-id".repeat(10);
@@ -82,7 +80,7 @@ fn experiment_id_and_branch_get_truncated_if_too_long() {
fn limits_on_experiments_extras_are_applied_correctly() {
let t = tempfile::tempdir().unwrap();
let name = t.path().display().to_string();
- let glean = Glean::with_options(&name, "org.mozilla.glean.tests", true);
+ let glean = Glean::with_options(&name, "org.mozilla.glean.tests", true, true);
let experiment_id = "test-experiment_id".to_string();
let branch_id = "test-branch-id".to_string();
@@ -138,7 +136,7 @@ fn limits_on_experiments_extras_are_applied_correctly() {
fn experiments_status_is_correctly_toggled() {
let t = tempfile::tempdir().unwrap();
let name = t.path().display().to_string();
- let glean = Glean::with_options(&name, "org.mozilla.glean.tests", true);
+ let glean = Glean::with_options(&name, "org.mozilla.glean.tests", true, true);
// Define the experiment's data.
let experiment_id: String = "test-toggle-experiment".into();
@@ -199,6 +197,7 @@ fn experimentation_id_is_set_correctly() {
rate_limit: None,
enable_event_timestamps: true,
experimentation_id: Some(experimentation_id.to_string()),
+ enable_internal_pings: true,
})
.unwrap();
@@ -219,7 +218,7 @@ fn client_id_and_first_run_date_must_be_regenerated() {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
{
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
glean.data_store.as_ref().unwrap().clear_all();
@@ -236,7 +235,7 @@ fn client_id_and_first_run_date_must_be_regenerated() {
}
{
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
assert!(glean
.core_metrics
.client_id
@@ -339,7 +338,7 @@ fn client_id_is_managed_correctly_when_toggling_uploading() {
fn client_id_is_set_to_known_value_when_uploading_disabled_at_start() {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, false);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, false, true);
assert_eq!(
*KNOWN_CLIENT_ID,
@@ -355,7 +354,7 @@ fn client_id_is_set_to_known_value_when_uploading_disabled_at_start() {
fn client_id_is_set_to_random_value_when_uploading_enabled_at_start() {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
let current_client_id = glean
.core_metrics
@@ -369,7 +368,7 @@ fn client_id_is_set_to_random_value_when_uploading_enabled_at_start() {
fn enabling_when_already_enabled_is_a_noop() {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
- let mut glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let mut glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
assert!(!glean.set_upload_enabled(true));
}
@@ -378,7 +377,7 @@ fn enabling_when_already_enabled_is_a_noop() {
fn disabling_when_already_disabled_is_a_noop() {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
- let mut glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, false);
+ let mut glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, false, true);
assert!(!glean.set_upload_enabled(false));
}
@@ -601,14 +600,14 @@ fn test_first_run() {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
{
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
// Check that this is indeed the first run.
assert!(glean.is_first_run());
}
{
// Other runs must be not marked as "first run".
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
assert!(!glean.is_first_run());
}
}
@@ -618,7 +617,7 @@ fn test_dirty_bit() {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
{
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
// The dirty flag must not be set the first time Glean runs.
assert!(!glean.is_dirty_flag_set());
@@ -630,7 +629,7 @@ fn test_dirty_bit() {
{
// Check that next time Glean runs, it correctly picks up the "dirty flag".
// It is expected to be 'true'.
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
assert!(glean.is_dirty_flag_set());
// Set the dirty flag to false.
@@ -641,7 +640,7 @@ fn test_dirty_bit() {
{
// Check that next time Glean runs, it correctly picks up the "dirty flag".
// It is expected to be 'false'.
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
assert!(!glean.is_dirty_flag_set());
}
}
@@ -1065,7 +1064,7 @@ fn test_empty_application_id() {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
- let glean = Glean::with_options(&tmpname, "", true);
+ let glean = Glean::with_options(&tmpname, "", true, true);
// Check that this is indeed the first run.
assert!(glean.is_first_run());
}
@@ -1080,7 +1079,7 @@ fn records_database_file_size() {
let tmpname = dir.path().display().to_string();
// Initialize Glean once to ensure we create the database and did not error.
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
let database_size = &glean.database_metrics.size;
let data = database_size.get_value(&glean, "metrics");
@@ -1089,7 +1088,7 @@ fn records_database_file_size() {
drop(glean);
// Initialize Glean again to record file size.
- let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true);
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true);
let database_size = &glean.database_metrics.size;
let data = database_size.get_value(&glean, "metrics");
@@ -1161,3 +1160,46 @@ fn test_activity_api() {
// Check that we set everything we needed for the 'inactive' status.
assert!(!glean.is_dirty_flag_set());
}
+
+#[test]
+fn disabled_pings_are_not_submitted() {
+ let _ = env_logger::builder().is_test(true).try_init();
+
+ let dir = tempfile::tempdir().unwrap();
+ let (mut glean, _t) = new_glean(Some(dir));
+
+ let ping = PingType::new_internal("custom-disabled", true, false, true, true, vec![], false);
+ glean.register_ping_type(&ping);
+
+ // We need to store a metric as an empty ping is not stored.
+ let counter = CounterMetric::new(CommonMetricData {
+ name: "counter".into(),
+ category: "local".into(),
+ send_in_pings: vec!["custom-disabled".into()],
+ ..Default::default()
+ });
+ counter.add_sync(&glean, 1);
+
+ assert!(!ping.submit_sync(&glean, None));
+}
+
+#[test]
+fn internal_pings_can_be_disabled() {
+ let _ = env_logger::builder().is_test(true).try_init();
+
+ let dir = tempfile::tempdir().unwrap();
+ let tmpname = dir.path().display().to_string();
+ let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, false);
+
+ // We need to store a metric as an empty ping is not stored.
+ let counter = CounterMetric::new(CommonMetricData {
+ name: "counter".into(),
+ category: "local".into(),
+ send_in_pings: vec!["baseline".into()],
+ ..Default::default()
+ });
+ counter.add_sync(&glean, 1);
+
+ let submitted = glean.internal_pings.baseline.submit_sync(&glean, None);
+ assert!(!submitted);
+}
diff --git a/third_party/rust/glean-core/src/metrics/event.rs b/third_party/rust/glean-core/src/metrics/event.rs
index c7aefd9cd6..74f90f4867 100644
--- a/third_party/rust/glean-core/src/metrics/event.rs
+++ b/third_party/rust/glean-core/src/metrics/event.rs
@@ -175,9 +175,21 @@ impl EventMetric {
.into()
.unwrap_or_else(|| &self.meta().inner.send_in_pings[0]);
- glean
+ let events = glean
.event_storage()
- .test_get_value(&self.meta, queried_ping_name)
+ .test_get_value(&self.meta, queried_ping_name);
+
+ events.map(|mut evts| {
+ for ev in &mut evts {
+ let Some(extra) = &mut ev.extra else { continue };
+ extra.remove("glean_timestamp");
+ if extra.is_empty() {
+ ev.extra = None;
+ }
+ }
+
+ evts
+ })
}
/// **Test-only API (exported for FFI purposes).**
diff --git a/third_party/rust/glean-core/src/metrics/memory_unit.rs b/third_party/rust/glean-core/src/metrics/memory_unit.rs
index ce51b975fa..19006a594e 100644
--- a/third_party/rust/glean-core/src/metrics/memory_unit.rs
+++ b/third_party/rust/glean-core/src/metrics/memory_unit.rs
@@ -2,8 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-use std::convert::TryFrom;
-
use serde::{Deserialize, Serialize};
use crate::error::{Error, ErrorKind};
diff --git a/third_party/rust/glean-core/src/metrics/metrics_enabled_config.rs b/third_party/rust/glean-core/src/metrics/metrics_enabled_config.rs
index 26d0deff31..b36cbc150a 100644
--- a/third_party/rust/glean-core/src/metrics/metrics_enabled_config.rs
+++ b/third_party/rust/glean-core/src/metrics/metrics_enabled_config.rs
@@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-use std::{collections::HashMap, convert::TryFrom};
+use std::collections::HashMap;
use serde::{Deserialize, Serialize};
diff --git a/third_party/rust/glean-core/src/metrics/ping.rs b/third_party/rust/glean-core/src/metrics/ping.rs
index e60284b1e2..5defab7a71 100644
--- a/third_party/rust/glean-core/src/metrics/ping.rs
+++ b/third_party/rust/glean-core/src/metrics/ping.rs
@@ -31,6 +31,11 @@ struct InnerPing {
pub include_info_sections: bool,
/// The "reason" codes that this ping can send
pub reason_codes: Vec<String>,
+
+ /// Whether this ping is enabled.
+ /// Note: Data for disabled pings is still recorded.
+ /// It will not be cleared out on submit.
+ enabled: bool,
}
impl fmt::Debug for PingType {
@@ -68,6 +73,26 @@ impl PingType {
include_info_sections: bool,
reason_codes: Vec<String>,
) -> Self {
+ Self::new_internal(
+ name,
+ include_client_id,
+ send_if_empty,
+ precise_timestamps,
+ include_info_sections,
+ reason_codes,
+ true,
+ )
+ }
+
+ pub(crate) fn new_internal<A: Into<String>>(
+ name: A,
+ include_client_id: bool,
+ send_if_empty: bool,
+ precise_timestamps: bool,
+ include_info_sections: bool,
+ reason_codes: Vec<String>,
+ enabled: bool,
+ ) -> Self {
let this = Self(Arc::new(InnerPing {
name: name.into(),
include_client_id,
@@ -75,6 +100,7 @@ impl PingType {
precise_timestamps,
include_info_sections,
reason_codes,
+ enabled,
}));
// Register this ping.
@@ -140,6 +166,11 @@ impl PingType {
/// Whether the ping was succesfully assembled and queued.
#[doc(hidden)]
pub fn submit_sync(&self, glean: &Glean, reason: Option<&str>) -> bool {
+ if !self.0.enabled {
+ log::info!("Ping disabled: not submitting '{}' ping.", self.0.name);
+ return false;
+ }
+
if !glean.is_upload_enabled() {
log::info!("Glean disabled: not submitting any pings.");
return false;
diff --git a/third_party/rust/glean-core/src/metrics/string.rs b/third_party/rust/glean-core/src/metrics/string.rs
index 4aa30a8d7e..a56ffab648 100644
--- a/third_party/rust/glean-core/src/metrics/string.rs
+++ b/third_party/rust/glean-core/src/metrics/string.rs
@@ -149,10 +149,8 @@ impl StringMetric {
#[cfg(test)]
mod test {
use super::*;
- use crate::test_get_num_recorded_errors;
use crate::tests::new_glean;
use crate::util::truncate_string_at_boundary;
- use crate::ErrorType;
use crate::Lifetime;
#[test]
diff --git a/third_party/rust/glean-core/src/metrics/text.rs b/third_party/rust/glean-core/src/metrics/text.rs
index baa8e88d75..35f803c728 100644
--- a/third_party/rust/glean-core/src/metrics/text.rs
+++ b/third_party/rust/glean-core/src/metrics/text.rs
@@ -153,10 +153,8 @@ impl TextMetric {
#[cfg(test)]
mod test {
use super::*;
- use crate::test_get_num_recorded_errors;
use crate::tests::new_glean;
use crate::util::truncate_string_at_boundary;
- use crate::ErrorType;
use crate::Lifetime;
#[test]
diff --git a/third_party/rust/glean-core/src/metrics/time_unit.rs b/third_party/rust/glean-core/src/metrics/time_unit.rs
index 6d61a8a242..6c68d5dff0 100644
--- a/third_party/rust/glean-core/src/metrics/time_unit.rs
+++ b/third_party/rust/glean-core/src/metrics/time_unit.rs
@@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-use std::convert::TryFrom;
use std::time::Duration;
use serde::{Deserialize, Serialize};
diff --git a/third_party/rust/glean-core/src/metrics/timespan.rs b/third_party/rust/glean-core/src/metrics/timespan.rs
index ee63fb52f8..d72492a590 100644
--- a/third_party/rust/glean-core/src/metrics/timespan.rs
+++ b/third_party/rust/glean-core/src/metrics/timespan.rs
@@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-use std::convert::TryInto;
use std::sync::{Arc, RwLock};
use std::time::Duration;
diff --git a/third_party/rust/glean-core/src/metrics/timing_distribution.rs b/third_party/rust/glean-core/src/metrics/timing_distribution.rs
index 3293be9518..776935afea 100644
--- a/third_party/rust/glean-core/src/metrics/timing_distribution.rs
+++ b/third_party/rust/glean-core/src/metrics/timing_distribution.rs
@@ -96,7 +96,7 @@ impl TimingDistributionMetric {
Self {
meta: Arc::new(meta.into()),
time_unit,
- next_id: Arc::new(AtomicUsize::new(0)),
+ next_id: Arc::new(AtomicUsize::new(1)),
start_times: Arc::new(Mutex::new(Default::default())),
}
}
diff --git a/third_party/rust/glean-core/src/metrics/url.rs b/third_party/rust/glean-core/src/metrics/url.rs
index 48b3f9e7ae..0fd5712eeb 100644
--- a/third_party/rust/glean-core/src/metrics/url.rs
+++ b/third_party/rust/glean-core/src/metrics/url.rs
@@ -168,9 +168,7 @@ impl UrlMetric {
#[cfg(test)]
mod test {
use super::*;
- use crate::test_get_num_recorded_errors;
use crate::tests::new_glean;
- use crate::ErrorType;
use crate::Lifetime;
#[test]
diff --git a/third_party/rust/glean-core/src/storage/mod.rs b/third_party/rust/glean-core/src/storage/mod.rs
index 67cb9a1552..a4225e21ed 100644
--- a/third_party/rust/glean-core/src/storage/mod.rs
+++ b/third_party/rust/glean-core/src/storage/mod.rs
@@ -235,7 +235,7 @@ mod test {
fn test_experiments_json_serialization() {
let t = tempfile::tempdir().unwrap();
let name = t.path().display().to_string();
- let glean = Glean::with_options(&name, "org.mozilla.glean", true);
+ let glean = Glean::with_options(&name, "org.mozilla.glean", true, true);
let extra: HashMap<String, String> = [("test-key".into(), "test-value".into())]
.iter()
@@ -264,7 +264,7 @@ mod test {
fn test_experiments_json_serialization_empty() {
let t = tempfile::tempdir().unwrap();
let name = t.path().display().to_string();
- let glean = Glean::with_options(&name, "org.mozilla.glean", true);
+ let glean = Glean::with_options(&name, "org.mozilla.glean", true, true);
let metric = ExperimentMetric::new(&glean, "some-experiment".to_string());
diff --git a/third_party/rust/glean-core/src/traits/event.rs b/third_party/rust/glean-core/src/traits/event.rs
index aa84699b30..ba8c0e5609 100644
--- a/third_party/rust/glean-core/src/traits/event.rs
+++ b/third_party/rust/glean-core/src/traits/event.rs
@@ -3,7 +3,6 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
use std::collections::HashMap;
-use std::convert::TryFrom;
use std::hash::Hash;
use crate::event_database::RecordedEvent;
diff --git a/third_party/rust/glean-core/src/upload/directory.rs b/third_party/rust/glean-core/src/upload/directory.rs
index 706550fe6c..91a4d061d1 100644
--- a/third_party/rust/glean-core/src/upload/directory.rs
+++ b/third_party/rust/glean-core/src/upload/directory.rs
@@ -317,8 +317,6 @@ impl PingDirectoryManager {
#[cfg(test)]
mod test {
- use std::fs::File;
-
use super::*;
use crate::metrics::PingType;
use crate::tests::new_glean;
diff --git a/third_party/rust/glean-core/src/upload/mod.rs b/third_party/rust/glean-core/src/upload/mod.rs
index e51a9d9508..f217137f00 100644
--- a/third_party/rust/glean-core/src/upload/mod.rs
+++ b/third_party/rust/glean-core/src/upload/mod.rs
@@ -14,7 +14,6 @@
use std::collections::HashMap;
use std::collections::VecDeque;
-use std::convert::TryInto;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use std::sync::{Arc, RwLock, RwLockWriteGuard};
@@ -856,9 +855,6 @@ pub fn chunked_log_info(_path: &str, payload: &str) {
#[cfg(test)]
mod test {
- use std::thread;
- use std::time::Duration;
-
use uuid::Uuid;
use super::*;
diff --git a/third_party/rust/glean-core/src/upload/request.rs b/third_party/rust/glean-core/src/upload/request.rs
index b4ac6eba97..6f3b0c0e5c 100644
--- a/third_party/rust/glean-core/src/upload/request.rs
+++ b/third_party/rust/glean-core/src/upload/request.rs
@@ -8,7 +8,7 @@ use std::collections::HashMap;
use chrono::prelude::{DateTime, Utc};
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
-use serde_json::{self, Value as JsonValue};
+use serde_json::Value as JsonValue;
use std::io::prelude::*;
use crate::error::{ErrorKind, Result};