aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorHazel Atkinson <yellowsink@riseup.net>2025-04-09 21:01:51 +0100
committerHazel Atkinson <yellowsink@riseup.net>2025-04-09 21:02:11 +0100
commit31f94168f7625f6dd9f13ef97165ae7c9d2a4ab4 (patch)
treeefab3dc920fc8763cbfff62ee8055ef7d2f03e20 /src/main.rs
parentbf0bb179554aedf61aa0212fe2b5c489e4d5da05 (diff)
downloadcontainerspy-31f94168f7625f6dd9f13ef97165ae7c9d2a4ab4.tar.gz
containerspy-31f94168f7625f6dd9f13ef97165ae7c9d2a4ab4.tar.bz2
containerspy-31f94168f7625f6dd9f13ef97165ae7c9d2a4ab4.zip
add structured logging, fix docker exit code
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 07ebeb0..26b2a4b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,9 +8,11 @@ use std::{collections::BTreeMap, sync::Arc, time::Duration};
use tokio::task::JoinHandle;
use tokio::time::MissedTickBehavior;
use tokio_util::sync::CancellationToken;
+use crate::s_log::*;
mod config;
mod stats_task;
+mod s_log;
// includes data from Cargo.toml and other sources using the `built` crate
pub mod built_info {
@@ -101,10 +103,11 @@ async fn main() -> Result<()> {
let st2 = shutdown_token.clone(); // to be moved into the task
tokio::spawn(async move {
- tokio::signal::ctrl_c()
- .await
- .expect("Failed to setup ctrl-c handler");
- st2.cancel();
+ if tokio::signal::ctrl_c().await.is_ok() {
+ st2.cancel();
+ } else {
+ warn("Failed to setup SIGINT handler, metrics may be dropped on exit", []);
+ }
});
let mut container_search_interval =
@@ -132,6 +135,7 @@ async fn main() -> Result<()> {
.binary_search_by(|c| c.id.as_ref().unwrap().cmp(cont))
.is_err()
{
+ debug(format_args!("Killing worker for {}", cont), [("container_id", &**cont)]);
handle.abort();
to_remove.push(cont.clone());
}
@@ -145,6 +149,7 @@ async fn main() -> Result<()> {
for cont in containers {
let id_string = cont.id.as_ref().unwrap();
if !tasks.contains_key(id_string) {
+ debug(format_args!("Launching worker for {}", id_string), [("container_id", &**id_string)]);
// all this string cloning hurts me
tasks.insert(
id_string.clone(),
@@ -159,7 +164,9 @@ async fn main() -> Result<()> {
task.abort();
}
- println!("clean shutdown.");
+ debug("Exiting cleanly", []);
+
+ let _ = meter_provider.force_flush();
Ok(())
}