mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-02 04:22:56 +00:00
Bug 1591564 - Convert FOGotype Glean pings to pingsender format and send them r=janerik
Differential Revision: https://phabricator.services.mozilla.com/D57108 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
3e39cc6eea
commit
f3ef53118d
@ -1171,7 +1171,7 @@ TelemetryImpl::GetIsOfficialTelemetry(bool* ret) {
|
||||
// C functions with the "fog_" prefix.
|
||||
// See toolkit/components/telemetry/fog/*.
|
||||
extern "C" {
|
||||
nsresult fog_init(const nsAString* dataDir);
|
||||
nsresult fog_init(const nsAString* dataDir, const nsAString* pingsenderPath);
|
||||
}
|
||||
|
||||
static void internal_initFogotype(bool aUseTelemetry) {
|
||||
@ -1187,7 +1187,26 @@ static void internal_initFogotype(bool aUseTelemetry) {
|
||||
NS_WARNING("Couldn't get data path. Bailing on FOGotype.");
|
||||
return;
|
||||
}
|
||||
NS_WARN_IF(NS_FAILED(fog_init(&path)));
|
||||
|
||||
nsCOMPtr<nsIFile> pingsender;
|
||||
rv = NS_GetSpecialDirectory(NS_GRE_BIN_DIR, getter_AddRefs(pingsender));
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Couldn't find pingsender. Bailing on FOGotype");
|
||||
return;
|
||||
}
|
||||
#ifdef XP_WIN
|
||||
pingsender->Append(NS_LITERAL_STRING("pingsender.exe"));
|
||||
#else
|
||||
pingsender->Append(NS_LITERAL_STRING("pingsender"));
|
||||
#endif
|
||||
nsAutoString pingsenderPath;
|
||||
rv = pingsender->GetPath(pingsenderPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Couldn't get pingsender path. Bailing on FOGotype.");
|
||||
return;
|
||||
}
|
||||
|
||||
Unused << NS_WARN_IF(NS_FAILED(fog_init(&path, &pingsenderPath)));
|
||||
}
|
||||
#endif // defined(MOZ_FOGOTYPE)
|
||||
|
||||
|
@ -7,11 +7,14 @@ use glean_preview::metrics::PingType;
|
||||
use nserror::{nsresult, NS_ERROR_FAILURE, NS_OK};
|
||||
use nsstring::nsAString;
|
||||
use std::{thread, time};
|
||||
use std::io::Error;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, BufRead, BufReader, Error, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::thread::JoinHandle;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_init(data_dir: &nsAString) -> nsresult {
|
||||
pub unsafe extern "C" fn fog_init(data_dir: &nsAString, pingsender_path: &nsAString) -> nsresult {
|
||||
|
||||
let upload_enabled = static_prefs::pref!("datareporting.healthreport.uploadEnabled");
|
||||
|
||||
@ -27,17 +30,21 @@ pub unsafe extern "C" fn fog_init(data_dir: &nsAString) -> nsresult {
|
||||
return NS_ERROR_FAILURE
|
||||
}
|
||||
|
||||
let mut data_path = PathBuf::from(data_dir.to_string());
|
||||
data_path.push("pending_pings");
|
||||
let pingsender_path = PathBuf::from(pingsender_path.to_string());
|
||||
|
||||
// We ignore the returned JoinHandle for the nonce.
|
||||
// The detached thread will live until this process (the main process) dies.
|
||||
if prototype_ping_init().is_err() {
|
||||
if prototype_ping_init(data_path, pingsender_path).is_err() {
|
||||
return NS_ERROR_FAILURE
|
||||
}
|
||||
|
||||
NS_OK
|
||||
}
|
||||
|
||||
fn prototype_ping_init() -> Result<JoinHandle<()>, Error> {
|
||||
thread::Builder::new().name("fogotype_ping".to_owned()).spawn(|| {
|
||||
fn prototype_ping_init(ping_dir: PathBuf, pingsender_path: PathBuf) -> Result<JoinHandle<()>, Error> {
|
||||
thread::Builder::new().name("fogotype_ping".to_owned()).spawn(move || {
|
||||
let prototype_ping = PingType::new("prototype", true, true);
|
||||
glean_preview::register_ping_type(&prototype_ping);
|
||||
|
||||
@ -47,6 +54,59 @@ fn prototype_ping_init() -> Result<JoinHandle<()>, Error> {
|
||||
let upload_enabled = static_prefs::pref!("datareporting.healthreport.uploadEnabled");
|
||||
glean_preview::set_upload_enabled(upload_enabled);
|
||||
prototype_ping.send();
|
||||
if let Err(_e) = send_all_pings(&ping_dir, &pingsender_path) {
|
||||
// TODO: Do something with _e.
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn send_all_pings(ping_dir: &Path, pingsender_path: &Path) -> io::Result<()> {
|
||||
assert!(ping_dir.is_dir());
|
||||
// This will be a multi-step process:
|
||||
// 1. Ensure we have an (empty) subdirectory in ping_dir called "telemetry" we can work within.
|
||||
// 2. Split the endpoint out of the glean-format ping in ping_dir, writing the rest to telemetry/.
|
||||
// 3. Invoke pingsender{.exe} for the ping in telemetry to the endpoint from the glean-format ping file we most timely ripp'd.
|
||||
// 4. Return to 2 while pings remain in ping_dir
|
||||
|
||||
let telemetry_dir = ping_dir.join("telemetry");
|
||||
let _ = fs::remove_dir_all(&telemetry_dir);
|
||||
fs::create_dir(&telemetry_dir)?;
|
||||
|
||||
for entry in fs::read_dir(ping_dir)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
if !path.is_file() {
|
||||
continue;
|
||||
}
|
||||
// Do the things.
|
||||
let file = File::open(&path)?;
|
||||
let reader = BufReader::new(file);
|
||||
let lines: Vec<String> = reader.lines().filter_map(io::Result::ok).collect();
|
||||
|
||||
// Sanity check: Glean SDK ping file format is two lines.
|
||||
// First line is the path of the ingestion endpoint.
|
||||
// Second line is the payload.
|
||||
if lines.len() != 2 {
|
||||
// Doesn't look like a Glean SDK-format ping. Get rid of it.
|
||||
fs::remove_file(path)?;
|
||||
continue;
|
||||
}
|
||||
|
||||
let telemetry_ping_path = telemetry_dir.join(path.file_name().unwrap());
|
||||
let mut telemetry_ping_file = File::create(&telemetry_ping_path)?;
|
||||
write!(telemetry_ping_file, "{}", lines[1])?;
|
||||
|
||||
fs::remove_file(path)?;
|
||||
|
||||
let mut pingsender = Command::new(pingsender_path);
|
||||
pingsender.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.stdin(Stdio::null());
|
||||
|
||||
let _status = pingsender.arg(format!("https://incoming.telemetry.mozilla.org{}", lines[0]))
|
||||
.arg(&telemetry_ping_path)
|
||||
.status();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user