Skip to content
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
2 changes: 1 addition & 1 deletion datadog-live-debugger-ffi/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub extern "C" fn ddog_live_debugger_spawn_sender(

let (tx, mailbox) = mpsc::channel(5000);
let mut config = Config::default();
try_c!(config.set_endpoint(endpoint.clone(), endpoint.clone()));
try_c!(config.set_endpoint(endpoint.clone()));
let config = Arc::new(config);

*handle = Box::into_raw(Box::new(SenderHandle {
Expand Down
147 changes: 116 additions & 31 deletions datadog-live-debugger/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ use std::str::FromStr;
use tokio::task::JoinHandle;
use uuid::Uuid;

pub const PROD_LOGS_INTAKE_SUBDOMAIN: &str = "http-intake.logs";
pub const PROD_DIAGNOSTICS_INTAKE_SUBDOMAIN: &str = "debugger-intake";

const DIRECT_DEBUGGER_LOGS_URL_PATH: &str = "/api/v2/logs";
const DIRECT_DEBUGGER_DIAGNOSTICS_URL_PATH: &str = "/api/v2/debugger";
const AGENT_DEBUGGER_LOGS_URL_PATH: &str = "/debugger/v1/input";
const AGENT_DEBUGGER_SNAPSHOTS_URL_PATH: &str = "/debugger/v2/input";
const AGENT_DEBUGGER_DIAGNOSTICS_URL_PATH: &str = "/debugger/v1/diagnostics";

Expand All @@ -36,39 +33,25 @@ pub struct Config {
}

impl Config {
pub fn set_endpoint(
&mut self,
mut logs_endpoint: Endpoint,
mut diagnostics_endpoint: Endpoint,
) -> anyhow::Result<()> {
let mut snapshots_endpoint = if diagnostics_endpoint.api_key.is_some() {
diagnostics_endpoint.clone()
} else {
logs_endpoint.clone()
};
pub fn set_endpoint(&mut self, mut diagnostics_endpoint: Endpoint) -> anyhow::Result<()> {
let mut logs_endpoint = diagnostics_endpoint.clone();
let mut snapshots_endpoint = diagnostics_endpoint.clone();

let mut logs_uri_parts = logs_endpoint.url.into_parts();
let mut snapshots_uri_parts = snapshots_endpoint.url.into_parts();
let mut diagnostics_uri_parts = diagnostics_endpoint.url.into_parts();

#[allow(clippy::unwrap_used)]
if logs_uri_parts.scheme.is_some()
&& logs_uri_parts.scheme.as_ref().unwrap().as_str() != "file"
if diagnostics_uri_parts.scheme.is_some()
&& diagnostics_uri_parts.scheme.as_ref().unwrap().as_str() != "file"
{
logs_uri_parts.path_and_query = Some(PathAndQuery::from_static(
if logs_endpoint.api_key.is_some() {
DIRECT_DEBUGGER_LOGS_URL_PATH
} else {
AGENT_DEBUGGER_LOGS_URL_PATH
},
));
snapshots_uri_parts.path_and_query = Some(PathAndQuery::from_static(
if snapshots_endpoint.api_key.is_some() {
DIRECT_DEBUGGER_DIAGNOSTICS_URL_PATH
} else {
AGENT_DEBUGGER_SNAPSHOTS_URL_PATH
},
));
let v2_path = PathAndQuery::from_static(if diagnostics_endpoint.api_key.is_some() {
DIRECT_DEBUGGER_DIAGNOSTICS_URL_PATH
} else {
AGENT_DEBUGGER_SNAPSHOTS_URL_PATH
});
logs_uri_parts.path_and_query = Some(v2_path.clone());
snapshots_uri_parts.path_and_query = Some(v2_path);
diagnostics_uri_parts.path_and_query = Some(PathAndQuery::from_static(
if diagnostics_endpoint.api_key.is_some() {
DIRECT_DEBUGGER_DIAGNOSTICS_URL_PATH
Expand All @@ -87,12 +70,13 @@ impl Config {
Ok(())
}

pub fn without_dedicated_snapshots_endpoint(&mut self) {
pub fn downgrade_to_diagnostics_endpoint(&mut self) {
self.snapshots_endpoint = self.diagnostics_endpoint.clone();
self.logs_endpoint = self.diagnostics_endpoint.clone();
}
}

pub fn agent_info_supports_dedicated_snapshots_endpoint(info: &AgentInfoStruct) -> bool {
pub fn agent_info_supports_debugger_v2_endpoint(info: &AgentInfoStruct) -> bool {
info.endpoints
.as_ref()
.map(|endpoints| {
Expand Down Expand Up @@ -312,3 +296,104 @@ pub async fn send(
pub fn generate_new_id() -> Uuid {
Uuid::new_v4()
}

#[cfg(test)]
mod tests {
use super::*;
use std::borrow::Cow;

fn agent_endpoint() -> Endpoint {
Endpoint::from_slice("http://localhost:8126")
}

fn direct_endpoint() -> Endpoint {
Endpoint {
url: Uri::from_static("https://debugger-intake.datadoghq.com"),
api_key: Some(Cow::Borrowed("test-api-key")),
..Default::default()
}
}

fn endpoint_path(endpoint: &Option<Endpoint>) -> &str {
endpoint
.as_ref()
.unwrap()
.url
.path_and_query()
.unwrap()
.as_str()
}

#[test]
fn test_set_endpoint_agent_mode() {
let mut config = Config::default();
config.set_endpoint(agent_endpoint()).unwrap();

assert_eq!(endpoint_path(&config.logs_endpoint), "/debugger/v2/input");
assert_eq!(
endpoint_path(&config.snapshots_endpoint),
"/debugger/v2/input"
);
assert_eq!(
endpoint_path(&config.diagnostics_endpoint),
"/debugger/v1/diagnostics"
);
}

#[test]
fn test_set_endpoint_direct_mode() {
let mut config = Config::default();
config.set_endpoint(direct_endpoint()).unwrap();

assert_eq!(endpoint_path(&config.logs_endpoint), "/api/v2/debugger");
assert_eq!(
endpoint_path(&config.snapshots_endpoint),
"/api/v2/debugger"
);
assert_eq!(
endpoint_path(&config.diagnostics_endpoint),
"/api/v2/debugger"
);
}

#[test]
fn test_downgrade_to_diagnostics_endpoint() {
let mut config = Config::default();
config.set_endpoint(agent_endpoint()).unwrap();
config.downgrade_to_diagnostics_endpoint();

assert_eq!(
endpoint_path(&config.logs_endpoint),
"/debugger/v1/diagnostics"
);
assert_eq!(
endpoint_path(&config.snapshots_endpoint),
"/debugger/v1/diagnostics"
);
assert_eq!(
endpoint_path(&config.diagnostics_endpoint),
"/debugger/v1/diagnostics"
);
}

#[test]
fn test_agent_info_supports_debugger_v2_endpoint() {
let with_v2 = AgentInfoStruct {
endpoints: Some(vec!["/debugger/v2/input".to_string()]),
..Default::default()
};
assert!(agent_info_supports_debugger_v2_endpoint(&with_v2));

let without_v2 = AgentInfoStruct {
endpoints: Some(vec!["/debugger/v1/diagnostics".to_string()]),
..Default::default()
};
assert!(!agent_info_supports_debugger_v2_endpoint(&without_v2));

let no_endpoints = AgentInfoStruct {
endpoints: None,
..Default::default()
};
assert!(!agent_info_supports_debugger_v2_endpoint(&no_endpoints));
}
}
14 changes: 4 additions & 10 deletions datadog-sidecar/src/service/sidecar_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ use crate::service::tracing::trace_flusher::TraceFlusherStats;
use crate::tokio_util::run_or_spawn_shared;
use datadog_ipc::platform::FileBackedHandle;
use datadog_ipc::tarpc::server::{Channel, InFlightRequest};
use datadog_live_debugger::sender::{
agent_info_supports_dedicated_snapshots_endpoint, DebuggerType,
};
use datadog_live_debugger::sender::{agent_info_supports_debugger_v2_endpoint, DebuggerType};
use datadog_remote_config::fetch::{ConfigInvariants, ConfigOptions, MultiTargetStats};
use libdd_common::tag::Tag;
use libdd_dogstatsd_client::{new, DogStatsDActionOwned};
Expand Down Expand Up @@ -594,24 +592,20 @@ impl SidecarInterface for SidecarServer {
*dogstatsd = d;
});
session.modify_debugger_config(|cfg| {
let logs_endpoint = get_product_endpoint(
datadog_live_debugger::sender::PROD_LOGS_INTAKE_SUBDOMAIN,
&config.endpoint,
);
let diagnostics_endpoint = get_product_endpoint(
datadog_live_debugger::sender::PROD_DIAGNOSTICS_INTAKE_SUBDOMAIN,
&config.endpoint,
);
cfg.set_endpoint(logs_endpoint, diagnostics_endpoint).ok();
cfg.set_endpoint(diagnostics_endpoint).ok();
});
if config.endpoint.api_key.is_none() {
// no agent info if agentless
let agent_info = self.agent_infos.query_for(config.endpoint.clone());
let session_info = session.clone();
run_or_spawn_shared(agent_info.get(), move |info| {
if !agent_info_supports_dedicated_snapshots_endpoint(info) {
if !agent_info_supports_debugger_v2_endpoint(info) {
session_info.modify_debugger_config(|cfg| {
cfg.without_dedicated_snapshots_endpoint();
cfg.downgrade_to_diagnostics_endpoint();
});
}
});
Expand Down
Loading