From 60f33e99030533b7e6b9c138770e4364c1298b9b Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Fri, 11 Jul 2025 09:34:58 -0400 Subject: [PATCH 1/7] build(prof): bump patch versions, drop indexmap Indexmap is no longer used. --- Cargo.lock | 59 ++++++++++++++++++++++---------------------- profiling/Cargo.toml | 1 - 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 24bd9356376..3037588fec6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,15 +19,15 @@ checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "ahash" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" dependencies = [ "cfg-if", - "getrandom 0.2.15", + "getrandom 0.3.2", "once_cell", "version_check 0.9.5", - "zerocopy 0.7.35", + "zerocopy 0.8.24", ] [[package]] @@ -118,9 +118,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.95" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "arc-swap" @@ -912,9 +912,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "cfg_aliases" @@ -924,9 +924,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.39" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "android-tzdata", "iana-time-zone", @@ -934,7 +934,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.6", + "windows-link", ] [[package]] @@ -1224,9 +1224,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.14" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471" +checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" dependencies = [ "crossbeam-utils", ] @@ -1601,7 +1601,6 @@ dependencies = [ "datadog-profiling", "ddcommon 18.0.0", "env_logger 0.11.6", - "indexmap 2.7.1", "lazy_static", "libc 0.2.173", "log", @@ -1612,7 +1611,7 @@ dependencies = [ "rustc-hash 1.1.0", "rustc_version", "serde_json", - "thiserror 2.0.11", + "thiserror 2.0.12", "tracing", "tracing-subscriber", "uuid", @@ -2993,16 +2992,18 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.10" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +checksum = "7f66d5bd4c6f02bf0542fad85d626775bab9258cf795a4256dcaf3161114d1df" dependencies = [ "bytes", "futures-channel", + "futures-core", "futures-util", "http 1.2.0", "http-body 1.0.1", "hyper 1.6.0", + "libc 0.2.173", "pin-project-lite", "socket2", "tokio", @@ -4141,7 +4142,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "059a34f111a9dee2ce1ac2826a68b24601c4298cfeb1a587c3cb493d5ab46f52" dependencies = [ - "libc 0.1.12", + "libc 0.2.173", "nix", ] @@ -4369,7 +4370,7 @@ dependencies = [ "rustc-hash 2.1.1", "rustls", "socket2", - "thiserror 2.0.11", + "thiserror 2.0.12", "tokio", "tracing", "web-time", @@ -4389,7 +4390,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror 2.0.11", + "thiserror 2.0.12", "tinyvec", "tracing", "web-time", @@ -5284,9 +5285,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.8" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" dependencies = [ "libc 0.2.173", "windows-sys 0.52.0", @@ -5602,11 +5603,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.11" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" dependencies = [ - "thiserror-impl 2.0.11", + "thiserror-impl 2.0.12", ] [[package]] @@ -5622,9 +5623,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.11" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", @@ -6474,9 +6475,9 @@ dependencies = [ [[package]] name = "windows-result" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" dependencies = [ "windows-link", ] diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index a3daa239213..788f3c2d4a8 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -24,7 +24,6 @@ datadog-profiling = { git = "https://github.com/DataDog/libdatadog", tag = "v18. ddcommon = { git = "https://github.com/DataDog/libdatadog", tag = "v18.0.0" } datadog-library-config-ffi = { git = "https://github.com/DataDog/libdatadog", tag = "v18.0.0" } env_logger = { version = "0.11", default-features = false } -indexmap = { version = "2.2" } lazy_static = { version = "1.4" } libc = "0.2" # TRACE set to max to support runtime configuration. From 77aad06fd7c6bd83e990ac4a76bbd0f01dd77f65 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Fri, 11 Jul 2025 09:56:04 -0400 Subject: [PATCH 2/7] feat(prof): use reqwest to send profiles to agent --- Cargo.lock | 227 +++++++++++++++++++++++++++- profiling/Cargo.toml | 1 + profiling/src/profiling/uploader.rs | 118 +++++++++++---- 3 files changed, 311 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3037588fec6..62b03107d96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1608,6 +1608,7 @@ dependencies = [ "perfcnt", "rand 0.8.5", "rand_distr", + "reqwest 0.12.22", "rustc-hash 1.1.0", "rustc_version", "serde_json", @@ -2326,6 +2327,21 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2990,12 +3006,29 @@ dependencies = [ "tower-service", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.6.0", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + [[package]] name = "hyper-util" version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f66d5bd4c6f02bf0542fad85d626775bab9258cf795a4256dcaf3161114d1df" dependencies = [ + "base64 0.22.1", "bytes", "futures-channel", "futures-core", @@ -3003,12 +3036,16 @@ dependencies = [ "http 1.2.0", "http-body 1.0.1", "hyper 1.6.0", + "ipnet", "libc 0.2.173", + "percent-encoding", "pin-project-lite", "socket2", + "system-configuration", "tokio", "tower-service", "tracing", + "windows-registry 0.5.2", ] [[package]] @@ -3251,6 +3288,16 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" +[[package]] +name = "iri-string" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc5ebe9c3a1a7a5127f920a418f7585e9e758e911d0466ed004f393b0e380b2" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "is-terminal" version = "0.4.13" @@ -3633,6 +3680,23 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "native-tls" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" +dependencies = [ + "libc 0.2.173", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework 2.11.1", + "security-framework-sys", + "tempfile", +] + [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -3770,12 +3834,50 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" +[[package]] +name = "openssl" +version = "0.10.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8" +dependencies = [ + "bitflags 2.8.0", + "cfg-if", + "foreign-types", + "libc 0.2.173", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-sys" +version = "0.9.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571" +dependencies = [ + "cc", + "libc 0.2.173", + "pkg-config", + "vcpkg", +] + [[package]] name = "opentelemetry" version = "0.17.0" @@ -4716,7 +4818,49 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "webpki-roots", - "windows-registry", + "windows-registry 0.4.0", +] + +[[package]] +name = "reqwest" +version = "0.12.22" +source = "git+https://github.com/seanmonstar/reqwest.git?branch=uds#3fb061f3bdf84d1b7c385931b6947c277fa487a4" +dependencies = [ + "base64 0.22.1", + "bytes", + "encoding_rs", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http 1.2.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.6.0", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "js-sys", + "log", + "mime", + "mime_guess", + "native-tls", + "percent-encoding", + "pin-project-lite", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-native-tls", + "tower 0.5.2", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", ] [[package]] @@ -5446,6 +5590,27 @@ dependencies = [ "libc 0.2.173", ] +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags 2.8.0", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc 0.2.173", +] + [[package]] name = "target-triple" version = "0.1.4" @@ -5581,7 +5746,7 @@ dependencies = [ "memchr", "parse-display", "pin-project-lite", - "reqwest", + "reqwest 0.12.15", "serde", "serde_json", "serde_with", @@ -5783,6 +5948,16 @@ dependencies = [ "syn 2.0.96", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.26.1" @@ -5946,6 +6121,24 @@ dependencies = [ "tower-service", ] +[[package]] +name = "tower-http" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" +dependencies = [ + "bitflags 2.8.0", + "bytes", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", + "iri-string", + "pin-project-lite", + "tower 0.5.2", + "tower-layer", + "tower-service", +] + [[package]] name = "tower-layer" version = "0.3.3" @@ -6176,6 +6369,12 @@ dependencies = [ "ryu", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.1.5" @@ -6430,7 +6629,7 @@ dependencies = [ "windows-implement", "windows-interface", "windows-result", - "windows-strings", + "windows-strings 0.3.1", "windows-targets 0.53.0", ] @@ -6469,10 +6668,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" dependencies = [ "windows-result", - "windows-strings", + "windows-strings 0.3.1", "windows-targets 0.53.0", ] +[[package]] +name = "windows-registry" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3bab093bdd303a1240bb99b8aba8ea8a69ee19d34c9e2ef9594e708a4878820" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings 0.4.2", +] + [[package]] name = "windows-result" version = "0.3.4" @@ -6491,6 +6701,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.42.0" diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index 788f3c2d4a8..0832e1e43c0 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -32,6 +32,7 @@ once_cell = { version = "1.12" } serde_json = {version = "1.0"} rand = { version = "0.8.5" } rand_distr = { version = "0.4.3" } +reqwest = { git = "https://github.com/seanmonstar/reqwest.git", branch = "uds", features = ["blocking", "multipart"] } rustc-hash = "1.1.0" thiserror = "2" tracing = { version = "0.1", optional = true } diff --git a/profiling/src/profiling/uploader.rs b/profiling/src/profiling/uploader.rs index 619f989d821..958ae838020 100644 --- a/profiling/src/profiling/uploader.rs +++ b/profiling/src/profiling/uploader.rs @@ -1,19 +1,22 @@ -#[cfg(feature = "allocation_profiling")] -use crate::allocation::{ALLOCATION_PROFILING_COUNT, ALLOCATION_PROFILING_SIZE}; use crate::config::AgentEndpoint; -#[cfg(feature = "exception_profiling")] -use crate::exception::EXCEPTION_PROFILING_EXCEPTION_COUNT; use crate::profiling::{UploadMessage, UploadRequest}; use crate::{PROFILER_NAME_STR, PROFILER_VERSION_STR}; use chrono::{DateTime, Utc}; use crossbeam_channel::{select, Receiver}; -use ddcommon::Endpoint; -use log::{debug, info, warn}; +use log::{info, warn}; +use reqwest::blocking::{multipart, Client}; +use reqwest::header::{HeaderMap, HeaderValue}; use serde_json::json; use std::borrow::Cow; use std::str; use std::sync::{Arc, Barrier}; +#[cfg(feature = "allocation_profiling")] +use crate::allocation::{ALLOCATION_PROFILING_COUNT, ALLOCATION_PROFILING_SIZE}; + +#[cfg(feature = "exception_profiling")] +use crate::exception::EXCEPTION_PROFILING_EXCEPTION_COUNT; + #[cfg(any( feature = "exception_profiling", feature = "allocation_profiling", @@ -84,36 +87,89 @@ impl Uploader { let index = message.index; let profile = message.profile; - let profiling_library_name: &str = &PROFILER_NAME_STR; - let profiling_library_version: &str = &PROFILER_VERSION_STR; - let agent_endpoint = &self.endpoint; - let endpoint = Endpoint::try_from(agent_endpoint)?; + // Serialize profile as compressed pprof + let serialized = + profile.serialize_into_compressed_pprof(Some(message.end_time), message.duration)?; + // Prepare multipart form + let mut form = multipart::Form::new().part( + "profile.pprof", + multipart::Part::bytes(serialized.buffer) + .file_name("profile.pprof") + .mime_str("application/octet-stream")?, + ); + + // Add event metadata as JSON let tags = Some(Arc::unwrap_or_clone(index.tags)); - let mut exporter = datadog_profiling::exporter::ProfileExporter::new( - profiling_library_name, - profiling_library_version, - "php", - tags, - endpoint, - )?; + let event_json = serde_json::to_string(&json!({ + "tags_profiler": tags, + "internal": Self::create_internal_metadata(), + "info": self.create_profiler_info(), + }))?; + form = form.part( + "event", + multipart::Part::text(event_json) + .file_name("event.json") + .mime_str("application/json")?, + ); - let serialized = - profile.serialize_into_compressed_pprof(Some(message.end_time), message.duration)?; - exporter.set_timeout(10000); // 10 seconds in milliseconds - let request = exporter.build( - serialized, - &[], - &[], - None, - Self::create_internal_metadata(), - self.create_profiler_info(), - )?; - debug!("Sending profile to: {agent_endpoint}"); - let result = exporter.send(request, None)?; - Ok(result.status().as_u16()) + // Build headers + let mut headers = HeaderMap::new(); + headers.insert("Connection", HeaderValue::from_static("close")); + headers.insert( + "DD-EVP-ORIGIN", + HeaderValue::from_static(&PROFILER_NAME_STR), + ); + headers.insert( + "DD-EVP-ORIGIN-VERSION", + HeaderValue::from_static(&PROFILER_VERSION_STR), + ); + + // Send request + let client = Client::new(); + let endpoint_url = self.endpoint.to_string(); // Adjust as needed + let response = client + .post(&endpoint_url) + .headers(headers) + .multipart(form) + .timeout(std::time::Duration::from_millis(10000)) + .send()?; + + Ok(response.status().as_u16()) } + // fn upload(&self, message: Box) -> anyhow::Result { + // use ddcommon::Endpoint; + // let index = message.index; + // let profile = message.profile; + // + // let profiling_library_name: &str = &PROFILER_NAME_STR; + // let profiling_library_version: &str = &PROFILER_VERSION_STR; + // let agent_endpoint = &self.endpoint; + // let endpoint = Endpoint::try_from(agent_endpoint)?; + // + // let tags = Some(Arc::unwrap_or_clone(index.tags)); + // let mut exporter = datadog_profiling::exporter::ProfileExporter::new( + // profiling_library_name, + // profiling_library_version, + // "php", + // tags, + // endpoint, + // )?; + // exporter.set_timeout(10000); // 10 seconds in milliseconds + // let request = exporter.build( + // serialized, + // &[], + // &[], + // None, + // Self::create_internal_metadata(), + // self.create_profiler_info(), + // )?; + // debug!("Sending profile to: {agent_endpoint}"); + // let result = exporter.send(request, None)?; + // Ok(result.status().as_u16()) + // } + pub fn run(self) { /* Safety: Called from Profiling::new, which is after config is * initialized, and before it's destroyed in mshutdown. From da9487aa16041166be6909a9f4cebe661fb46869 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Fri, 11 Jul 2025 10:19:22 -0400 Subject: [PATCH 3/7] feat(prof): switch to UDS --- Cargo.lock | 18 ++++++++++++++++-- profiling/Cargo.toml | 1 + profiling/src/profiling/uploader.rs | 27 ++++++++++++++++++--------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62b03107d96..91f8ab3ba8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1613,6 +1613,7 @@ dependencies = [ "rustc_version", "serde_json", "thiserror 2.0.12", + "tokio", "tracing", "tracing-subscriber", "uuid", @@ -3270,6 +3271,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "io-uring" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" +dependencies = [ + "bitflags 2.8.0", + "cfg-if", + "libc 0.2.173", +] + [[package]] name = "ipconfig" version = "0.3.2" @@ -5920,17 +5932,19 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.43.0" +version = "1.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" +checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" dependencies = [ "backtrace", "bytes", + "io-uring", "libc 0.2.173", "mio", "parking_lot", "pin-project-lite", "signal-hook-registry", + "slab", "socket2", "tokio-macros", "tracing", diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index 0832e1e43c0..3c7e165ff4d 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -35,6 +35,7 @@ rand_distr = { version = "0.4.3" } reqwest = { git = "https://github.com/seanmonstar/reqwest.git", branch = "uds", features = ["blocking", "multipart"] } rustc-hash = "1.1.0" thiserror = "2" +tokio = "1.46" tracing = { version = "0.1", optional = true } uuid = { version = "1.0", features = ["v4"] } diff --git a/profiling/src/profiling/uploader.rs b/profiling/src/profiling/uploader.rs index 958ae838020..05888deb555 100644 --- a/profiling/src/profiling/uploader.rs +++ b/profiling/src/profiling/uploader.rs @@ -4,8 +4,8 @@ use crate::{PROFILER_NAME_STR, PROFILER_VERSION_STR}; use chrono::{DateTime, Utc}; use crossbeam_channel::{select, Receiver}; use log::{info, warn}; -use reqwest::blocking::{multipart, Client}; use reqwest::header::{HeaderMap, HeaderValue}; +use reqwest::{multipart, ClientBuilder}; use serde_json::json; use std::borrow::Cow; use std::str; @@ -126,14 +126,23 @@ impl Uploader { ); // Send request - let client = Client::new(); - let endpoint_url = self.endpoint.to_string(); // Adjust as needed - let response = client - .post(&endpoint_url) - .headers(headers) - .multipart(form) - .timeout(std::time::Duration::from_millis(10000)) - .send()?; + let client = ClientBuilder::new().timeout(std::time::Duration::from_millis(10000)); + // Handle UDS + let client = match &self.endpoint { + AgentEndpoint::Socket(path) => client.unix_socket(path.clone()), + _ => client, + }; + + let rt = tokio::runtime::Builder::new_current_thread().build()?; + let client = client.build()?; + let response = rt.block_on(async { + client + .post(self.endpoint.to_string()) + .headers(headers) + .multipart(form) + .send() + .await + })?; Ok(response.status().as_u16()) } From 25d0c84599829bcd3e1bff7e14e18614081f9caf Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Fri, 11 Jul 2025 11:25:01 -0400 Subject: [PATCH 4/7] fix(prof): enable IO & time on tokio runtime --- profiling/src/profiling/uploader.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/profiling/src/profiling/uploader.rs b/profiling/src/profiling/uploader.rs index 05888deb555..ba173ac38e6 100644 --- a/profiling/src/profiling/uploader.rs +++ b/profiling/src/profiling/uploader.rs @@ -133,7 +133,10 @@ impl Uploader { _ => client, }; - let rt = tokio::runtime::Builder::new_current_thread().build()?; + let rt = tokio::runtime::Builder::new_current_thread() + .enable_io() + .enable_time() + .build()?; let client = client.build()?; let response = rt.block_on(async { client From c658472b39db00405a7235550c835d03433e3332 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Mon, 14 Jul 2025 10:12:00 -0600 Subject: [PATCH 5/7] refactor: move back to blocking now that upstream supports it --- Cargo.lock | 3 +-- profiling/Cargo.toml | 3 +-- profiling/src/profiling/uploader.rs | 33 +++++++++++------------------ 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91f8ab3ba8d..eb5232d343f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1613,7 +1613,6 @@ dependencies = [ "rustc_version", "serde_json", "thiserror 2.0.12", - "tokio", "tracing", "tracing-subscriber", "uuid", @@ -4836,7 +4835,7 @@ dependencies = [ [[package]] name = "reqwest" version = "0.12.22" -source = "git+https://github.com/seanmonstar/reqwest.git?branch=uds#3fb061f3bdf84d1b7c385931b6947c277fa487a4" +source = "git+https://github.com/seanmonstar/reqwest.git?rev=10ad5afa5985c9ce8f486cefa27e258a3e925f8b#10ad5afa5985c9ce8f486cefa27e258a3e925f8b" dependencies = [ "base64 0.22.1", "bytes", diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index 3c7e165ff4d..f1b084620d5 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -32,10 +32,9 @@ once_cell = { version = "1.12" } serde_json = {version = "1.0"} rand = { version = "0.8.5" } rand_distr = { version = "0.4.3" } -reqwest = { git = "https://github.com/seanmonstar/reqwest.git", branch = "uds", features = ["blocking", "multipart"] } +reqwest = { git = "https://github.com/seanmonstar/reqwest.git", rev = "10ad5afa5985c9ce8f486cefa27e258a3e925f8b", features = ["blocking", "multipart"] } rustc-hash = "1.1.0" thiserror = "2" -tokio = "1.46" tracing = { version = "0.1", optional = true } uuid = { version = "1.0", features = ["v4"] } diff --git a/profiling/src/profiling/uploader.rs b/profiling/src/profiling/uploader.rs index ba173ac38e6..1009e3e37c6 100644 --- a/profiling/src/profiling/uploader.rs +++ b/profiling/src/profiling/uploader.rs @@ -4,8 +4,8 @@ use crate::{PROFILER_NAME_STR, PROFILER_VERSION_STR}; use chrono::{DateTime, Utc}; use crossbeam_channel::{select, Receiver}; use log::{info, warn}; +use reqwest::blocking::{multipart, ClientBuilder}; use reqwest::header::{HeaderMap, HeaderValue}; -use reqwest::{multipart, ClientBuilder}; use serde_json::json; use std::borrow::Cow; use std::str; @@ -125,27 +125,18 @@ impl Uploader { HeaderValue::from_static(&PROFILER_VERSION_STR), ); - // Send request - let client = ClientBuilder::new().timeout(std::time::Duration::from_millis(10000)); - // Handle UDS - let client = match &self.endpoint { - AgentEndpoint::Socket(path) => client.unix_socket(path.clone()), - _ => client, - }; - - let rt = tokio::runtime::Builder::new_current_thread() - .enable_io() - .enable_time() - .build()?; + // Build blocking client with optional unix socket + let mut client = ClientBuilder::new().timeout(std::time::Duration::from_millis(10000)); + if let AgentEndpoint::Socket(path) = &self.endpoint { + client = client.unix_socket(path.clone()) + } let client = client.build()?; - let response = rt.block_on(async { - client - .post(self.endpoint.to_string()) - .headers(headers) - .multipart(form) - .send() - .await - })?; + + let response = client + .post(self.endpoint.to_string()) + .headers(headers) + .multipart(form) + .send()?; Ok(response.status().as_u16()) } From b4ed42e0f074cb039eb76f607dc2b753567dba02 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Mon, 14 Jul 2025 12:22:45 -0600 Subject: [PATCH 6/7] fix: use rustls to avoid libssl and libcrypto as runtime deps --- Cargo.lock | 19 ++++++++++++++++--- profiling/Cargo.toml | 7 ++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb5232d343f..01c7c86a86b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2943,7 +2943,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", - "webpki-roots", + "webpki-roots 0.26.7", ] [[package]] @@ -2990,7 +2990,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", - "webpki-roots", + "webpki-roots 0.26.7", ] [[package]] @@ -4828,7 +4828,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", + "webpki-roots 0.26.7", "windows-registry 0.4.0", ] @@ -4858,6 +4858,8 @@ dependencies = [ "native-tls", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pki-types", "serde", "serde_json", @@ -4865,6 +4867,7 @@ dependencies = [ "sync_wrapper", "tokio", "tokio-native-tls", + "tokio-rustls", "tower 0.5.2", "tower-http", "tower-service", @@ -4872,6 +4875,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots 1.0.1", ] [[package]] @@ -6534,6 +6538,15 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "webpki-roots" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8782dd5a41a24eed3a4f40b606249b3e236ca61adf1f25ea4d45c73de122b502" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "which" version = "4.4.2" diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index f1b084620d5..3d1eb9335a0 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -32,12 +32,17 @@ once_cell = { version = "1.12" } serde_json = {version = "1.0"} rand = { version = "0.8.5" } rand_distr = { version = "0.4.3" } -reqwest = { git = "https://github.com/seanmonstar/reqwest.git", rev = "10ad5afa5985c9ce8f486cefa27e258a3e925f8b", features = ["blocking", "multipart"] } rustc-hash = "1.1.0" thiserror = "2" tracing = { version = "0.1", optional = true } uuid = { version = "1.0", features = ["v4"] } +[dependencies.reqwest] +git = "https://github.com/seanmonstar/reqwest.git" +rev = "10ad5afa5985c9ce8f486cefa27e258a3e925f8b" +default-feaures = false +features = ["blocking", "multipart", "rustls-tls"] + [dependencies.tracing-subscriber] version = "0.3" optional = true From ba8f818cb1c79d11247c4e90ef93ca7dbc96e0c8 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Tue, 15 Jul 2025 15:54:58 -0600 Subject: [PATCH 7/7] fix: reqwest UDS handling --- Cargo.lock | 158 +--------------------------- profiling/Cargo.toml | 3 +- profiling/src/profiling/uploader.rs | 64 ++++++++--- 3 files changed, 56 insertions(+), 169 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 01c7c86a86b..1b4fee2a5bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1601,6 +1601,7 @@ dependencies = [ "datadog-profiling", "ddcommon 18.0.0", "env_logger 0.11.6", + "http 1.2.0", "lazy_static", "libc 0.2.173", "log", @@ -2327,21 +2328,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -3006,22 +2992,6 @@ dependencies = [ "tower-service", ] -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper 1.6.0", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - [[package]] name = "hyper-util" version = "0.1.15" @@ -3041,11 +3011,9 @@ dependencies = [ "percent-encoding", "pin-project-lite", "socket2", - "system-configuration", "tokio", "tower-service", "tracing", - "windows-registry 0.5.2", ] [[package]] @@ -3691,23 +3659,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "native-tls" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" -dependencies = [ - "libc 0.2.173", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework 2.11.1", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -3845,50 +3796,12 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" -[[package]] -name = "openssl" -version = "0.10.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8" -dependencies = [ - "bitflags 2.8.0", - "cfg-if", - "foreign-types", - "libc 0.2.173", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.96", -] - [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-sys" -version = "0.9.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571" -dependencies = [ - "cc", - "libc 0.2.173", - "pkg-config", - "vcpkg", -] - [[package]] name = "opentelemetry" version = "0.17.0" @@ -4829,7 +4742,7 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "webpki-roots 0.26.7", - "windows-registry 0.4.0", + "windows-registry", ] [[package]] @@ -4839,23 +4752,18 @@ source = "git+https://github.com/seanmonstar/reqwest.git?rev=10ad5afa5985c9ce8f4 dependencies = [ "base64 0.22.1", "bytes", - "encoding_rs", "futures-channel", "futures-core", "futures-util", - "h2", "http 1.2.0", "http-body 1.0.1", "http-body-util", "hyper 1.6.0", "hyper-rustls", - "hyper-tls", "hyper-util", "js-sys", "log", - "mime", "mime_guess", - "native-tls", "percent-encoding", "pin-project-lite", "quinn", @@ -4866,7 +4774,6 @@ dependencies = [ "serde_urlencoded", "sync_wrapper", "tokio", - "tokio-native-tls", "tokio-rustls", "tower 0.5.2", "tower-http", @@ -5605,27 +5512,6 @@ dependencies = [ "libc 0.2.173", ] -[[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags 2.8.0", - "core-foundation 0.9.4", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" -dependencies = [ - "core-foundation-sys", - "libc 0.2.173", -] - [[package]] name = "target-triple" version = "0.1.4" @@ -5965,16 +5851,6 @@ dependencies = [ "syn 2.0.96", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.1" @@ -6386,12 +6262,6 @@ dependencies = [ "ryu", ] -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.1.5" @@ -6655,7 +6525,7 @@ dependencies = [ "windows-implement", "windows-interface", "windows-result", - "windows-strings 0.3.1", + "windows-strings", "windows-targets 0.53.0", ] @@ -6694,21 +6564,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" dependencies = [ "windows-result", - "windows-strings 0.3.1", + "windows-strings", "windows-targets 0.53.0", ] -[[package]] -name = "windows-registry" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3bab093bdd303a1240bb99b8aba8ea8a69ee19d34c9e2ef9594e708a4878820" -dependencies = [ - "windows-link", - "windows-result", - "windows-strings 0.4.2", -] - [[package]] name = "windows-result" version = "0.3.4" @@ -6727,15 +6586,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-strings" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" -dependencies = [ - "windows-link", -] - [[package]] name = "windows-sys" version = "0.42.0" diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index 3d1eb9335a0..06630693029 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -24,6 +24,7 @@ datadog-profiling = { git = "https://github.com/DataDog/libdatadog", tag = "v18. ddcommon = { git = "https://github.com/DataDog/libdatadog", tag = "v18.0.0" } datadog-library-config-ffi = { git = "https://github.com/DataDog/libdatadog", tag = "v18.0.0" } env_logger = { version = "0.11", default-features = false } +http = "1" lazy_static = { version = "1.4" } libc = "0.2" # TRACE set to max to support runtime configuration. @@ -40,7 +41,7 @@ uuid = { version = "1.0", features = ["v4"] } [dependencies.reqwest] git = "https://github.com/seanmonstar/reqwest.git" rev = "10ad5afa5985c9ce8f486cefa27e258a3e925f8b" -default-feaures = false +default-features = false features = ["blocking", "multipart", "rustls-tls"] [dependencies.tracing-subscriber] diff --git a/profiling/src/profiling/uploader.rs b/profiling/src/profiling/uploader.rs index 1009e3e37c6..d8aba685459 100644 --- a/profiling/src/profiling/uploader.rs +++ b/profiling/src/profiling/uploader.rs @@ -3,11 +3,13 @@ use crate::profiling::{UploadMessage, UploadRequest}; use crate::{PROFILER_NAME_STR, PROFILER_VERSION_STR}; use chrono::{DateTime, Utc}; use crossbeam_channel::{select, Receiver}; -use log::{info, warn}; +use ddcommon::Endpoint; +use log::{debug, info, warn}; use reqwest::blocking::{multipart, ClientBuilder}; use reqwest::header::{HeaderMap, HeaderValue}; use serde_json::json; use std::borrow::Cow; +use std::ops::Sub; use std::str; use std::sync::{Arc, Barrier}; @@ -91,7 +93,7 @@ impl Uploader { let serialized = profile.serialize_into_compressed_pprof(Some(message.end_time), message.duration)?; - // Prepare multipart form + // Prepare multipart form with only profile.pprof let mut form = multipart::Form::new().part( "profile.pprof", multipart::Part::bytes(serialized.buffer) @@ -99,16 +101,40 @@ impl Uploader { .mime_str("application/octet-stream")?, ); - // Add event metadata as JSON + // Build tags string let tags = Some(Arc::unwrap_or_clone(index.tags)); - let event_json = serde_json::to_string(&json!({ - "tags_profiler": tags, - "internal": Self::create_internal_metadata(), - "info": self.create_profiler_info(), - }))?; + let mut tags_profiler = String::new(); + if let Some(tags_vec) = &tags { + for tag in tags_vec { + tags_profiler.push_str(tag.as_ref()); + tags_profiler.push(','); + } + } + + // Build internal metadata + let mut internal: serde_json::value::Value = + Self::create_internal_metadata().unwrap_or_else(|| json!({})); + internal["libdatadog_version"] = json!(env!("CARGO_PKG_VERSION")); + + // todo: use start_time + let start = message.end_time.sub(message.duration.unwrap()); + + // Build event JSON + let event = json!({ + "attachments": vec!["profile.pprof"], + "tags_profiler": tags_profiler, + "start": DateTime::::from(start).format("%Y-%m-%dT%H:%M:%S%.9fZ").to_string(), + "end": DateTime::::from(message.end_time).format("%Y-%m-%dT%H:%M:%S%.9fZ").to_string(), + "family": "php", + "version": "4", + "internal": internal, + "info": self.create_profiler_info().unwrap_or_else(|| json!({})), + }) + .to_string(); + form = form.part( "event", - multipart::Part::text(event_json) + multipart::Part::text(event) .file_name("event.json") .mime_str("application/json")?, ); @@ -126,14 +152,22 @@ impl Uploader { ); // Build blocking client with optional unix socket - let mut client = ClientBuilder::new().timeout(std::time::Duration::from_millis(10000)); + let mut client = ClientBuilder::new().timeout(std::time::Duration::from_secs(10)); + let mut endpoint = Endpoint::try_from(&self.endpoint)?.url; if let AgentEndpoint::Socket(path) = &self.endpoint { - client = client.unix_socket(path.clone()) - } + let mut parts = endpoint.into_parts(); + // reqwest doesn't support "unix" as a scheme, only "http" or + // "https", and "unix" urls as documented are currently HTTP only. + parts.scheme = Some(http::uri::Scheme::HTTP); + endpoint = parts.try_into()?; + let socket = path.display(); + debug!("using unix socket `{socket}` for profiling upload to URL `{endpoint}`"); + client = client.unix_socket(path.as_path()); + }; let client = client.build()?; let response = client - .post(self.endpoint.to_string()) + .post(endpoint.to_string()) .headers(headers) .multipart(form) .send()?; @@ -142,7 +176,6 @@ impl Uploader { } // fn upload(&self, message: Box) -> anyhow::Result { - // use ddcommon::Endpoint; // let index = message.index; // let profile = message.profile; // @@ -159,6 +192,9 @@ impl Uploader { // tags, // endpoint, // )?; + // + // let serialized = + // profile.serialize_into_compressed_pprof(Some(message.end_time), message.duration)?; // exporter.set_timeout(10000); // 10 seconds in milliseconds // let request = exporter.build( // serialized,