Skip to content

Commit

Permalink
Log crashtracker errors in sidecar
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Weinand <[email protected]>
  • Loading branch information
bwoebi committed Jan 30, 2025
1 parent 043ebdd commit 1440610
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions crashtracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub use crash_info::*;

#[cfg(all(unix, feature = "receiver"))]
pub use receiver::{
async_receiver_entry_point_unix_socket, receiver_entry_point_stdin,
receiver_entry_point_unix_socket,
async_receiver_entry_point_unix_listener, async_receiver_entry_point_unix_socket,
get_receiver_unix_socket, receiver_entry_point_stdin, receiver_entry_point_unix_socket,
};

#[cfg(all(unix, any(feature = "collector", feature = "receiver")))]
Expand Down
20 changes: 11 additions & 9 deletions crashtracker/src/receiver/entry_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ pub fn receiver_entry_point_stdin() -> anyhow::Result<()> {
Ok(())
}

pub async fn async_receiver_entry_point_unix_listener(
listener: &UnixListener,
) -> anyhow::Result<()> {
let (unix_stream, _) = listener.accept().await?;
let stream = BufReader::new(unix_stream);
receiver_entry_point(receiver_timeout(), stream).await
}

pub async fn async_receiver_entry_point_unix_socket(
socket_path: impl AsRef<str>,
one_shot: bool,
) -> anyhow::Result<()> {
let listener = get_unix_socket(socket_path)?;
let listener = get_receiver_unix_socket(socket_path)?;
loop {
let (unix_stream, _) = listener.accept().await?;
let stream = BufReader::new(unix_stream);
let res = receiver_entry_point(receiver_timeout(), stream).await;
let res = async_receiver_entry_point_unix_listener(&listener).await;
// TODO, should we log failures somewhere?
if one_shot {
return res;
Expand All @@ -48,11 +54,7 @@ pub fn receiver_entry_point_unix_socket(socket_path: impl AsRef<str>) -> anyhow:
// Dropping the stream closes it, allowing the collector to exit if it was waiting.
}

/*-----------------------------------------
| Helper Functions |
------------------------------------------*/

fn get_unix_socket(socket_path: impl AsRef<str>) -> anyhow::Result<UnixListener> {
pub fn get_receiver_unix_socket(socket_path: impl AsRef<str>) -> anyhow::Result<UnixListener> {
fn path_bind(socket_path: impl AsRef<str>) -> anyhow::Result<UnixListener> {
let socket_path = socket_path.as_ref();
if std::fs::metadata(socket_path).is_ok() {
Expand Down
4 changes: 2 additions & 2 deletions crashtracker/src/receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

mod entry_points;
pub use entry_points::{
async_receiver_entry_point_unix_socket, receiver_entry_point_stdin,
receiver_entry_point_unix_socket,
async_receiver_entry_point_unix_listener, async_receiver_entry_point_unix_socket,
get_receiver_unix_socket, receiver_entry_point_stdin, receiver_entry_point_unix_socket,
};
mod receive_report;

Expand Down
13 changes: 8 additions & 5 deletions sidecar/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ where
#[cfg(unix)]
tokio::spawn(async move {
let socket_path = crashtracker_unix_socket_path();
let _ = datadog_crashtracker::async_receiver_entry_point_unix_socket(
socket_path.to_str().unwrap_or_default(),
false,
)
.await;
let listener = datadog_crashtracker::get_receiver_unix_socket(socket_path);
loop {
if let Err(e) =
datadog_crashtracker::async_receiver_entry_point_unix_listener(&listener).await
{
tracing::warn!("Got error while receiving crash report: {e}");
}
}
});

// Init. Early, before we start listening.
Expand Down
4 changes: 3 additions & 1 deletion sidecar/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ pub(crate) fn enable_logging() -> anyhow::Result<()> {
let config = config::Config::get();
if !config.log_level.is_empty() {
let filter = MULTI_LOG_FILTER.add(config.log_level.clone());
unsafe { PERMANENT_MIN_LOG_LEVEL.replace(filter); } // SAFETY: initialized once
unsafe {
PERMANENT_MIN_LOG_LEVEL.replace(filter);
} // SAFETY: initialized once
}
MULTI_LOG_WRITER.add(config.log_method); // same than MULTI_LOG_FILTER

Expand Down

0 comments on commit 1440610

Please sign in to comment.