feat: add message to patch event (#210)
This commit is contained in:
+11
-1
@@ -69,11 +69,20 @@ pub struct PatchEvent {
|
||||
|
||||
/// When this event occurred as a Unix epoch timestamp in seconds.
|
||||
pub timestamp: u64,
|
||||
|
||||
/// An optional message to be sent with the event.
|
||||
/// Care should be taken that this field *never* contain PII or sensitive information.
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
impl PatchEvent {
|
||||
/// Creates a `PatchEvent` for the given `EventType` and patch number for reporting to the server.
|
||||
pub fn new(config: &UpdateConfig, event_type: EventType, patch_number: usize) -> PatchEvent {
|
||||
pub fn new(
|
||||
config: &UpdateConfig,
|
||||
event_type: EventType,
|
||||
patch_number: usize,
|
||||
message: Option<&str>,
|
||||
) -> PatchEvent {
|
||||
PatchEvent {
|
||||
app_id: config.app_id.clone(),
|
||||
arch: current_arch().to_string(),
|
||||
@@ -82,6 +91,7 @@ impl PatchEvent {
|
||||
platform: current_platform().to_string(),
|
||||
release_version: config.release_version.clone(),
|
||||
timestamp: time::unix_timestamp(),
|
||||
message: message.map(|s| s.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
-1
@@ -287,12 +287,33 @@ mod tests {
|
||||
release_version: "release_version".to_string(),
|
||||
identifier: EventType::PatchInstallSuccess,
|
||||
timestamp: 1234,
|
||||
message: None,
|
||||
};
|
||||
let request = super::CreatePatchEventRequest { event };
|
||||
let json_string = serde_json::to_string(&request).unwrap();
|
||||
assert_eq!(
|
||||
json_string,
|
||||
r#"{"event":{"app_id":"app_id","arch":"arch","type":"__patch_install__","patch_number":1,"platform":"platform","release_version":"release_version","timestamp":1234}}"#
|
||||
r#"{"event":{"app_id":"app_id","arch":"arch","type":"__patch_install__","patch_number":1,"platform":"platform","release_version":"release_version","timestamp":1234,"message":null}}"#
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_patch_install_event_request_serializes_with_message() {
|
||||
let event = PatchEvent {
|
||||
app_id: "app_id".to_string(),
|
||||
arch: "arch".to_string(),
|
||||
patch_number: 1,
|
||||
platform: "platform".to_string(),
|
||||
release_version: "release_version".to_string(),
|
||||
identifier: EventType::PatchInstallSuccess,
|
||||
timestamp: 1234,
|
||||
message: Some("hello".to_string()),
|
||||
};
|
||||
let request = super::CreatePatchEventRequest { event };
|
||||
let json_string = serde_json::to_string(&request).unwrap();
|
||||
assert_eq!(
|
||||
json_string,
|
||||
r#"{"event":{"app_id":"app_id","arch":"arch","type":"__patch_install__","patch_number":1,"platform":"platform","release_version":"release_version","timestamp":1234,"message":"hello"}}"#
|
||||
)
|
||||
}
|
||||
|
||||
@@ -367,6 +388,7 @@ mod tests {
|
||||
release_version: "release_version".to_string(),
|
||||
identifier: EventType::PatchInstallSuccess,
|
||||
timestamp: time::unix_timestamp(),
|
||||
message: None,
|
||||
};
|
||||
let result = super::report_event_default(
|
||||
// Make the request to a non-existent URL, which will trigger the
|
||||
@@ -395,6 +417,7 @@ mod tests {
|
||||
release_version: "release_version".to_string(),
|
||||
identifier: EventType::PatchInstallSuccess,
|
||||
timestamp: time::unix_timestamp(),
|
||||
message: None,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
+22
-2
@@ -223,6 +223,13 @@ pub fn handle_prior_boot_failure_if_necessary() -> Result<(), InitError> {
|
||||
config,
|
||||
EventType::PatchInstallFailure,
|
||||
patch.number,
|
||||
Some(
|
||||
format!(
|
||||
"Patch {} was marked currently_booting in init",
|
||||
patch.number
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
))?;
|
||||
}
|
||||
|
||||
@@ -420,7 +427,7 @@ fn update_internal(_: &UpdaterLockState) -> anyhow::Result<UpdateStatus> {
|
||||
);
|
||||
|
||||
std::thread::spawn(move || {
|
||||
let event = PatchEvent::new(&config, EventType::PatchDownload, patch.number);
|
||||
let event = PatchEvent::new(&config, EventType::PatchDownload, patch.number, None);
|
||||
let report_result = crate::network::send_patch_event(event, &config);
|
||||
if let Err(err) = report_result {
|
||||
error!("Failed to report patch download: {:?}", err);
|
||||
@@ -562,7 +569,18 @@ pub fn report_launch_failure() -> anyhow::Result<()> {
|
||||
if mark_result.is_err() {
|
||||
error!("Failed to mark patch as bad: {:?}", mark_result);
|
||||
}
|
||||
let event = PatchEvent::new(config, EventType::PatchInstallFailure, patch.number);
|
||||
let event = PatchEvent::new(
|
||||
config,
|
||||
EventType::PatchInstallFailure,
|
||||
patch.number,
|
||||
Some(
|
||||
format!(
|
||||
"Install failure reported from engine for patch {}",
|
||||
patch.number
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
// Queue the failure event for later sending since right after this
|
||||
// function returns the Flutter engine is likely to abort().
|
||||
state.queue_event(event)
|
||||
@@ -612,6 +630,7 @@ pub fn report_launch_success() -> anyhow::Result<()> {
|
||||
&config_copy,
|
||||
EventType::PatchInstallSuccess,
|
||||
booting_patch.number,
|
||||
None,
|
||||
);
|
||||
let report_result = crate::network::send_patch_event(event, &config_copy);
|
||||
if let Err(err) = report_result {
|
||||
@@ -1216,6 +1235,7 @@ mod tests {
|
||||
platform: current_platform().to_string(),
|
||||
release_version: config.release_version.clone(),
|
||||
timestamp: time::unix_timestamp(),
|
||||
message: Some("Install failure reported from engine for patch 1".to_string()),
|
||||
};
|
||||
// Queue 5 events.
|
||||
assert!(state.queue_event(fail_event.clone()).is_ok());
|
||||
|
||||
Reference in New Issue
Block a user