diff --git a/Cargo.lock b/Cargo.lock index 81875926ec06..6db47b50626f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1180,7 +1180,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "fog" version = "0.1.0" dependencies = [ - "glean-preview 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "glean-preview 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "nserror 0.1.0", "nsstring 0.1.0", @@ -1549,7 +1549,7 @@ dependencies = [ [[package]] name = "glean-preview" -version = "0.0.2" +version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "glean-core 22.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4766,7 +4766,7 @@ dependencies = [ "checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd" "checksum gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7f46fd8874e043ffac0d638ed1567a2584f7814f6d72b4db37ab1689004a26c4" "checksum glean-core 22.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37b55f71885fc523ac6327feb24e31bde57d9c5679b4553e942306adb44be408" -"checksum glean-preview 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cc50cdfb3c420f83b14e5f130279af9f66d4b3f693c32edf76bc6e3450321434" +"checksum glean-preview 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cb3bf34b889307680056e1493552dc6385becaea073ed99743a5e1a340ed2342" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" "checksum goblin 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88a79ef1f0dad46fd78075b6f80f92d97710eddf87b3e18a15a66761e8942672" "checksum guid_win 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "87261686cc5e35b6584f4c2a430c2b153d8a92ab1ef820c16be34c1df8f5f58b" diff --git a/third_party/rust/glean-preview/.cargo-checksum.json b/third_party/rust/glean-preview/.cargo-checksum.json index 493907c6730b..0f18bfac819b 100644 --- a/third_party/rust/glean-preview/.cargo-checksum.json +++ b/third_party/rust/glean-preview/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"c4a40b0a35d7435c1413880650bca50577beb519a0dc716883a54766a252901b","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"5b03d20955e9c9b31f73b4a04d65194f88d9cd73a1119fbbe1f1ebb7b1515d99","src/lib.rs":"d44002ec88fd167e3fb03ffd9951fd392b871b9ffd807e20144ba1ebf4ec2092","src/metrics/mod.rs":"3f0dc73758bc5836362742b4ab424032f4f398151c6e85ea879a4e7641614347","src/metrics/ping.rs":"10c2e58231d1348d9d2d2b374def6e230158d11dabc96fb32b9634729509e376"},"package":"cc50cdfb3c420f83b14e5f130279af9f66d4b3f693c32edf76bc6e3450321434"} \ No newline at end of file +{"files":{"CHANGELOG.md":"9adfab85300058ddcaf7c7805150bb64effb1d4d367ff6e5bc28d9e3ded226be","Cargo.toml":"a847452858135864ba7778ba219b734d3663a4a97494a81cc2d9d0d167146bd5","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"f234c25515132b7205fcf05545f1d5661bba6f2c189aca848290c7e32b832952","src/configuration.rs":"16e3ec9be802ac37b39d2ad4d1a4702d7e5b462071ef7f0265aea84de520641f","src/core_metrics.rs":"0490dfefaccdbb36ead40af02fa4aa75ebb98056884f2eef4340fe27a24f6cfd","src/lib.rs":"5764c3d3760dd071729ffd4de18d51668db76707f370b4214269c19bb98e890b","src/metrics/mod.rs":"3f0dc73758bc5836362742b4ab424032f4f398151c6e85ea879a4e7641614347","src/metrics/ping.rs":"27f5153b33060b817304e11ec58cb17184a6264f29fc45cd7042464c3a9263b5","src/system.rs":"7dbe5007bdaa3d4547c992757c26b7543e059f179078f06b946adad0a0bb4e34"},"package":"cb3bf34b889307680056e1493552dc6385becaea073ed99743a5e1a340ed2342"} \ No newline at end of file diff --git a/third_party/rust/glean-preview/CHANGELOG.md b/third_party/rust/glean-preview/CHANGELOG.md new file mode 100644 index 000000000000..81730ed9f12b --- /dev/null +++ b/third_party/rust/glean-preview/CHANGELOG.md @@ -0,0 +1,15 @@ +# v0.0.4 (2019-12-20) + +* Set target architecture in `client_info` ([#603](https://github.com/mozilla/glean/pull/603)) + +# v0.0.3 (2019-12-19) + +* **Breaking Change**: Stub out client info values and provide a way to set app version information ([#592](https://github.com/mozilla/glean/pull/592)) + +# v0.0.2 (2019-12-09) + +* Removed glean-ffi dependency in favor of implementing state in this crate + +# v0.0.1 (2019-12-05) + +First release of the Glean Rust API preview. diff --git a/third_party/rust/glean-preview/Cargo.toml b/third_party/rust/glean-preview/Cargo.toml index 57a695d3a208..4fa81bf491bd 100644 --- a/third_party/rust/glean-preview/Cargo.toml +++ b/third_party/rust/glean-preview/Cargo.toml @@ -13,9 +13,9 @@ [package] edition = "2018" name = "glean-preview" -version = "0.0.2" +version = "0.0.4" authors = ["Jan-Erik Rediger ", "The Glean Team "] -include = ["README.md", "LICENSE", "src/**/*", "tests/**/*", "Cargo.toml"] +include = ["README.md", "LICENSE", "CHANGELOG.md", "src/**/*", "tests/**/*", "Cargo.toml"] description = "Nice Glean SDK Rust API" readme = "README.md" keywords = ["telemetry", "glean"] diff --git a/third_party/rust/glean-preview/README.md b/third_party/rust/glean-preview/README.md index 2154c7267d8a..2b5e882f8ac0 100644 --- a/third_party/rust/glean-preview/README.md +++ b/third_party/rust/glean-preview/README.md @@ -37,7 +37,7 @@ let prototype_ping = PingType::new("prototype", true, true); glean_preview::register_ping_type(&prototype_ping); -prototype_ping.send(); +prototype_ping.submit(); ``` ## License diff --git a/third_party/rust/glean-preview/src/configuration.rs b/third_party/rust/glean-preview/src/configuration.rs new file mode 100644 index 000000000000..059b3d92283d --- /dev/null +++ b/third_party/rust/glean-preview/src/configuration.rs @@ -0,0 +1,22 @@ +// 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/. + +/// The Glean configuration. +/// +/// Optional values will be filled in with default values. +#[derive(Debug, Clone)] +pub struct Configuration { + /// Whether upload should be enabled. + pub upload_enabled: bool, + /// Path to a directory to store all data in. + pub data_path: String, + /// The application ID (will be sanitized during initialization). + pub application_id: String, + /// The maximum number of events to store before sending a ping containing events. + pub max_events: Option, + /// Whether Glean should delay persistence of data from metrics with ping lifetime. + pub delay_ping_lifetime_io: bool, + /// The release channel the application is on, if known. + pub channel: Option, +} diff --git a/third_party/rust/glean-preview/src/core_metrics.rs b/third_party/rust/glean-preview/src/core_metrics.rs new file mode 100644 index 000000000000..2215e87e1e9f --- /dev/null +++ b/third_party/rust/glean-preview/src/core_metrics.rs @@ -0,0 +1,107 @@ +// 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 glean_core::{metrics::StringMetric, CommonMetricData, Lifetime}; + +/// Metrics included in every ping as `client_info`. +#[derive(Debug)] +pub struct ClientInfoMetrics { + /// The build identifier generated by the CI system (e.g. "1234/A"). + pub app_build: String, + /// The user visible version string (e.g. "1.0.3"). + pub app_display_version: String, +} + +impl ClientInfoMetrics { + /// Create the client info with dummy values for all. + pub fn unknown() -> Self { + ClientInfoMetrics { + app_build: "unknown".to_string(), + app_display_version: "unknown".to_string(), + } + } +} + +#[derive(Debug)] +pub struct InternalMetrics { + pub app_build: StringMetric, + pub app_display_version: StringMetric, + pub app_channel: StringMetric, + pub os: StringMetric, + pub os_version: StringMetric, + pub architecture: StringMetric, + pub device_manufacturer: StringMetric, + pub device_model: StringMetric, +} + +impl InternalMetrics { + pub fn new() -> Self { + Self { + app_build: StringMetric::new(CommonMetricData { + name: "app_build".into(), + category: "".into(), + send_in_pings: vec!["glean_client_info".into()], + lifetime: Lifetime::Application, + disabled: false, + dynamic_label: None, + }), + app_display_version: StringMetric::new(CommonMetricData { + name: "app_display_version".into(), + category: "".into(), + send_in_pings: vec!["glean_client_info".into()], + lifetime: Lifetime::Application, + disabled: false, + dynamic_label: None, + }), + app_channel: StringMetric::new(CommonMetricData { + name: "app_channel".into(), + category: "".into(), + send_in_pings: vec!["glean_client_info".into()], + lifetime: Lifetime::Application, + disabled: false, + dynamic_label: None, + }), + os: StringMetric::new(CommonMetricData { + name: "os".into(), + category: "".into(), + send_in_pings: vec!["glean_client_info".into()], + lifetime: Lifetime::Application, + disabled: false, + dynamic_label: None, + }), + os_version: StringMetric::new(CommonMetricData { + name: "os_version".into(), + category: "".into(), + send_in_pings: vec!["glean_client_info".into()], + lifetime: Lifetime::Application, + disabled: false, + dynamic_label: None, + }), + architecture: StringMetric::new(CommonMetricData { + name: "architecture".into(), + category: "".into(), + send_in_pings: vec!["glean_client_info".into()], + lifetime: Lifetime::Application, + disabled: false, + dynamic_label: None, + }), + device_manufacturer: StringMetric::new(CommonMetricData { + name: "device_manufacturer".into(), + category: "".into(), + send_in_pings: vec!["glean_client_info".into()], + lifetime: Lifetime::Application, + disabled: false, + dynamic_label: None, + }), + device_model: StringMetric::new(CommonMetricData { + name: "device_model".into(), + category: "".into(), + send_in_pings: vec!["glean_client_info".into()], + lifetime: Lifetime::Application, + disabled: false, + dynamic_label: None, + }), + } + } +} diff --git a/third_party/rust/glean-preview/src/lib.rs b/third_party/rust/glean-preview/src/lib.rs index cb4ac692d6f2..57ce58a0a5a2 100644 --- a/third_party/rust/glean-preview/src/lib.rs +++ b/third_party/rust/glean-preview/src/lib.rs @@ -17,7 +17,7 @@ //! Initialize Glean, register a ping and then send it. //! //! ```rust,no_run -//! # use glean_preview::{Configuration, Error, metrics::*}; +//! # use glean_preview::{Configuration, ClientInfoMetrics, Error, metrics::*}; //! # fn main() -> Result<(), Error> { //! let cfg = Configuration { //! data_path: "/tmp/data".into(), @@ -25,14 +25,15 @@ //! upload_enabled: true, //! max_events: None, //! delay_ping_lifetime_io: false, +//! channel: None, //! }; -//! glean_preview::initialize(cfg)?; +//! glean_preview::initialize(cfg, ClientInfoMetrics::unknown())?; //! //! let prototype_ping = PingType::new("prototype", true, true); //! //! glean_preview::register_ping_type(&prototype_ping); //! -//! prototype_ping.send(); +//! prototype_ping.submit(); //! # Ok(()) //! # } //! ``` @@ -40,9 +41,14 @@ use once_cell::sync::OnceCell; use std::sync::Mutex; -pub use glean_core::{Configuration, Error, Glean, Result}; +pub use configuration::Configuration; +pub use core_metrics::ClientInfoMetrics; +pub use glean_core::{CommonMetricData, Error, Glean, Lifetime, Result}; +mod configuration; +mod core_metrics; pub mod metrics; +mod system; static GLEAN: OnceCell> = OnceCell::new(); @@ -83,13 +89,46 @@ where /// Create and initialize a new Glean object. /// /// See `glean_core::Glean::new`. -pub fn initialize(cfg: Configuration) -> Result<()> { +pub fn initialize(cfg: Configuration, client_info: ClientInfoMetrics) -> Result<()> { + let channel = cfg.channel; + let cfg = glean_core::Configuration { + upload_enabled: cfg.upload_enabled, + data_path: cfg.data_path, + application_id: cfg.application_id, + max_events: cfg.max_events, + delay_ping_lifetime_io: cfg.delay_ping_lifetime_io, + }; let glean = Glean::new(cfg)?; + + // First initialize core metrics + initialize_core_metrics(&glean, client_info, channel); + // Now make this the global object available to others. setup_glean(glean)?; Ok(()) } +fn initialize_core_metrics(glean: &Glean, client_info: ClientInfoMetrics, channel: Option) { + let core_metrics = core_metrics::InternalMetrics::new(); + + core_metrics.app_build.set(glean, client_info.app_build); + core_metrics + .app_display_version + .set(glean, client_info.app_display_version); + if let Some(app_channel) = channel { + core_metrics.app_channel.set(glean, app_channel); + } + core_metrics.os.set(glean, system::OS.to_string()); + core_metrics.os_version.set(glean, "unknown".to_string()); + core_metrics + .architecture + .set(glean, system::ARCH.to_string()); + core_metrics + .device_manufacturer + .set(glean, "unknown".to_string()); + core_metrics.device_model.set(glean, "unknown".to_string()); +} + /// Set whether upload is enabled or not. /// /// See `glean_core::Glean.set_upload_enabled`. @@ -114,33 +153,33 @@ pub fn register_ping_type(ping: &metrics::PingType) { }) } -/// Send a ping. +/// Collect and submit a ping for eventual uploading. /// -/// See `glean_core::Glean.send_ping`. +/// See `glean_core::Glean.submit_ping`. /// /// ## Return value /// /// Returns true if a ping was assembled and queued, false otherwise. -pub fn send_ping(ping: &metrics::PingType) -> bool { - send_ping_by_name(&ping.name) +pub fn submit_ping(ping: &metrics::PingType) -> bool { + submit_ping_by_name(&ping.name) } -/// Send a ping by name. +/// Collect and submit a ping for eventual uploading by name. /// -/// See `glean_core::Glean.send_ping_by_name`. +/// See `glean_core::Glean.submit_ping_by_name`. /// /// ## Return value /// /// Returns true if a ping was assembled and queued, false otherwise. -pub fn send_ping_by_name(ping: &str) -> bool { - send_pings_by_name(&[ping.to_string()]) +pub fn submit_ping_by_name(ping: &str) -> bool { + submit_pings_by_name(&[ping.to_string()]) } -/// Send multiple pings by name +/// Collect and submit multiple pings by name for eventual uploading. /// /// ## Return value /// /// Returns true if at least one ping was assembled and queued, false otherwise. -pub fn send_pings_by_name(pings: &[String]) -> bool { +pub fn submit_pings_by_name(pings: &[String]) -> bool { with_glean(|glean| glean.send_pings_by_name(pings)) } diff --git a/third_party/rust/glean-preview/src/metrics/ping.rs b/third_party/rust/glean-preview/src/metrics/ping.rs index d5a44943b41f..260158e3f643 100644 --- a/third_party/rust/glean-preview/src/metrics/ping.rs +++ b/third_party/rust/glean-preview/src/metrics/ping.rs @@ -28,12 +28,12 @@ impl PingType { Self { name, ping_type } } - /// Send the ping. + /// Submit the ping. /// /// ## Return value /// /// Returns true if a ping was assembled and queued, false otherwise. - pub fn send(&self) -> bool { - crate::send_ping(self) + pub fn submit(&self) -> bool { + crate::submit_ping(self) } } diff --git a/third_party/rust/glean-preview/src/system.rs b/third_party/rust/glean-preview/src/system.rs new file mode 100644 index 000000000000..468cc9887088 --- /dev/null +++ b/third_party/rust/glean-preview/src/system.rs @@ -0,0 +1,65 @@ +// 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/. + +// Detect and expose `target_os` as a constant. +// Whether this is a good idea is somewhat debatable. +// +// Code adopted from the "platforms" crate: . + +#[cfg(target_os = "android")] +/// `target_os` when building this crate: `android` +pub const OS: &str = "Android"; + +#[cfg(target_os = "ios")] +/// `target_os` when building this crate: `ios` +pub const OS: &str = "iOS"; + +#[cfg(target_os = "linux")] +/// `target_os` when building this crate: `linux` +pub const OS: &str = "Linux"; + +#[cfg(target_os = "macos")] +/// `target_os` when building this crate: `macos` +pub const OS: &str = "MacOS"; + +#[cfg(target_os = "windows")] +/// `target_os` when building this crate: `windows` +pub const OS: &str = "Windows"; + +#[cfg(not(any( + target_os = "android", + target_os = "ios", + target_os = "linux", + target_os = "macos", + target_os = "windows", +)))] +pub const OS: &str = "unknown"; + +// Detect and expose `target_arch` as a constant +// Whether this is a good idea is somewhat debatable + +#[cfg(target_arch = "aarch64")] +/// `target_arch` when building this crate: `aarch64` +pub const ARCH: &str = "aarch64"; + +#[cfg(target_arch = "arm")] +/// `target_arch` when building this crate: `arm` +pub const ARCH: &str = "arm"; + +#[cfg(target_arch = "x86")] +/// `target_arch` when building this crate: `x86` +pub const ARCH: &str = "x86"; + +#[cfg(target_arch = "x86_64")] +/// `target_arch` when building this crate: `x86_64` +pub const ARCH: &str = "x86_64"; + +#[cfg(not(any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86", + target_arch = "x86_64" +)))] +/// `target_arch` when building this crate: unknown! +pub const ARCH: &str = "unknown"; diff --git a/toolkit/components/telemetry/fog/Cargo.toml b/toolkit/components/telemetry/fog/Cargo.toml index 23d47ddb7f0b..a262a326dfe0 100644 --- a/toolkit/components/telemetry/fog/Cargo.toml +++ b/toolkit/components/telemetry/fog/Cargo.toml @@ -8,7 +8,7 @@ license = "MPL-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -glean-preview = "0.0.2" +glean-preview = "0.0.4" log = "0.4" nserror = { path = "../../../../xpcom/rust/nserror" } nsstring = { path = "../../../../xpcom/rust/nsstring" } diff --git a/toolkit/components/telemetry/fog/src/lib.rs b/toolkit/components/telemetry/fog/src/lib.rs index a3f8e8e51920..4d92f1ed7f12 100644 --- a/toolkit/components/telemetry/fog/src/lib.rs +++ b/toolkit/components/telemetry/fog/src/lib.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 http://mozilla.org/MPL/2.0/. */ -use glean_preview::Configuration; +use glean_preview::{ClientInfoMetrics, Configuration}; use glean_preview::metrics::PingType; use log::error; use nserror::{nsresult, NS_ERROR_FAILURE, NS_OK}; @@ -22,12 +22,14 @@ pub unsafe extern "C" fn fog_init(data_dir: &nsAString, pingsender_path: &nsAStr let cfg = Configuration { data_path: data_dir.to_string(), application_id: "org.mozilla.fogotype".into(), - upload_enabled: upload_enabled, + upload_enabled, max_events: None, delay_ping_lifetime_io: false, // We will want this eventually. + channel: Some("nightly".into()), }; - if glean_preview::initialize(cfg).is_err() { + // TODO: Build our own ClientInfoMetrics instead of using unknown(). + if glean_preview::initialize(cfg, ClientInfoMetrics::unknown()).is_err() { return NS_ERROR_FAILURE } @@ -54,7 +56,10 @@ fn prototype_ping_init(ping_dir: PathBuf, pingsender_path: PathBuf) -> Result