Skip to content

Commit c665eb4

Browse files
committed
Merge branch 'main' into levi/split-net
2 parents 1cf5035 + a3c1bd4 commit c665eb4

File tree

8 files changed

+53
-36
lines changed

8 files changed

+53
-36
lines changed

Cargo.lock

+9-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE-3rdparty.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22948,7 +22948,7 @@ third_party_libraries:
2294822948
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2294922949
DEALINGS IN THE SOFTWARE.
2295022950
- package_name: rustls
22951-
package_version: 0.23.16
22951+
package_version: 0.23.18
2295222952
repository: https://github.com/rustls/rustls
2295322953
license: Apache-2.0 OR ISC OR MIT
2295422954
licenses:

builder/src/builder.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ impl Builder {
139139

140140
pub fn add_cmake(&self) {
141141
let libs = arch::NATIVE_LIBS.to_owned();
142-
let cmake_path: PathBuf = [&self.target_dir, "DatadogConfig.cmake"].iter().collect();
142+
let cmake_dir: PathBuf = [&self.target_dir, "cmake"].iter().collect();
143+
fs::create_dir_all(cmake_dir).expect("Failed to create cmake dir");
144+
145+
let cmake_path: PathBuf = [&self.target_dir, "cmake", "DatadogConfig.cmake"]
146+
.iter()
147+
.collect();
143148
let mut origin = project_root();
144149
origin.push("cmake");
145150
origin.push("DatadogConfig.cmake.in");

builder/src/crashtracker.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ pub struct CrashTracker {
2222
impl CrashTracker {
2323
fn gen_binaries(&self) -> Result<()> {
2424
if arch::BUILD_CRASHTRACKER {
25+
let mut datadog_root = project_root();
26+
datadog_root.push(self.target_dir.as_ref());
27+
2528
let mut crashtracker_dir = project_root();
2629
crashtracker_dir.push("crashtracker");
2730
let _dst = cmake::Config::new(crashtracker_dir.to_str().unwrap())
28-
.define("Datadog_ROOT", self.target_dir.as_ref())
29-
.define("CMAKE_INSTALL_PREFIX", self.target_dir.as_ref())
31+
.define("Datadog_ROOT", datadog_root.to_str().unwrap())
32+
.define("CMAKE_INSTALL_PREFIX", self.target_dir.to_string())
3033
.build();
3134
}
3235

data-pipeline-ffi/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ build_common = { path = "../build-common" }
2424
[dependencies]
2525
data-pipeline = { path = "../data-pipeline" }
2626
ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false }
27-
bytes = "1.4"
28-
libc = "0.2.153"
27+
tinybytes = { path = "../tinybytes" }

data-pipeline-ffi/src/trace_exporter.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,27 @@ pub unsafe extern "C" fn ddog_trace_exporter_free(handle: Box<TraceExporter>) {
102102
///
103103
/// * `handle` - The handle to the TraceExporter instance.
104104
/// * `trace` - The traces to send to the Datadog Agent in the input format used to create the
105-
/// TraceExporter.
105+
/// TraceExporter. The memory for the trace must be valid for the life of the call to this
106+
/// function.
106107
/// * `trace_count` - The number of traces to send to the Datadog Agent.
107108
#[no_mangle]
108109
pub unsafe extern "C" fn ddog_trace_exporter_send(
109110
handle: &TraceExporter,
110111
trace: ByteSlice,
111112
trace_count: usize,
112113
) -> MaybeError {
113-
// TODO - handle errors - https://datadoghq.atlassian.net/browse/APMSP-1095
114+
// necessary that the trace be static for the life of the FFI function call as the caller
115+
// currently owns the memory.
116+
//APMSP-1621 - Properly fix this sharp-edge by allocating memory on the Rust side
117+
let static_trace: ByteSlice<'static> = std::mem::transmute(trace);
118+
119+
// TODO: APMSP-1095 - properly handle errors from the send call
114120
handle
115-
.send(trace.as_bytes(), trace_count)
121+
.send(
122+
tinybytes::Bytes::from_static(static_trace.as_slice()),
123+
trace_count,
124+
)
116125
.unwrap_or(String::from(""));
126+
117127
MaybeError::None
118128
}

data-pipeline/examples/send-traces-with-stats.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ fn main() {
5555
traces.push(trace);
5656
}
5757
let data = rmp_serde::to_vec_named(&traces).unwrap();
58-
exporter.send(&data, 100).unwrap();
58+
let data_as_bytes = tinybytes::Bytes::from(data);
59+
60+
exporter.send(data_as_bytes, 100).unwrap();
5961
exporter.shutdown(None).unwrap();
6062
}

data-pipeline/src/trace_exporter.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,11 @@ impl TraceExporter {
254254

255255
/// Send msgpack serialized traces to the agent
256256
#[allow(missing_docs)]
257-
pub fn send(&self, data: &[u8], trace_count: usize) -> Result<String, String> {
257+
pub fn send(&self, data: tinybytes::Bytes, trace_count: usize) -> Result<String, String> {
258258
self.check_agent_info();
259259
match self.input_format {
260-
TraceExporterInputFormat::Proxy => self.send_proxy(data, trace_count),
261-
TraceExporterInputFormat::V04 => {
262-
self.send_deser_ser(tinybytes::Bytes::copy_from_slice(data))
263-
// TODO: APMSP-1582 - Refactor data-pipeline-ffi so we can leverage a type that
264-
// implements tinybytes::UnderlyingBytes trait to avoid copying
265-
}
260+
TraceExporterInputFormat::Proxy => self.send_proxy(data.as_ref(), trace_count),
261+
TraceExporterInputFormat::V04 => self.send_deser_ser(data),
266262
}
267263
}
268264

@@ -1188,7 +1184,7 @@ mod tests {
11881184
..Default::default()
11891185
}];
11901186

1191-
let data = rmp_serde::to_vec_named(&vec![trace_chunk]).unwrap();
1187+
let data = tinybytes::Bytes::from(rmp_serde::to_vec_named(&vec![trace_chunk]).unwrap());
11921188

11931189
// Wait for the info fetcher to get the config
11941190
while mock_info.hits() == 0 {
@@ -1197,7 +1193,7 @@ mod tests {
11971193
})
11981194
}
11991195

1200-
exporter.send(data.as_slice(), 1).unwrap();
1196+
exporter.send(data, 1).unwrap();
12011197
exporter.shutdown(None).unwrap();
12021198

12031199
mock_traces.assert();
@@ -1315,8 +1311,10 @@ mod tests {
13151311
..Default::default()
13161312
}],
13171313
];
1318-
let bytes = rmp_serde::to_vec_named(&traces).expect("failed to serialize static trace");
1319-
let _result = exporter.send(&bytes, 1).expect("failed to send trace");
1314+
let bytes = tinybytes::Bytes::from(
1315+
rmp_serde::to_vec_named(&traces).expect("failed to serialize static trace"),
1316+
);
1317+
let _result = exporter.send(bytes, 1).expect("failed to send trace");
13201318

13211319
assert_eq!(
13221320
&format!(
@@ -1347,9 +1345,8 @@ mod tests {
13471345
stats_socket.local_addr().unwrap().to_string(),
13481346
);
13491347

1350-
let _result = exporter
1351-
.send(b"some_bad_payload", 1)
1352-
.expect("failed to send trace");
1348+
let bad_payload = tinybytes::Bytes::copy_from_slice(b"some_bad_payload".as_ref());
1349+
let _result = exporter.send(bad_payload, 1).expect("failed to send trace");
13531350

13541351
assert_eq!(
13551352
&format!(
@@ -1382,8 +1379,10 @@ mod tests {
13821379
name: BytesString::from_slice(b"test").unwrap(),
13831380
..Default::default()
13841381
}]];
1385-
let bytes = rmp_serde::to_vec_named(&traces).expect("failed to serialize static trace");
1386-
let _result = exporter.send(&bytes, 1).expect("failed to send trace");
1382+
let bytes = tinybytes::Bytes::from(
1383+
rmp_serde::to_vec_named(&traces).expect("failed to serialize static trace"),
1384+
);
1385+
let _result = exporter.send(bytes, 1).expect("failed to send trace");
13871386

13881387
assert_eq!(
13891388
&format!(

0 commit comments

Comments
 (0)