chore(gui-client): log uptime and run ID when a window is shown (#3913)

I want to make sure there aren't bugs that prevent the GUI clients from
reaching high uptime, so this makes it easy to check the uptime with
e.g. `tail -f`. The run IDs would let us re-construct when the app
restarts.

"chore" doesn't seem right but it's not a user-facing feature, test,
doc, fix, or refactor, either.

Signed-off-by: Reactor Scram <ReactorScram@users.noreply.github.com>
This commit is contained in:
Reactor Scram
2024-03-04 12:13:22 -06:00
committed by GitHub
parent 09f82b5b5a
commit 9c93345885
3 changed files with 46 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ mod network_changes;
mod resolvers;
mod settings;
mod updates;
mod uptime;
#[cfg(target_os = "windows")]
mod wintun_install;

View File

@@ -503,6 +503,7 @@ struct Controller {
/// Tells us when to wake up and look for a new resource list. Tokio docs say that memory reads and writes are synchronized when notifying, so we don't need an extra mutex on the resources.
notify_controller: Arc<Notify>,
tunnel_ready: bool,
uptime: client::uptime::Tracker,
}
/// Everything related to a signed-in user session
@@ -634,7 +635,18 @@ impl Controller {
self.sign_out()?;
}
}
Req::SystemTrayMenu(TrayMenuEvent::ShowWindow(window)) => self.show_window(window)?,
Req::SystemTrayMenu(TrayMenuEvent::ShowWindow(window)) => {
self.show_window(window)?;
// When the About or Settings windows are hidden / shown, log the
// run ID and uptime. This makes it easy to check client stability on
// dev or test systems without parsing the whole log file.
let uptime_info = self.uptime.info();
tracing::debug!(
uptime_s = uptime_info.uptime.as_secs(),
run_id = uptime_info.run_id.to_string(),
"Uptime info"
);
}
Req::SystemTrayMenu(TrayMenuEvent::Resource { id }) => self
.copy_resource(&id)
.context("Couldn't copy resource to clipboard")?,
@@ -784,6 +796,7 @@ async fn run_controller(
logging_handles,
notify_controller,
tunnel_ready: false,
uptime: Default::default(),
};
if let Some(token) = controller

View File

@@ -0,0 +1,31 @@
use std::time::Duration;
use tokio::time::Instant;
use uuid::Uuid;
pub struct Tracker {
run_id: Uuid,
start_time: Instant,
}
pub struct Info {
pub run_id: Uuid,
pub uptime: Duration,
}
impl Default for Tracker {
fn default() -> Self {
Self {
start_time: Instant::now(),
run_id: Uuid::new_v4(),
}
}
}
impl Tracker {
pub fn info(&self) -> Info {
Info {
run_id: self.run_id,
uptime: Instant::now() - self.start_time,
}
}
}