Bug 1591564 - Update glean-preview to 0.0.4 r=janerik

Differential Revision: https://phabricator.services.mozilla.com/D57977

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris H-C 2020-01-13 18:52:24 +00:00
Родитель c160ad338d
Коммит a02b492d20
12 изменённых файлов: 283 добавлений и 30 удалений

6
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"

Просмотреть файл

@ -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"}
{"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"}

15
third_party/rust/glean-preview/CHANGELOG.md поставляемый Normal file
Просмотреть файл

@ -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.

4
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 <jrediger@mozilla.com>", "The Glean Team <glean-team@mozilla.com>"]
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"]

2
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

22
third_party/rust/glean-preview/src/configuration.rs поставляемый Normal file
Просмотреть файл

@ -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<usize>,
/// 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<String>,
}

107
third_party/rust/glean-preview/src/core_metrics.rs поставляемый Normal file
Просмотреть файл

@ -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,
}),
}
}
}

69
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<Mutex<Glean>> = 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<String>) {
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))
}

Просмотреть файл

@ -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)
}
}

65
third_party/rust/glean-preview/src/system.rs поставляемый Normal file
Просмотреть файл

@ -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: <https://github.com/RustSec/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";

Просмотреть файл

@ -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" }

Просмотреть файл

@ -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<Jo
thread::sleep(an_hour);
let upload_enabled = static_prefs::pref!("datareporting.healthreport.uploadEnabled");
glean_preview::set_upload_enabled(upload_enabled);
prototype_ping.send();
if !upload_enabled {
continue;
}
prototype_ping.submit();
if let Err(e) = send_all_pings(&ping_dir, &pingsender_path) {
error!("Failed to send all pings due to {:?}", e);
}