summaryrefslogtreecommitdiffstats
path: root/third_party/rust/glean
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/glean')
-rw-r--r--third_party/rust/glean/.cargo-checksum.json2
-rw-r--r--third_party/rust/glean/Cargo.toml34
-rw-r--r--third_party/rust/glean/src/common_test.rs1
-rw-r--r--third_party/rust/glean/src/configuration.rs2
-rw-r--r--third_party/rust/glean/src/lib.rs2
-rw-r--r--third_party/rust/glean/src/net/http_uploader.rs11
-rw-r--r--third_party/rust/glean/src/net/mod.rs25
-rw-r--r--third_party/rust/glean/src/private/mod.rs2
-rw-r--r--third_party/rust/glean/src/private/object.rs192
-rw-r--r--third_party/rust/glean/src/private/ping.rs2
-rw-r--r--third_party/rust/glean/src/test.rs215
-rw-r--r--third_party/rust/glean/tests/init_fails.rs2
-rw-r--r--third_party/rust/glean/tests/never_init.rs2
-rw-r--r--third_party/rust/glean/tests/no_time_to_init.rs2
-rw-r--r--third_party/rust/glean/tests/schema.rs13
-rw-r--r--third_party/rust/glean/tests/simple.rs2
-rw-r--r--third_party/rust/glean/tests/upload_timing.rs10
17 files changed, 333 insertions, 186 deletions
diff --git a/third_party/rust/glean/.cargo-checksum.json b/third_party/rust/glean/.cargo-checksum.json
index 74c885aad7..f624e73c99 100644
--- a/third_party/rust/glean/.cargo-checksum.json
+++ b/third_party/rust/glean/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"13aebaf3dc74c32fa745410731828cf3b8d27025f5d3371b31178531bf49b009","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"5627cc81e6187ab6c2b4dff061af16d559edcab64ba786bac39daa69c703c595","src/common_test.rs":"de47b53dcca37985c0a2b8c02daecbf32309aa54f5a4dd9290719c2c1fd0fa55","src/configuration.rs":"186b9d92e48f2f34f1ea51023ad83c9d7abec97bcb0b862641bcb79a93c97d9e","src/core_metrics.rs":"fef8fb4e5fa57c179836c6eb2cf59278fe3b8b036dbe57b0ff02971b4acd822f","src/lib.rs":"c0229403026edc22ddf53ea60ea92cdd2eb820c06f63a6057b3ef10050800279","src/net/http_uploader.rs":"43812a70d19a38e8d7a093c8076c2b6345372c3c861b0f3511428762700a65e0","src/net/mod.rs":"612a9f13ade0b202c8762bccc7b5dc288101cb3820e47be2755331911a221c55","src/private/event.rs":"d7c70c02648584c19c73af89e5180d3c6153c911f2c6830f7d1599b18d6150eb","src/private/mod.rs":"eb8fe4e588bb32a54617324db39319920c627e6fc23c23cf4da5c17c63e0afed","src/private/ping.rs":"da7545b8fc3b8cbaa8f598dc18fa4ba7c499573c360e8de6e1714d38dd4a665d","src/system.rs":"6eae5b41c15eba9cad6dbd116abe3519ee3e1fe034e79bdd692b029829a8c384","src/test.rs":"3ff6cf151f416e7a8d0f1b54ff28360ad7ebd3dcf47df02c08a8039702d636d9","tests/common/mod.rs":"08fb9483d9b6ed9fe873b4395245166ae8a15263be750c7a8e298c41d9604745","tests/init_fails.rs":"96bbb67ec64976f505fc05eb2c2e101f06c11bd2eaf6a0c6383b1a3e05a1cf4b","tests/never_init.rs":"2cf13a67b34cda8447f489cf3755eba0595978d242d29025670f9bb7c1025937","tests/no_time_to_init.rs":"5fd92258e3fb0302c7f8ab1dee374ece7343cc727206d9da134442bca746b88d","tests/overflowing_preinit.rs":"7ad4b2274dd9240b53430859a4eb1d2597cf508a5a678333f3d3abbadd2ed4a7","tests/persist_ping_lifetime.rs":"81415dc1d74743f02269f0d0dfa524003147056853f080276972e64a0b761d3c","tests/persist_ping_lifetime_nopanic.rs":"18379d3ffbf4a2c8c684c04ff7a0660b86dfbbb447db2d24dfed6073cb7ddf8f","tests/schema.rs":"e611cc168b648b5f515c54873c71b3e5e86431afa2aaff94581eeeb4f1d4935d","tests/simple.rs":"3a762995c06c0adc5adb94ad9c37e41dbbcf08a96b87bc20a449240fa0d93b0c","tests/test-shutdown-blocking.sh":"9b16a01c190c7062474dd92182298a3d9a27928c8fa990340fdd798e6cdb7ab2","tests/test-thread-crashing.sh":"ff1bc8e5d7e4ba3a10d0d38bef222db8bfba469e7d30e45b1053d177a4084f09","tests/upload_timing.rs":"4100ddba97cad28e1abfeb1492dfff61d151a67360392393d6f90d891b3e86be"},"package":"ae5847ad58b7f925c984de7f4dffcad67d7d0befa59a5a888cf93741b5ef1e6a"} \ No newline at end of file
+{"files":{"Cargo.toml":"29b8551de6fff2f0fa3a821eb933f71a2a326b3ce3d37c25bcef3001f9146dfb","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"5627cc81e6187ab6c2b4dff061af16d559edcab64ba786bac39daa69c703c595","src/common_test.rs":"454df3d99eef045270e813946f921f56c39b16c18a5fadedc32829c3d44129cf","src/configuration.rs":"82b3a7933d913e1e2a4f328a76621db2d2e618d209d9785086d64c5c78c2a2d6","src/core_metrics.rs":"fef8fb4e5fa57c179836c6eb2cf59278fe3b8b036dbe57b0ff02971b4acd822f","src/lib.rs":"aa9c81fc6dc19ca1cb4bede25d554377a5d717fb3b246967edb1be12a395ce61","src/net/http_uploader.rs":"01ad5bd91384411a12c74434cd1c5cd585078cb34faba4615c70bdb669a9bccb","src/net/mod.rs":"f47b96bb878f1a6c771cedbaeaeefb270bc87fb1d1bbbed1b282dddca16216ed","src/private/event.rs":"d7c70c02648584c19c73af89e5180d3c6153c911f2c6830f7d1599b18d6150eb","src/private/mod.rs":"3565eb569d2b96f938f130abe0fc3ee3f55e7e03fd6501e309d3ef6af72ef6ee","src/private/object.rs":"3f70363a196aea46cc163af025a53e48c117c6208babc4bce772bb4c337cced8","src/private/ping.rs":"a6262a3453c77cbf30766c19b535a1bf66a37b2a316e8f87baee03025255c33e","src/system.rs":"6eae5b41c15eba9cad6dbd116abe3519ee3e1fe034e79bdd692b029829a8c384","src/test.rs":"6388b9e8bf96e0fb56ad71b7a5b5630d209ae62f1a65c62e878cbc1757ddd585","tests/common/mod.rs":"08fb9483d9b6ed9fe873b4395245166ae8a15263be750c7a8e298c41d9604745","tests/init_fails.rs":"906bbf0faa613976623e0cf782bd86545b49d76afaab182af7634690b747ebf7","tests/never_init.rs":"19bad996e22f7d6958cc1a650528530aa7d1aeb4a8ab42229a90bbc0315c8ed1","tests/no_time_to_init.rs":"06c81148c27d383cb708c0c80a2e806024c9955337d7adfba8c53aaeade9be67","tests/overflowing_preinit.rs":"7ad4b2274dd9240b53430859a4eb1d2597cf508a5a678333f3d3abbadd2ed4a7","tests/persist_ping_lifetime.rs":"81415dc1d74743f02269f0d0dfa524003147056853f080276972e64a0b761d3c","tests/persist_ping_lifetime_nopanic.rs":"18379d3ffbf4a2c8c684c04ff7a0660b86dfbbb447db2d24dfed6073cb7ddf8f","tests/schema.rs":"9d24028cab4dc60fe3c4d7a0bafbff0815cbc0249fa3e23625d42c3b4fa71734","tests/simple.rs":"1b8b227249ae9d3cc281db07ed779bc75252c7849b1c48b4ac3d765228d65b20","tests/test-shutdown-blocking.sh":"9b16a01c190c7062474dd92182298a3d9a27928c8fa990340fdd798e6cdb7ab2","tests/test-thread-crashing.sh":"ff1bc8e5d7e4ba3a10d0d38bef222db8bfba469e7d30e45b1053d177a4084f09","tests/upload_timing.rs":"3024b7999a0c23f2c3d7e59725b5455522e4e9fdf63e3265b93fea4cec18725f"},"package":"f58388f10d013e2d12bb58e6e76983ede120789956fe827913a3d2560c66d44d"} \ No newline at end of file
diff --git a/third_party/rust/glean/Cargo.toml b/third_party/rust/glean/Cargo.toml
index 1a702be403..bc25a08940 100644
--- a/third_party/rust/glean/Cargo.toml
+++ b/third_party/rust/glean/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2021"
rust-version = "1.66"
name = "glean"
-version = "57.0.0"
+version = "58.1.0"
authors = [
"Jan-Erik Rediger <jrediger@mozilla.com>",
"The Glean Team <glean-team@mozilla.com>",
@@ -34,15 +34,8 @@ keywords = [
license = "MPL-2.0"
repository = "https://github.com/mozilla/glean"
-[dependencies.chrono]
-version = "0.4.10"
-features = ["serde"]
-
-[dependencies.crossbeam-channel]
-version = "0.5"
-
[dependencies.glean-core]
-version = "57.0.0"
+version = "58.1.0"
[dependencies.inherent]
version = "1"
@@ -53,26 +46,12 @@ version = "0.4.8"
[dependencies.once_cell]
version = "1.18.0"
-[dependencies.serde]
-version = "1.0.104"
-features = ["derive"]
-
-[dependencies.serde_json]
-version = "1.0.44"
-
-[dependencies.thiserror]
-version = "1.0.4"
-
-[dependencies.time]
-version = "0.1.40"
-
-[dependencies.uuid]
-version = "1.0"
-features = ["v4"]
-
[dependencies.whatsys]
version = "0.3.0"
+[dev-dependencies.crossbeam-channel]
+version = "0.5"
+
[dev-dependencies.env_logger]
version = "0.10.0"
features = ["humantime"]
@@ -87,6 +66,9 @@ version = "0.5.0"
[dev-dependencies.libc]
version = "0.2"
+[dev-dependencies.serde_json]
+version = "1.0.44"
+
[dev-dependencies.tempfile]
version = "3.1.0"
diff --git a/third_party/rust/glean/src/common_test.rs b/third_party/rust/glean/src/common_test.rs
index fdb7cfadbf..e3c80da5f2 100644
--- a/third_party/rust/glean/src/common_test.rs
+++ b/third_party/rust/glean/src/common_test.rs
@@ -42,6 +42,7 @@ pub(crate) fn new_glean(
Some(c) => c,
None => ConfigurationBuilder::new(true, tmpname, GLOBAL_APPLICATION_ID)
.with_server_endpoint("invalid-test-host")
+ .with_event_timestamps(false)
.build(),
};
diff --git a/third_party/rust/glean/src/configuration.rs b/third_party/rust/glean/src/configuration.rs
index 42360e96e0..ca0a39c3f1 100644
--- a/third_party/rust/glean/src/configuration.rs
+++ b/third_party/rust/glean/src/configuration.rs
@@ -113,7 +113,7 @@ impl Builder {
trim_data_to_registered_pings: false,
log_level: None,
rate_limit: None,
- enable_event_timestamps: false,
+ enable_event_timestamps: true,
experimentation_id: None,
}
}
diff --git a/third_party/rust/glean/src/lib.rs b/third_party/rust/glean/src/lib.rs
index 538b8c590d..5c5b945a95 100644
--- a/third_party/rust/glean/src/lib.rs
+++ b/third_party/rust/glean/src/lib.rs
@@ -23,7 +23,7 @@
//! let cfg = ConfigurationBuilder::new(true, "/tmp/data", "org.mozilla.glean_core.example").build();
//! glean::initialize(cfg, ClientInfoMetrics::unknown());
//!
-//! let prototype_ping = PingType::new("prototype", true, true, true, vec!());
+//! let prototype_ping = PingType::new("prototype", true, true, true, true, vec!());
//!
//! prototype_ping.submit(None);
//! ```
diff --git a/third_party/rust/glean/src/net/http_uploader.rs b/third_party/rust/glean/src/net/http_uploader.rs
index 4646fe61b4..4ca1687acf 100644
--- a/third_party/rust/glean/src/net/http_uploader.rs
+++ b/third_party/rust/glean/src/net/http_uploader.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 crate::net::{PingUploader, UploadResult};
+use crate::net::{PingUploadRequest, PingUploader, UploadResult};
/// A simple mechanism to upload pings over HTTPS.
#[derive(Debug)]
@@ -13,12 +13,9 @@ impl PingUploader for HttpUploader {
///
/// # Arguments
///
- /// * `url` - the URL path to upload the data to.
- /// * `body` - the serialized text data to send.
- /// * `headers` - a vector of tuples containing the headers to send with
- /// the request, i.e. (Name, Value).
- fn upload(&self, url: String, _body: Vec<u8>, _headers: Vec<(String, String)>) -> UploadResult {
- log::debug!("TODO bug 1675468: submitting to {:?}", url);
+ /// * `upload_request` - the requested upload.
+ fn upload(&self, upload_request: PingUploadRequest) -> UploadResult {
+ log::debug!("TODO bug 1675468: submitting to {:?}", upload_request.url);
UploadResult::http_status(200)
}
}
diff --git a/third_party/rust/glean/src/net/mod.rs b/third_party/rust/glean/src/net/mod.rs
index 5571d30e67..5546078e63 100644
--- a/third_party/rust/glean/src/net/mod.rs
+++ b/third_party/rust/glean/src/net/mod.rs
@@ -19,6 +19,20 @@ use thread_state::{AtomicState, State};
mod http_uploader;
+/// Everything you need to request a ping to be uploaded.
+pub struct PingUploadRequest {
+ /// The URL the Glean SDK expects you to use to upload the ping.
+ pub url: String,
+ /// The body, already content-encoded, for upload.
+ pub body: Vec<u8>,
+ /// The HTTP headers, including any Content-Encoding.
+ pub headers: Vec<(String, String)>,
+ /// Whether the body has {client|ping}_info sections in it.
+ pub body_has_info_sections: bool,
+ /// The name (aka doctype) of the ping.
+ pub ping_name: String,
+}
+
/// A description of a component used to upload pings.
pub trait PingUploader: std::fmt::Debug + Send + Sync {
/// Uploads a ping to a server.
@@ -29,7 +43,7 @@ pub trait PingUploader: std::fmt::Debug + Send + Sync {
/// * `body` - the serialized text data to send.
/// * `headers` - a vector of tuples containing the headers to send with
/// the request, i.e. (Name, Value).
- fn upload(&self, url: String, body: Vec<u8>, headers: Vec<(String, String)>) -> UploadResult;
+ fn upload(&self, upload_request: PingUploadRequest) -> UploadResult;
}
/// The logic for uploading pings: this leaves the actual upload mechanism as
@@ -105,7 +119,14 @@ impl UploadManager {
let upload_url = format!("{}{}", inner.server_endpoint, request.path);
let headers: Vec<(String, String)> =
request.headers.into_iter().collect();
- let result = inner.uploader.upload(upload_url, request.body, headers);
+ let upload_request = PingUploadRequest {
+ url: upload_url,
+ body: request.body,
+ headers,
+ body_has_info_sections: request.body_has_info_sections,
+ ping_name: request.ping_name,
+ };
+ let result = inner.uploader.upload(upload_request);
// Process the upload response.
match glean_core::glean_process_ping_upload_response(doc_id, result) {
UploadTaskAction::Next => (),
diff --git a/third_party/rust/glean/src/private/mod.rs b/third_party/rust/glean/src/private/mod.rs
index 8a5c304193..575707cf59 100644
--- a/third_party/rust/glean/src/private/mod.rs
+++ b/third_party/rust/glean/src/private/mod.rs
@@ -5,6 +5,7 @@
//! The different metric types supported by the Glean SDK to handle data.
mod event;
+mod object;
mod ping;
pub use event::EventMetric;
@@ -26,6 +27,7 @@ pub use glean_core::UrlMetric;
pub use glean_core::UuidMetric;
pub use glean_core::{AllowLabeled, LabeledMetric};
pub use glean_core::{Datetime, DatetimeMetric};
+pub use object::ObjectMetric;
pub use ping::PingType;
// Re-export types that are used by the glean_parser-generated code.
diff --git a/third_party/rust/glean/src/private/object.rs b/third_party/rust/glean/src/private/object.rs
new file mode 100644
index 0000000000..f7403ec889
--- /dev/null
+++ b/third_party/rust/glean/src/private/object.rs
@@ -0,0 +1,192 @@
+// This Source Code Form is subject to the terms of the Mozilla Public
+// 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::marker::PhantomData;
+
+use glean_core::metrics::JsonValue;
+use glean_core::traits;
+
+use crate::ErrorType;
+
+// We need to wrap the glean-core type: otherwise if we try to implement
+// the trait for the metric in `glean_core::metrics` we hit error[E0117]:
+// only traits defined in the current crate can be implemented for arbitrary
+// types.
+
+/// Developer-facing API for recording object metrics.
+///
+/// Instances of this class type are automatically generated by the parsers
+/// at build time, allowing developers to record values that were previously
+/// registered in the metrics.yaml file.
+#[derive(Clone)]
+pub struct ObjectMetric<K> {
+ pub(crate) inner: glean_core::metrics::ObjectMetric,
+ object_type: PhantomData<K>,
+}
+
+impl<K: traits::ObjectSerialize> ObjectMetric<K> {
+ /// The public constructor used by automatically generated metrics.
+ pub fn new(meta: glean_core::CommonMetricData) -> Self {
+ let inner = glean_core::metrics::ObjectMetric::new(meta);
+ Self {
+ inner,
+ object_type: PhantomData,
+ }
+ }
+
+ /// Sets to the specified structure.
+ ///
+ /// # Arguments
+ ///
+ /// * `object` - the object to set.
+ pub fn set(&self, object: K) {
+ let obj = object
+ .into_serialized_object()
+ .expect("failed to serialize object. This should be impossible.");
+ self.inner.set(obj);
+ }
+
+ /// Sets to the specified structure.
+ ///
+ /// Parses the passed JSON string.
+ /// If it can't be parsed into a valid object it records an invalid value error.
+ ///
+ /// # Arguments
+ ///
+ /// * `object` - JSON representation of the object to set.
+ pub fn set_string(&self, object: String) {
+ let data = match K::from_str(&object) {
+ Ok(data) => data,
+ Err(_) => {
+ self.inner.record_schema_error();
+ return;
+ }
+ };
+ self.set(data)
+ }
+
+ /// **Test-only API (exported for FFI purposes).**
+ ///
+ /// Gets the currently stored value as JSON-encoded string.
+ ///
+ /// This doesn't clear the stored value.
+ pub fn test_get_value<'a, S: Into<Option<&'a str>>>(&self, ping_name: S) -> Option<JsonValue> {
+ let ping_name = ping_name.into().map(|s| s.to_string());
+ self.inner.test_get_value(ping_name)
+ }
+
+ /// **Exported for test purposes.**
+ ///
+ /// Gets the number of recorded errors for the given metric and error type.
+ ///
+ /// # Arguments
+ ///
+ /// * `error` - The type of error
+ ///
+ /// # Returns
+ ///
+ /// The number of errors reported.
+ pub fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32 {
+ self.inner.test_get_num_recorded_errors(error)
+ }
+}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+ use crate::common_test::{lock_test, new_glean};
+ use crate::CommonMetricData;
+
+ use serde_json::json;
+
+ #[test]
+ fn simple_array() {
+ let _lock = lock_test();
+ let _t = new_glean(None, true);
+
+ type SimpleArray = Vec<i64>;
+
+ let metric: ObjectMetric<SimpleArray> = ObjectMetric::new(CommonMetricData {
+ name: "object".into(),
+ category: "test".into(),
+ send_in_pings: vec!["test1".into()],
+ ..Default::default()
+ });
+
+ let arr = SimpleArray::from([1, 2, 3]);
+ metric.set(arr);
+
+ let data = metric.test_get_value(None).expect("no object recorded");
+ let expected = json!([1, 2, 3]);
+ assert_eq!(expected, data);
+ }
+
+ #[test]
+ fn complex_nested_object() {
+ let _lock = lock_test();
+ let _t = new_glean(None, true);
+
+ type BalloonsObject = Vec<BalloonsObjectItem>;
+
+ #[derive(
+ Debug, Hash, Eq, PartialEq, traits::__serde::Deserialize, traits::__serde::Serialize,
+ )]
+ #[serde(crate = "traits::__serde")]
+ #[serde(deny_unknown_fields)]
+ struct BalloonsObjectItem {
+ #[serde(skip_serializing_if = "Option::is_none")]
+ colour: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ diameter: Option<i64>,
+ }
+
+ let metric: ObjectMetric<BalloonsObject> = ObjectMetric::new(CommonMetricData {
+ name: "object".into(),
+ category: "test".into(),
+ send_in_pings: vec!["test1".into()],
+ ..Default::default()
+ });
+
+ let balloons = BalloonsObject::from([
+ BalloonsObjectItem {
+ colour: Some("red".to_string()),
+ diameter: Some(5),
+ },
+ BalloonsObjectItem {
+ colour: Some("green".to_string()),
+ diameter: None,
+ },
+ ]);
+ metric.set(balloons);
+
+ let data = metric.test_get_value(None).expect("no object recorded");
+ let expected = json!([
+ { "colour": "red", "diameter": 5 },
+ { "colour": "green" },
+ ]);
+ assert_eq!(expected, data);
+ }
+
+ #[test]
+ fn set_string_api() {
+ let _lock = lock_test();
+ let _t = new_glean(None, true);
+
+ type SimpleArray = Vec<i64>;
+
+ let metric: ObjectMetric<SimpleArray> = ObjectMetric::new(CommonMetricData {
+ name: "object".into(),
+ category: "test".into(),
+ send_in_pings: vec!["test1".into()],
+ ..Default::default()
+ });
+
+ let arr_str = String::from("[1, 2, 3]");
+ metric.set_string(arr_str);
+
+ let data = metric.test_get_value(None).expect("no object recorded");
+ let expected = json!([1, 2, 3]);
+ assert_eq!(expected, data);
+ }
+}
diff --git a/third_party/rust/glean/src/private/ping.rs b/third_party/rust/glean/src/private/ping.rs
index c9c68a10a2..6c126992bc 100644
--- a/third_party/rust/glean/src/private/ping.rs
+++ b/third_party/rust/glean/src/private/ping.rs
@@ -33,6 +33,7 @@ impl PingType {
include_client_id: bool,
send_if_empty: bool,
precise_timestamps: bool,
+ include_info_sections: bool,
reason_codes: Vec<String>,
) -> Self {
let inner = glean_core::metrics::PingType::new(
@@ -40,6 +41,7 @@ impl PingType {
include_client_id,
send_if_empty,
precise_timestamps,
+ include_info_sections,
reason_codes,
);
diff --git a/third_party/rust/glean/src/test.rs b/third_party/rust/glean/src/test.rs
index cb41b49b66..16d6d05447 100644
--- a/third_party/rust/glean/src/test.rs
+++ b/third_party/rust/glean/src/test.rs
@@ -22,22 +22,16 @@ use crate::common_test::{lock_test, new_glean, GLOBAL_APPLICATION_ID};
fn send_a_ping() {
let _lock = lock_test();
- let (s, r) = crossbeam_channel::bounded::<String>(1);
+ let (s, r) = crossbeam_channel::bounded::<net::PingUploadRequest>(1);
- // Define a fake uploader that reports back the submission URL
- // using a crossbeam channel.
+ // Define a fake uploader that reports back the ping upload request.
#[derive(Debug)]
pub struct FakeUploader {
- sender: crossbeam_channel::Sender<String>,
+ sender: crossbeam_channel::Sender<net::PingUploadRequest>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(url).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -55,12 +49,54 @@ fn send_a_ping() {
// Define a new ping and submit it.
const PING_NAME: &str = "test-ping";
- let custom_ping = private::PingType::new(PING_NAME, true, true, true, vec![]);
+ let custom_ping = private::PingType::new(PING_NAME, true, true, true, true, vec![]);
custom_ping.submit(None);
// Wait for the ping to arrive.
- let url = r.recv().unwrap();
- assert!(url.contains(PING_NAME));
+ let upload_request = r.recv().unwrap();
+ assert!(upload_request.body_has_info_sections);
+ assert_eq!(upload_request.ping_name, PING_NAME);
+ assert!(upload_request.url.contains(PING_NAME));
+}
+
+#[test]
+fn send_a_ping_without_info_sections() {
+ let _lock = lock_test();
+
+ let (s, r) = crossbeam_channel::bounded::<net::PingUploadRequest>(1);
+
+ // Define a fake uploader that reports back the ping upload request.
+ #[derive(Debug)]
+ pub struct FakeUploader {
+ sender: crossbeam_channel::Sender<net::PingUploadRequest>,
+ }
+ impl net::PingUploader for FakeUploader {
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request).unwrap();
+ net::UploadResult::http_status(200)
+ }
+ }
+
+ // Create a custom configuration to use a fake uploader.
+ let dir = tempfile::tempdir().unwrap();
+ let tmpname = dir.path().to_path_buf();
+
+ let cfg = ConfigurationBuilder::new(true, tmpname, GLOBAL_APPLICATION_ID)
+ .with_server_endpoint("invalid-test-host")
+ .with_uploader(FakeUploader { sender: s })
+ .build();
+
+ let _t = new_glean(Some(cfg), true);
+
+ // Define a new ping and submit it.
+ const PING_NAME: &str = "noinfo-ping";
+ let custom_ping = private::PingType::new(PING_NAME, true, true, true, false, vec![]);
+ custom_ping.submit(None);
+
+ // Wait for the ping to arrive.
+ let upload_request = r.recv().unwrap();
+ assert!(!upload_request.body_has_info_sections);
+ assert_eq!(upload_request.ping_name, PING_NAME);
}
#[test]
@@ -190,13 +226,8 @@ fn sending_of_foreground_background_pings() {
sender: crossbeam_channel::Sender<String>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(url).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.url).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -263,13 +294,8 @@ fn sending_of_startup_baseline_ping() {
sender: crossbeam_channel::Sender<String>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(url).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.url).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -315,13 +341,8 @@ fn no_dirty_baseline_on_clean_shutdowns() {
sender: crossbeam_channel::Sender<String>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(url).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.url).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -543,12 +564,8 @@ fn ping_collection_must_happen_after_concurrently_scheduled_metrics_recordings()
sender: crossbeam_channel::Sender<(String, JsonValue)>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ let net::PingUploadRequest { body, url, .. } = upload_request;
// Decode the gzipped body.
let mut gzip_decoder = GzDecoder::new(&body[..]);
let mut s = String::with_capacity(body.len());
@@ -577,7 +594,7 @@ fn ping_collection_must_happen_after_concurrently_scheduled_metrics_recordings()
);
let ping_name = "custom_ping_1";
- let ping = private::PingType::new(ping_name, true, false, true, vec![]);
+ let ping = private::PingType::new(ping_name, true, false, true, true, vec![]);
let metric = private::StringMetric::new(CommonMetricData {
name: "string_metric".into(),
category: "telemetry".into(),
@@ -681,13 +698,8 @@ fn sending_deletion_ping_if_disabled_outside_of_run() {
sender: crossbeam_channel::Sender<String>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(url).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.url).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -731,13 +743,8 @@ fn no_sending_of_deletion_ping_if_unchanged_outside_of_run() {
sender: crossbeam_channel::Sender<String>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(url).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.url).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -779,12 +786,8 @@ fn deletion_request_ping_contains_experimentation_id() {
sender: crossbeam_channel::Sender<JsonValue>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- _url: String,
- body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ let body = upload_request.body;
let mut gzip_decoder = GzDecoder::new(&body[..]);
let mut body_str = String::with_capacity(body.len());
let data: JsonValue = gzip_decoder
@@ -847,12 +850,8 @@ fn test_sending_of_startup_baseline_ping_with_application_lifetime_metric() {
sender: crossbeam_channel::Sender<(String, JsonValue)>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ let net::PingUploadRequest { url, body, .. } = upload_request;
// Decode the gzipped body.
let mut gzip_decoder = GzDecoder::new(&body[..]);
let mut s = String::with_capacity(body.len());
@@ -932,13 +931,8 @@ fn setting_debug_view_tag_before_initialization_should_not_crash() {
sender: crossbeam_channel::Sender<Vec<(String, String)>>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- _url: String,
- _body: Vec<u8>,
- headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(headers).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.headers).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -983,13 +977,8 @@ fn setting_source_tags_before_initialization_should_not_crash() {
sender: crossbeam_channel::Sender<Vec<(String, String)>>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- _url: String,
- _body: Vec<u8>,
- headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(headers).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.headers).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -1033,13 +1022,8 @@ fn setting_source_tags_after_initialization_should_not_crash() {
sender: crossbeam_channel::Sender<Vec<(String, String)>>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- _url: String,
- _body: Vec<u8>,
- headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(headers).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.headers).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -1097,13 +1081,8 @@ fn flipping_upload_enabled_respects_order_of_events() {
sender: crossbeam_channel::Sender<String>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(url).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.url).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -1118,7 +1097,7 @@ fn flipping_upload_enabled_respects_order_of_events() {
.build();
// We create a ping and a metric before we initialize Glean
- let sample_ping = PingType::new("sample-ping-1", true, false, true, vec![]);
+ let sample_ping = PingType::new("sample-ping-1", true, false, true, true, vec![]);
let metric = private::StringMetric::new(CommonMetricData {
name: "string_metric".into(),
category: "telemetry".into(),
@@ -1155,19 +1134,14 @@ fn registering_pings_before_init_must_work() {
sender: crossbeam_channel::Sender<String>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(url).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.url).unwrap();
net::UploadResult::http_status(200)
}
}
// Create a custom ping and attempt its registration.
- let sample_ping = PingType::new("pre-register", true, true, true, vec![]);
+ let sample_ping = PingType::new("pre-register", true, true, true, true, vec![]);
// Create a custom configuration to use a fake uploader.
let dir = tempfile::tempdir().unwrap();
@@ -1201,13 +1175,8 @@ fn test_a_ping_before_submission() {
sender: crossbeam_channel::Sender<String>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
- self.sender.send(url).unwrap();
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
+ self.sender.send(upload_request.url).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -1224,7 +1193,7 @@ fn test_a_ping_before_submission() {
let _t = new_glean(Some(cfg), true);
// Create a custom ping and register it.
- let sample_ping = PingType::new("custom1", true, true, true, vec![]);
+ let sample_ping = PingType::new("custom1", true, true, true, true, vec![]);
let metric = CounterMetric::new(CommonMetricData {
name: "counter_metric".into(),
@@ -1308,12 +1277,7 @@ fn signaling_done() {
counter: Arc<Mutex<HashMap<ThreadId, u32>>>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- _url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
+ fn upload(&self, _upload_request: net::PingUploadRequest) -> net::UploadResult {
let mut map = self.counter.lock().unwrap();
*map.entry(thread::current().id()).or_insert(0) += 1;
@@ -1346,7 +1310,7 @@ fn signaling_done() {
// Define a new ping and submit it.
const PING_NAME: &str = "test-ping";
- let custom_ping = private::PingType::new(PING_NAME, true, true, true, vec![]);
+ let custom_ping = private::PingType::new(PING_NAME, true, true, true, true, vec![]);
custom_ping.submit(None);
custom_ping.submit(None);
@@ -1385,17 +1349,12 @@ fn configure_ping_throttling() {
done: Arc<std::sync::atomic::AtomicBool>,
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- url: String,
- _body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
if self.done.load(std::sync::atomic::Ordering::SeqCst) {
// If we've outlived the test, just lie.
return net::UploadResult::http_status(200);
}
- self.sender.send(url).unwrap();
+ self.sender.send(upload_request.url).unwrap();
net::UploadResult::http_status(200)
}
}
@@ -1422,7 +1381,7 @@ fn configure_ping_throttling() {
// Define a new ping.
const PING_NAME: &str = "test-ping";
- let custom_ping = private::PingType::new(PING_NAME, true, true, true, vec![]);
+ let custom_ping = private::PingType::new(PING_NAME, true, true, true, true, vec![]);
// Submit and receive it `pings_per_interval` times.
for _ in 0..pings_per_interval {
diff --git a/third_party/rust/glean/tests/init_fails.rs b/third_party/rust/glean/tests/init_fails.rs
index def5acc4b9..a0c23ca277 100644
--- a/third_party/rust/glean/tests/init_fails.rs
+++ b/third_party/rust/glean/tests/init_fails.rs
@@ -43,7 +43,7 @@ mod pings {
#[allow(non_upper_case_globals)]
pub static validation: Lazy<PingType> =
- Lazy::new(|| glean::private::PingType::new("validation", true, true, true, vec![]));
+ Lazy::new(|| glean::private::PingType::new("validation", true, true, true, true, vec![]));
}
/// Test scenario: Glean initialization fails.
diff --git a/third_party/rust/glean/tests/never_init.rs b/third_party/rust/glean/tests/never_init.rs
index 3df472ee31..0d0d3768ff 100644
--- a/third_party/rust/glean/tests/never_init.rs
+++ b/third_party/rust/glean/tests/never_init.rs
@@ -39,7 +39,7 @@ mod pings {
#[allow(non_upper_case_globals)]
pub static validation: Lazy<PingType> =
- Lazy::new(|| glean::private::PingType::new("validation", true, true, true, vec![]));
+ Lazy::new(|| glean::private::PingType::new("validation", true, true, true, true, vec![]));
}
/// Test scenario: Glean is never initialized.
diff --git a/third_party/rust/glean/tests/no_time_to_init.rs b/third_party/rust/glean/tests/no_time_to_init.rs
index 763835f2f3..c312b397af 100644
--- a/third_party/rust/glean/tests/no_time_to_init.rs
+++ b/third_party/rust/glean/tests/no_time_to_init.rs
@@ -41,7 +41,7 @@ mod pings {
#[allow(non_upper_case_globals)]
pub static validation: Lazy<PingType> =
- Lazy::new(|| glean::private::PingType::new("validation", true, true, true, vec![]));
+ Lazy::new(|| glean::private::PingType::new("validation", true, true, true, true, vec![]));
}
/// Test scenario: Glean initialization fails.
diff --git a/third_party/rust/glean/tests/schema.rs b/third_party/rust/glean/tests/schema.rs
index 0a1bf4d2e8..01a2108b3c 100644
--- a/third_party/rust/glean/tests/schema.rs
+++ b/third_party/rust/glean/tests/schema.rs
@@ -10,7 +10,7 @@ use glean_core::TextMetric;
use jsonschema_valid::{self, schemas::Draft};
use serde_json::Value;
-use glean::net::UploadResult;
+use glean::net::{PingUploadRequest, UploadResult};
use glean::private::*;
use glean::{
traits, ClientInfoMetrics, CommonMetricData, ConfigurationBuilder, HistogramType, MemoryUnit,
@@ -60,13 +60,8 @@ fn validate_against_schema() {
sender: crossbeam_channel::Sender<Vec<u8>>,
}
impl glean::net::PingUploader for ValidatingUploader {
- fn upload(
- &self,
- _url: String,
- body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> UploadResult {
- self.sender.send(body).unwrap();
+ fn upload(&self, ping_request: PingUploadRequest) -> UploadResult {
+ self.sender.send(ping_request.body).unwrap();
UploadResult::http_status(200)
}
}
@@ -176,7 +171,7 @@ fn validate_against_schema() {
text_metric.set("loooooong text".repeat(100));
// Define a new ping and submit it.
- let custom_ping = glean::private::PingType::new(PING_NAME, true, true, true, vec![]);
+ let custom_ping = glean::private::PingType::new(PING_NAME, true, true, true, true, vec![]);
custom_ping.submit(None);
// Wait for the ping to arrive.
diff --git a/third_party/rust/glean/tests/simple.rs b/third_party/rust/glean/tests/simple.rs
index 3685d44faa..3baa4df14e 100644
--- a/third_party/rust/glean/tests/simple.rs
+++ b/third_party/rust/glean/tests/simple.rs
@@ -41,7 +41,7 @@ mod pings {
#[allow(non_upper_case_globals)]
pub static validation: Lazy<PingType> =
- Lazy::new(|| glean::private::PingType::new("validation", true, true, true, vec![]));
+ Lazy::new(|| glean::private::PingType::new("validation", true, true, true, true, vec![]));
}
/// Test scenario: A clean run
diff --git a/third_party/rust/glean/tests/upload_timing.rs b/third_party/rust/glean/tests/upload_timing.rs
index 9e77fc3eb5..ba0eee3402 100644
--- a/third_party/rust/glean/tests/upload_timing.rs
+++ b/third_party/rust/glean/tests/upload_timing.rs
@@ -97,7 +97,7 @@ mod pings {
#[allow(non_upper_case_globals)]
pub static validation: Lazy<PingType> =
- Lazy::new(|| glean::private::PingType::new("validation", true, true, true, vec![]));
+ Lazy::new(|| glean::private::PingType::new("validation", true, true, true, true, vec![]));
}
// Define a fake uploader that sleeps.
@@ -108,13 +108,9 @@ struct FakeUploader {
}
impl net::PingUploader for FakeUploader {
- fn upload(
- &self,
- _url: String,
- body: Vec<u8>,
- _headers: Vec<(String, String)>,
- ) -> net::UploadResult {
+ fn upload(&self, upload_request: net::PingUploadRequest) -> net::UploadResult {
let calls = self.calls.fetch_add(1, Ordering::SeqCst);
+ let body = upload_request.body;
let decode = |body: Vec<u8>| {
let mut gzip_decoder = GzDecoder::new(&body[..]);
let mut s = String::with_capacity(body.len());