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

Deduplicate Debugger diagnostics in sidecar #736

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions live-debugger-ffi/src/send_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub extern "C" fn ddog_create_exception_snapshot<'a>(
) -> *mut DebuggerCapture<'a> {
let snapshot = DebuggerPayload {
service: service.to_utf8_lossy(),
ddsource: "dd_debugger",
ddsource: Cow::Borrowed("dd_debugger"),
timestamp,
message: None,
debugger: DebuggerData::Snapshot(Snapshot {
Expand Down Expand Up @@ -159,7 +159,7 @@ pub extern "C" fn ddog_create_log_probe_snapshot<'a>(
) -> Box<DebuggerPayload<'a>> {
Box::new(DebuggerPayload {
service: service.to_utf8_lossy(),
ddsource: "dd_debugger",
ddsource: Cow::Borrowed("dd_debugger"),
timestamp,
message: message.map(|m| m.to_utf8_lossy()),
debugger: DebuggerData::Snapshot(Snapshot {
Expand Down Expand Up @@ -334,7 +334,7 @@ pub extern "C" fn ddog_evaluation_error_snapshot<'a>(
) -> Box<DebuggerPayload<'a>> {
Box::new(DebuggerPayload {
service: service.to_utf8_lossy(),
ddsource: "dd_debugger",
ddsource: Cow::Borrowed("dd_debugger"),
timestamp,
message: Some(Cow::Owned(format!(
"Evaluation errors for probe id {}",
Expand Down Expand Up @@ -397,7 +397,7 @@ pub fn ddog_debugger_diagnostics_create_unboxed<'a>(
}
DebuggerPayload {
service,
ddsource: "dd_debugger",
ddsource: Cow::Borrowed("dd_debugger"),
timestamp,
message: Some(if probe.diagnostic_msg.len() > 0 {
probe.diagnostic_msg.to_utf8_lossy()
Expand Down
28 changes: 14 additions & 14 deletions live-debugger/src/debugger_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::collections::HashMap;

#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct DebuggerPayload<'a> {
pub service: Cow<'a, str>,
pub ddsource: &'static str,
pub ddsource: Cow<'static, str>,
pub timestamp: u64,
pub debugger: DebuggerData<'a>,
pub message: Option<Cow<'a, str>>,
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[allow(clippy::large_enum_variant)]
pub enum DebuggerData<'a> {
Snapshot(Snapshot<'a>),
Diagnostics(Diagnostics<'a>),
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct ProbeMetadataLocation<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub method: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#type: Option<Cow<'a, str>>,
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct ProbeMetadata<'a> {
pub id: Cow<'a, str>,
pub location: ProbeMetadataLocation<'a>,
Expand All @@ -42,13 +42,13 @@ pub struct SnapshotEvaluationError {
pub message: String,
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct SnapshotStackFrame {
pub expr: String,
pub message: String,
}

#[derive(Default, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Snapshot<'a> {
pub language: Cow<'a, str>,
Expand All @@ -70,7 +70,7 @@ pub struct Snapshot<'a> {
pub stack: Vec<SnapshotStackFrame>,
}

#[derive(Default, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Captures<'a> {
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub lines: HashMap<u32, Capture<'a>>,
Expand All @@ -81,7 +81,7 @@ pub struct Captures<'a> {
}

pub type Fields<'a> = HashMap<Cow<'a, str>, Value<'a>>;
#[derive(Default, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Capture<'a> {
#[serde(skip_serializing_if = "HashMap::is_empty")]
#[serde(rename = "staticFields")]
Expand All @@ -94,10 +94,10 @@ pub struct Capture<'a> {
pub throwable: Option<Value<'a>>,
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct Entry<'a>(pub Value<'a>, pub Value<'a>);

#[derive(Default, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Value<'a> {
pub r#type: Cow<'a, str>,
Expand All @@ -119,7 +119,7 @@ pub struct Value<'a> {
pub size: Option<Cow<'a, str>>,
}

#[derive(Default, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Diagnostics<'a> {
pub probe_id: Cow<'a, str>,
Expand All @@ -134,7 +134,7 @@ pub struct Diagnostics<'a> {
pub details: Option<Cow<'a, str>>,
}

#[derive(Serialize, Deserialize, Default, Copy, Clone)]
#[derive(Serialize, Deserialize, Debug, Default, Copy, Clone, Eq, PartialEq)]
#[serde(rename_all = "UPPERCASE")]
#[repr(C)]
pub enum ProbeStatus {
Expand All @@ -147,7 +147,7 @@ pub enum ProbeStatus {
Warning,
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DiagnosticsError<'a> {
pub r#type: Cow<'a, str>,
Expand Down
19 changes: 19 additions & 0 deletions sidecar-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,25 @@ pub unsafe extern "C" fn ddog_sidecar_send_debugger_datum(
ddog_sidecar_send_debugger_data(transport, instance_id, queue_id, vec![*payload])
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
#[allow(improper_ctypes_definitions)] // DebuggerPayload is just a pointer, we hide its internals
pub unsafe extern "C" fn ddog_sidecar_send_debugger_diagnostics(
transport: &mut Box<SidecarTransport>,
instance_id: &InstanceId,
queue_id: QueueId,
diagnostics_payload: DebuggerPayload,
) -> MaybeError {
try_c!(blocking::send_debugger_diagnostics(
transport,
instance_id,
queue_id,
diagnostics_payload,
));

MaybeError::None
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn ddog_sidecar_set_remote_config_data(
Expand Down
29 changes: 28 additions & 1 deletion sidecar/src/service/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::{
};
use datadog_ipc::platform::{Channel, FileBackedHandle, ShmHandle};
use datadog_ipc::transport::blocking::BlockingTransport;
use datadog_live_debugger::debugger_defs::DebuggerPayload;
use datadog_live_debugger::sender::DebuggerType;
use ddcommon::tag::Tag;
use dogstatsd_client::DogStatsDActionOwned;
Expand Down Expand Up @@ -318,7 +319,7 @@ pub fn send_debugger_data_shm_vec(
transport: &mut SidecarTransport,
instance_id: &InstanceId,
queue_id: QueueId,
payloads: Vec<datadog_live_debugger::debugger_defs::DebuggerPayload>,
payloads: Vec<DebuggerPayload>,
) -> anyhow::Result<()> {
if payloads.is_empty() {
return Ok(());
Expand Down Expand Up @@ -352,6 +353,32 @@ pub fn send_debugger_data_shm_vec(
)?)
}

/// Submits debugger diagnostics.
///
/// # Arguments
///
/// * `transport` - The transport used for communication.
/// * `instance_id` - The ID of the instance.
/// * `queue_id` - The unique identifier for the trace context.
/// * `handle` - The handle to the shared memory.
/// * `diagnostics_payload` - The diagnostics data to send.
///
/// # Returns
///
/// An `io::Result<()>` indicating the result of the operation.
pub fn send_debugger_diagnostics(
transport: &mut SidecarTransport,
instance_id: &InstanceId,
queue_id: QueueId,
diagnostics_payload: DebuggerPayload,
) -> io::Result<()> {
transport.send(SidecarInterfaceRequest::SendDebuggerDiagnostics {
instance_id: instance_id.clone(),
queue_id,
diagnostics_payload: serde_json::to_vec(&diagnostics_payload)?,
})
}

/// Acquire an exception hash rate limiter
///
/// # Arguments
Expand Down
Loading
Loading