Skip to content

Commit

Permalink
[crashtracker] Remove profiling endpoint since we're using IT now (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsn authored May 1, 2024
1 parent 19f9976 commit 5683b74
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 137 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions LICENSE-3rdparty.yml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion crashtracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ blazesym = {git = "https://github.com/libbpf/blazesym.git", rev = "v0.2.0-alpha.
anyhow = "1.0"
backtrace = "0.3.69"
chrono = {version = "0.4", default-features = false, features = ["std", "clock", "serde"]}
datadog-profiling = { path = "../profiling"}
ddcommon = {path = "../ddcommon"}
hyper = {version = "0.14", features = ["client"], default-features = false}
libc = "0.2"
Expand Down
94 changes: 14 additions & 80 deletions crashtracker/src/crash_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use anyhow::Context;
#[cfg(unix)]
use blazesym::symbolize::{Process, Source, Symbolizer};
use chrono::{DateTime, Utc};
use datadog_profiling::exporter::{self, Tag};
use ddcommon::Endpoint;
use ddcommon::tag::Tag;
use serde::{Deserialize, Serialize};
use std::io::BufRead;
use std::time::Duration;
use std::{collections::HashMap, fs::File, io::BufReader};
use uuid::Uuid;

Expand Down Expand Up @@ -208,87 +206,23 @@ impl CrashInfo {
Ok(())
}

/// Package the CrashInfo as a json file `crash_info.json` associated with
/// an empty profile, and upload it to the profiling endpoint given in
/// `endpoint`.
/// SIGNAL SAFETY:
/// Uploading the data involve both allocation and synchronization and
/// should not be done inside a signal handler.
pub fn upload_to_dd(
&self,
endpoint: Endpoint,
timeout: Duration,
) -> anyhow::Result<hyper::Response<hyper::Body>> {
fn make_tag(key: &str, value: &str) -> anyhow::Result<Tag> {
match Tag::new(key, value) {
Ok(tag) => Ok(tag),
Err(e) => anyhow::bail!("{}", e),
pub fn upload_to_endpoint(&self, config: &CrashtrackerConfiguration) -> anyhow::Result<()> {
// If we're debugging to a file, dump the actual crashinfo into a json
if let Some(endpoint) = &config.endpoint {
if Some("file") == endpoint.url.scheme_str() {
self.to_file(
endpoint
.url
.path_and_query()
.ok_or_else(|| anyhow::format_err!("empty path for upload to file"))?
.as_str(),
)?;
}
}

let data = serde_json::to_vec(self)?;
let metadata = &self.metadata.as_ref().context("Missing metadata")?;

let is_crash_tag = make_tag("is_crash", "yes")?;
let tags = Some(
metadata
.tags
.iter()
.cloned()
.chain([is_crash_tag])
.collect(),
);
let time = Utc::now();
let crash_file = exporter::File {
name: "crash-info.json",
bytes: &data,
};
let exporter = exporter::ProfileExporter::new(
metadata.profiling_library_name.clone(),
metadata.profiling_library_version.clone(),
metadata.family.clone(),
tags,
endpoint,
)?;
let request = exporter.build(
time,
time,
&[crash_file],
&[],
None,
None,
None,
None,
timeout,
)?;
let response = exporter.send(request, None)?;
//TODO, do we need to wait a bit for the agent to finish upload?
Ok(response)
}

pub fn upload_to_endpoint(
&self,
endpoint: Endpoint,
timeout: Duration,
) -> anyhow::Result<Option<hyper::Response<hyper::Body>>> {
// Using scheme "file" currently fails:
// error trying to connect: Unsupported scheme file
// Instead, manually support it.
if Some("file") == endpoint.url.scheme_str() {
self.to_file(
endpoint
.url
.path_and_query()
.ok_or_else(|| anyhow::format_err!("empty path for upload to file"))?
.as_str(),
)?;
Ok(None)
} else {
Ok(Some(self.upload_to_dd(endpoint, timeout)?))
}
self.upload_to_telemetry(config)
}

pub fn upload_to_telemetry(&self, config: &CrashtrackerConfiguration) -> anyhow::Result<()> {
fn upload_to_telemetry(&self, config: &CrashtrackerConfiguration) -> anyhow::Result<()> {
if let Some(metadata) = &self.metadata {
if let Ok(uploader) = TelemetryCrashUploader::new(metadata, config) {
uploader.upload_to_telemetry(self, config.timeout)?;
Expand Down
19 changes: 2 additions & 17 deletions crashtracker/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use self::stacktrace::StackFrame;
use super::*;
use anyhow::Context;
use nix::unistd::getppid;
use std::time::Duration;

pub fn resolve_frames(
config: &CrashtrackerConfiguration,
Expand Down Expand Up @@ -36,26 +35,12 @@ pub fn receiver_entry_point() -> anyhow::Result<()> {
CrashReportStatus::NoCrash => Ok(()),
CrashReportStatus::CrashReport(config, mut crash_info) => {
resolve_frames(&config, &mut crash_info)?;

if let Some(endpoint) = &config.endpoint {
// TODO Experiment to see if 30 is the right number.
crash_info.upload_to_endpoint(endpoint.clone(), Duration::from_secs(30))?;
}
crash_info.upload_to_telemetry(&config)?;

Ok(())
crash_info.upload_to_endpoint(&config)
}
CrashReportStatus::PartialCrashReport(config, mut crash_info, stdin_state) => {
eprintln!("Failed to fully receive crash. Exit state was: {stdin_state:?}");
resolve_frames(&config, &mut crash_info)?;

if let Some(endpoint) = &config.endpoint {
// TODO Experiment to see if 30 is the right number.
crash_info.upload_to_endpoint(endpoint.clone(), Duration::from_secs(30))?;
}
crash_info.upload_to_telemetry(&config)?;

Ok(())
crash_info.upload_to_endpoint(&config)
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions examples/ffi/crashinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ int main(void) {
.tags = &tags,
};

// TODO: We should set more tags that are expected by telemetry
check_result(ddog_crashinfo_set_metadata(crashinfo.get(), metadata), "Failed to add metadata");
check_result(ddog_crashinfo_add_tag(crashinfo.get(), to_slice_c_char("best hockey team"),
to_slice_c_char("Habs")),
Expand All @@ -116,8 +117,11 @@ int main(void) {
check_result(ddog_crashinfo_set_timestamp(crashinfo.get(), 1568899800, 0),
"Failed to set timestamp");

auto endpoint = ddog_Endpoint_file(to_slice_c_char("file://tmp/test.txt"));
check_result(ddog_crashinfo_upload_to_endpoint(crashinfo.get(), endpoint, 1),
ddog_prof_CrashtrackerConfiguration config = {
.endpoint = ddog_Endpoint_file(to_slice_c_char("file://tmp/test")),
.timeout_secs = 1,
};

check_result(ddog_crashinfo_upload_to_endpoint(crashinfo.get(), config),
"Failed to export to file");
ddog_prof_Option_U32 opt;
}
32 changes: 4 additions & 28 deletions profiling-ffi/src/crashtracker/crash_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use crate::crashtracker::{
crashinfo_ptr_to_inner, option_from_char_slice, CrashInfo, CrashInfoNewResult,
CrashtrackerResult, StackFrame,
};
use crate::exporter::{self, ProfilingEndpoint};
use anyhow::Context;
use chrono::DateTime;
use ddcommon_ffi::{slice::AsBytes, CharSlice, Slice};
use std::time::Duration;

/// Create a new crashinfo, and returns an opaque reference to it.
/// # Safety
Expand Down Expand Up @@ -211,42 +209,20 @@ pub unsafe extern "C" fn ddog_crashinfo_set_timestamp_to_now(
.into()
}

/// Exports `crashinfo` to the Instrumentation Telemetry backend
///
/// # Safety
/// `crashinfo` must be a valid pointer to a `CrashInfo` object.
#[no_mangle]
#[must_use]
pub unsafe extern "C" fn ddog_crashinfo_upload_to_telemetry(
crashinfo: *mut CrashInfo,
config: CrashtrackerConfiguration,
) -> CrashtrackerResult {
(|| {
let crashinfo = crashinfo_ptr_to_inner(crashinfo)?;
let config = config.try_into()?;
crashinfo.upload_to_telemetry(&config)
})()
.context("ddog_crashinfo_upload_to_telemetry failed")
.into()
}

/// Exports `crashinfo` to the profiling backend at `endpoint`
/// Exports `crashinfo` to the backend at `endpoint`
/// Note that we support the "file://" endpoint for local file output.
/// # Safety
/// `crashinfo` must be a valid pointer to a `CrashInfo` object.
#[no_mangle]
#[must_use]
pub unsafe extern "C" fn ddog_crashinfo_upload_to_endpoint(
crashinfo: *mut CrashInfo,
endpoint: ProfilingEndpoint,
timeout_secs: u64,
config: CrashtrackerConfiguration,
) -> CrashtrackerResult {
(|| {
let crashinfo = crashinfo_ptr_to_inner(crashinfo)?;
let endpoint = exporter::try_to_endpoint(endpoint)?;
let timeout = Duration::from_secs(timeout_secs);
crashinfo.upload_to_endpoint(endpoint, timeout)?;
anyhow::Ok(())
let config = config.try_into()?;
crashinfo.upload_to_endpoint(&config)
})()
.context("ddog_crashinfo_upload_to_endpoint failed")
.into()
Expand Down

0 comments on commit 5683b74

Please sign in to comment.