diff --git a/Cargo.lock b/Cargo.lock index 84107f081..b08cdecae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1326,10 +1326,9 @@ name = "data-pipeline-ffi" version = "14.3.1" dependencies = [ "build_common", - "bytes", "data-pipeline", "ddcommon-ffi", - "libc", + "tinybytes", ] [[package]] @@ -1852,7 +1851,7 @@ dependencies = [ "hyper-util", "lazy_static", "pin-project", - "rustls 0.23.16", + "rustls 0.23.18", "rustls-native-certs 0.7.3", "serde", "tokio", @@ -2831,7 +2830,7 @@ dependencies = [ "http 1.1.0", "hyper 1.5.0", "hyper-util", - "rustls 0.23.16", + "rustls 0.23.18", "rustls-native-certs 0.8.0", "rustls-pki-types", "tokio", @@ -4314,7 +4313,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash 2.0.0", - "rustls 0.23.16", + "rustls 0.23.18", "socket2", "thiserror", "tokio", @@ -4331,7 +4330,7 @@ dependencies = [ "rand", "ring 0.17.8", "rustc-hash 2.0.0", - "rustls 0.23.16", + "rustls 0.23.18", "slab", "thiserror", "tinyvec", @@ -4529,7 +4528,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn", - "rustls 0.23.16", + "rustls 0.23.18", "rustls-pemfile", "rustls-pki-types", "serde", @@ -4678,9 +4677,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.16" +version = "0.23.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f" dependencies = [ "aws-lc-rs", "once_cell", @@ -5734,7 +5733,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.16", + "rustls 0.23.18", "rustls-pki-types", "tokio", ] diff --git a/LICENSE-3rdparty.yml b/LICENSE-3rdparty.yml index 61cea531f..65832f248 100644 --- a/LICENSE-3rdparty.yml +++ b/LICENSE-3rdparty.yml @@ -22948,7 +22948,7 @@ third_party_libraries: IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - package_name: rustls - package_version: 0.23.16 + package_version: 0.23.18 repository: https://github.com/rustls/rustls license: Apache-2.0 OR ISC OR MIT licenses: diff --git a/builder/src/builder.rs b/builder/src/builder.rs index 92672adc6..08850dc78 100644 --- a/builder/src/builder.rs +++ b/builder/src/builder.rs @@ -139,7 +139,12 @@ impl Builder { pub fn add_cmake(&self) { let libs = arch::NATIVE_LIBS.to_owned(); - let cmake_path: PathBuf = [&self.target_dir, "DatadogConfig.cmake"].iter().collect(); + let cmake_dir: PathBuf = [&self.target_dir, "cmake"].iter().collect(); + fs::create_dir_all(cmake_dir).expect("Failed to create cmake dir"); + + let cmake_path: PathBuf = [&self.target_dir, "cmake", "DatadogConfig.cmake"] + .iter() + .collect(); let mut origin = project_root(); origin.push("cmake"); origin.push("DatadogConfig.cmake.in"); diff --git a/builder/src/crashtracker.rs b/builder/src/crashtracker.rs index be2c7603b..489e9c173 100644 --- a/builder/src/crashtracker.rs +++ b/builder/src/crashtracker.rs @@ -22,11 +22,14 @@ pub struct CrashTracker { impl CrashTracker { fn gen_binaries(&self) -> Result<()> { if arch::BUILD_CRASHTRACKER { + let mut datadog_root = project_root(); + datadog_root.push(self.target_dir.as_ref()); + let mut crashtracker_dir = project_root(); crashtracker_dir.push("crashtracker"); let _dst = cmake::Config::new(crashtracker_dir.to_str().unwrap()) - .define("Datadog_ROOT", self.target_dir.as_ref()) - .define("CMAKE_INSTALL_PREFIX", self.target_dir.as_ref()) + .define("Datadog_ROOT", datadog_root.to_str().unwrap()) + .define("CMAKE_INSTALL_PREFIX", self.target_dir.to_string()) .build(); } diff --git a/data-pipeline-ffi/Cargo.toml b/data-pipeline-ffi/Cargo.toml index 8d5f4b6a0..f3fb0bc63 100644 --- a/data-pipeline-ffi/Cargo.toml +++ b/data-pipeline-ffi/Cargo.toml @@ -24,5 +24,4 @@ build_common = { path = "../build-common" } [dependencies] data-pipeline = { path = "../data-pipeline" } ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false } -bytes = "1.4" -libc = "0.2.153" +tinybytes = { path = "../tinybytes" } diff --git a/data-pipeline-ffi/src/trace_exporter.rs b/data-pipeline-ffi/src/trace_exporter.rs index b3cdbe365..0b1854f30 100644 --- a/data-pipeline-ffi/src/trace_exporter.rs +++ b/data-pipeline-ffi/src/trace_exporter.rs @@ -102,7 +102,8 @@ pub unsafe extern "C" fn ddog_trace_exporter_free(handle: Box) { /// /// * `handle` - The handle to the TraceExporter instance. /// * `trace` - The traces to send to the Datadog Agent in the input format used to create the -/// TraceExporter. +/// TraceExporter. The memory for the trace must be valid for the life of the call to this +/// function. /// * `trace_count` - The number of traces to send to the Datadog Agent. #[no_mangle] pub unsafe extern "C" fn ddog_trace_exporter_send( @@ -110,9 +111,18 @@ pub unsafe extern "C" fn ddog_trace_exporter_send( trace: ByteSlice, trace_count: usize, ) -> MaybeError { - // TODO - handle errors - https://datadoghq.atlassian.net/browse/APMSP-1095 + // necessary that the trace be static for the life of the FFI function call as the caller + // currently owns the memory. + //APMSP-1621 - Properly fix this sharp-edge by allocating memory on the Rust side + let static_trace: ByteSlice<'static> = std::mem::transmute(trace); + + // TODO: APMSP-1095 - properly handle errors from the send call handle - .send(trace.as_bytes(), trace_count) + .send( + tinybytes::Bytes::from_static(static_trace.as_slice()), + trace_count, + ) .unwrap_or(String::from("")); + MaybeError::None } diff --git a/data-pipeline/examples/send-traces-with-stats.rs b/data-pipeline/examples/send-traces-with-stats.rs index be58c1712..095c02528 100644 --- a/data-pipeline/examples/send-traces-with-stats.rs +++ b/data-pipeline/examples/send-traces-with-stats.rs @@ -55,6 +55,8 @@ fn main() { traces.push(trace); } let data = rmp_serde::to_vec_named(&traces).unwrap(); - exporter.send(&data, 100).unwrap(); + let data_as_bytes = tinybytes::Bytes::from(data); + + exporter.send(data_as_bytes, 100).unwrap(); exporter.shutdown(None).unwrap(); } diff --git a/data-pipeline/src/trace_exporter.rs b/data-pipeline/src/trace_exporter.rs index c4f9684c6..6725446a7 100644 --- a/data-pipeline/src/trace_exporter.rs +++ b/data-pipeline/src/trace_exporter.rs @@ -254,15 +254,11 @@ impl TraceExporter { /// Send msgpack serialized traces to the agent #[allow(missing_docs)] - pub fn send(&self, data: &[u8], trace_count: usize) -> Result { + pub fn send(&self, data: tinybytes::Bytes, trace_count: usize) -> Result { self.check_agent_info(); match self.input_format { - TraceExporterInputFormat::Proxy => self.send_proxy(data, trace_count), - TraceExporterInputFormat::V04 => { - self.send_deser_ser(tinybytes::Bytes::copy_from_slice(data)) - // TODO: APMSP-1582 - Refactor data-pipeline-ffi so we can leverage a type that - // implements tinybytes::UnderlyingBytes trait to avoid copying - } + TraceExporterInputFormat::Proxy => self.send_proxy(data.as_ref(), trace_count), + TraceExporterInputFormat::V04 => self.send_deser_ser(data), } } @@ -1188,7 +1184,7 @@ mod tests { ..Default::default() }]; - let data = rmp_serde::to_vec_named(&vec![trace_chunk]).unwrap(); + let data = tinybytes::Bytes::from(rmp_serde::to_vec_named(&vec![trace_chunk]).unwrap()); // Wait for the info fetcher to get the config while mock_info.hits() == 0 { @@ -1197,7 +1193,7 @@ mod tests { }) } - exporter.send(data.as_slice(), 1).unwrap(); + exporter.send(data, 1).unwrap(); exporter.shutdown(None).unwrap(); mock_traces.assert(); @@ -1315,8 +1311,10 @@ mod tests { ..Default::default() }], ]; - let bytes = rmp_serde::to_vec_named(&traces).expect("failed to serialize static trace"); - let _result = exporter.send(&bytes, 1).expect("failed to send trace"); + let bytes = tinybytes::Bytes::from( + rmp_serde::to_vec_named(&traces).expect("failed to serialize static trace"), + ); + let _result = exporter.send(bytes, 1).expect("failed to send trace"); assert_eq!( &format!( @@ -1347,9 +1345,8 @@ mod tests { stats_socket.local_addr().unwrap().to_string(), ); - let _result = exporter - .send(b"some_bad_payload", 1) - .expect("failed to send trace"); + let bad_payload = tinybytes::Bytes::copy_from_slice(b"some_bad_payload".as_ref()); + let _result = exporter.send(bad_payload, 1).expect("failed to send trace"); assert_eq!( &format!( @@ -1382,8 +1379,10 @@ mod tests { name: BytesString::from_slice(b"test").unwrap(), ..Default::default() }]]; - let bytes = rmp_serde::to_vec_named(&traces).expect("failed to serialize static trace"); - let _result = exporter.send(&bytes, 1).expect("failed to send trace"); + let bytes = tinybytes::Bytes::from( + rmp_serde::to_vec_named(&traces).expect("failed to serialize static trace"), + ); + let _result = exporter.send(bytes, 1).expect("failed to send trace"); assert_eq!( &format!(