diff options
Diffstat (limited to 'third_party/rust/glean-core/src/ping/mod.rs')
-rw-r--r-- | third_party/rust/glean-core/src/ping/mod.rs | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/third_party/rust/glean-core/src/ping/mod.rs b/third_party/rust/glean-core/src/ping/mod.rs index c22a890aa2..d1a67ae360 100644 --- a/third_party/rust/glean-core/src/ping/mod.rs +++ b/third_party/rust/glean-core/src/ping/mod.rs @@ -14,7 +14,7 @@ use serde_json::{json, Value as JsonValue}; use crate::common_metric_data::{CommonMetricData, Lifetime}; use crate::metrics::{CounterMetric, DatetimeMetric, Metric, MetricType, PingType, TimeUnit}; use crate::storage::{StorageManager, INTERNAL_STORAGE}; -use crate::upload::HeaderMap; +use crate::upload::{HeaderMap, PingMetadata}; use crate::util::{get_iso_time_string, local_now_with_offset}; use crate::{Glean, Result, DELETION_REQUEST_PINGS_DIRECTORY, PENDING_PINGS_DIRECTORY}; @@ -30,6 +30,8 @@ pub struct Ping<'a> { pub content: JsonValue, /// The headers to upload with the payload. pub headers: HeaderMap, + /// Whether the content contains {client|ping}_info sections. + pub includes_info_sections: bool, } /// Collect a ping's data, assemble it into its full payload and store it on disk. @@ -237,9 +239,9 @@ impl PingMaker { .snapshot_as_json(glean, ping.name(), true); // Due to the way the experimentation identifier could link datasets that are intentionally unlinked, - // it will not be included in pings that specifically exclude the Glean client-id and those pings that - // should not be sent if empty. - if (!ping.include_client_id() || !ping.send_if_empty()) + // it will not be included in pings that specifically exclude the Glean client-id, those pings that + // should not be sent if empty, or pings that exclude the {client|ping}_info sections wholesale. + if (!ping.include_client_id() || !ping.send_if_empty() || !ping.include_info_sections()) && glean.test_get_experimentation_id().is_some() && metrics_data.is_some() { @@ -285,13 +287,18 @@ impl PingMaker { TimeUnit::Minute }; - let ping_info = self.get_ping_info(glean, ping.name(), reason, precision); - let client_info = self.get_client_info(glean, ping.include_client_id()); + let mut json = if ping.include_info_sections() { + let ping_info = self.get_ping_info(glean, ping.name(), reason, precision); + let client_info = self.get_client_info(glean, ping.include_client_id()); + + json!({ + "ping_info": ping_info, + "client_info": client_info + }) + } else { + json!({}) + }; - let mut json = json!({ - "ping_info": ping_info, - "client_info": client_info - }); let json_obj = json.as_object_mut()?; if let Some(metrics_data) = metrics_data { json_obj.insert("metrics".to_string(), metrics_data); @@ -306,6 +313,7 @@ impl PingMaker { doc_id, url_path, headers: self.get_headers(glean), + includes_info_sections: ping.include_info_sections(), }) } @@ -355,11 +363,17 @@ impl PingMaker { file.write_all(ping.url_path.as_bytes())?; file.write_all(b"\n")?; file.write_all(::serde_json::to_string(&ping.content)?.as_bytes())?; - if !ping.headers.is_empty() { - file.write_all(b"\n{\"headers\":")?; - file.write_all(::serde_json::to_string(&ping.headers)?.as_bytes())?; - file.write_all(b"}")?; - } + file.write_all(b"\n")?; + let metadata = PingMetadata { + // We don't actually need to clone the headers except to match PingMetadata's ownership. + // But since we're going to write a file to disk in a sec, + // and HeaderMaps tend to have only like two things in them, tops, + // the cost is bearable. + headers: Some(ping.headers.clone()), + body_has_info_sections: Some(ping.includes_info_sections), + ping_name: Some(ping.name.to_string()), + }; + file.write_all(::serde_json::to_string(&metadata)?.as_bytes())?; } if let Err(e) = std::fs::rename(&temp_ping_path, &ping_path) { |