Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crashtracker] Enable dynamic updating of metadata and config at runtime #297

Merged
merged 21 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions crashtracker/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2023-Present Datadog, Inc.
#![cfg(unix)]

use crate::crash_handler::{register_crash_handlers, setup_receiver};

use super::{
counters::reset_counters,
crash_handler::{
register_crash_handlers, replace_receiver, restore_old_handlers, setup_receiver,
shutdown_receiver,
},
crash_handler::{replace_receiver, restore_old_handlers, shutdown_receiver},
};
use ddcommon::tag::Tag;
use ddcommon::Endpoint;
Expand Down Expand Up @@ -100,7 +99,7 @@ impl CrashtrackerConfiguration {
/// This function is not atomic. A crash during its execution may lead to
/// unexpected crash-handling behaviour.
pub fn shutdown_crash_handler() -> anyhow::Result<()> {
restore_old_handlers()?;
restore_old_handlers(false)?;
shutdown_receiver()?;
Ok(())
}
Expand Down Expand Up @@ -134,7 +133,7 @@ pub fn on_fork(
// https://man7.org/linux/man-pages/man2/sigaltstack.2.html

// See function level comment about why we do this.
replace_receiver(&config, &metadata)?;
replace_receiver(config, metadata)?;
Ok(())
}

Expand All @@ -154,8 +153,9 @@ pub fn init(
) -> anyhow::Result<()> {
// Setup the receiver first, so that if there is a crash detected it has
// somewhere to go.
setup_receiver(&config, &metadata)?;
register_crash_handlers(&config)?;
let create_alt_stack = config.create_alt_stack;
setup_receiver(config, metadata)?;
register_crash_handlers(create_alt_stack)?;
Ok(())
}

Expand All @@ -169,9 +169,11 @@ pub fn init(
// ./build-profiling-ffi /tmp/libdatadog
// mkdir /tmp/crashreports
// look in /tmp/crashreports for the crash reports and output files
// Commented out since `ignore` doesn't work in CI.
//#[test]
fn test_crash() {
use crate::begin_profiling_op;
use crate::update_metadata;
use chrono::Utc;
use ddcommon::parse_uri;

Expand Down Expand Up @@ -208,6 +210,16 @@ fn test_crash() {
);
init(config, metadata).expect("not to fail");
begin_profiling_op(crate::ProfilingOpTypes::CollectingSample).expect("Not to fail");

let tag = Tag::new("apple", "banana").expect("tag");
let metadata2 = CrashtrackerMetadata::new(
"libname".to_string(),
"version".to_string(),
"family".to_string(),
vec![tag],
);
update_metadata(metadata2).expect("metadata");

let p: *const u32 = std::ptr::null();
let q = unsafe { *p };
assert_eq!(q, 3);
Expand Down
12 changes: 8 additions & 4 deletions crashtracker/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2023-Present Datadog, Inc.

pub const DD_CRASHTRACK_BEGIN_CONFIG: &str = "DD_CRASHTRACK_BEGIN_CONFIG";
pub const DD_CRASHTRACK_BEGIN_COUNTERS: &str = "DD_CRASHTRACK_BEGIN_COUNTERS";
pub const DD_CRASHTRACK_BEGIN_FILE: &str = "DD_CRASHTRACK_BEGIN_FILE";
pub const DD_CRASHTRACK_BEGIN_METADATA: &str = "DD_CRASHTRACK_BEGIN_METADATA";
pub const DD_CRASHTRACK_BEGIN_SIGINFO: &str = "DD_CRASHTRACK_BEGIN_SIGINFO";
pub const DD_CRASHTRACK_BEGIN_STACKTRACE: &str = "DD_CRASHTRACK_BEGIN_STACKTRACE";
pub const DD_CRASHTRACK_DONE: &str = "DD_CRASHTRACK_DONE";
pub const DD_CRASHTRACK_END_CONFIG: &str = "DD_CRASHTRACK_END_CONFIG";
pub const DD_CRASHTRACK_END_COUNTERS: &str = "DD_CRASHTRACK_END_COUNTERS";
pub const DD_CRASHTRACK_END_FILE: &str = "DD_CRASHTRACK_END_FILE";
pub const DD_CRASHTRACK_END_STACKTRACE: &str = "DD_CRASHTRACK_END_STACKTRACE";
pub const DD_CRASHTRACK_END_METADATA: &str = "DD_CRASHTRACK_END_METADATA";
pub const DD_CRASHTRACK_END_SIGINFO: &str = "DD_CRASHTRACK_END_SIGINFO";
pub const DD_CRASHTRACK_BEGIN_COUNTERS: &str = "DD_CRASHTRACK_BEGIN_COUNTERS";
pub const DD_CRASHTRACK_END_COUNTERS: &str = "DD_CRASHTRACK_END_COUNTERS";
pub const DD_CRASHTRACK_DONE: &str = "DD_CRASHTRACK_DONE";
pub const DD_CRASHTRACK_END_STACKTRACE: &str = "DD_CRASHTRACK_END_STACKTRACE";
Loading
Loading