Skip to content

Commit b8c5304

Browse files
committed
refactor!: move ddog_Endpoint to ddtelemetry
It should be moved somewhere else actually, just getting it out of ddcommon_ffi for now.
1 parent c48d690 commit b8c5304

File tree

10 files changed

+57
-71
lines changed

10 files changed

+57
-71
lines changed

Cargo.lock

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

ddcommon-ffi/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ anyhow = "1.0"
2323
chrono = { version = "0.4.38", features = ["std"] }
2424
crossbeam-queue = "0.3.11"
2525
ddcommon = { path = "../ddcommon" }
26-
ddcommon-net1 = { path = "../ddcommon-net1" }
27-
hyper = {version = "0.14", features = ["backports", "deprecated"], default-features = false}
2826
serde = "1.0"
2927

3028
[dev-dependencies]

ddcommon-ffi/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
mod error;
55

66
pub mod array_queue;
7-
pub mod endpoint;
87
pub mod option;
98
pub mod slice;
109
pub mod string;

ddcommon-net1/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ license.workspace = true
1212
bench = false
1313

1414
[features]
15-
default = ["hyper-rustls/rustls-native-certs"]
15+
default = []
1616
use_webpki_roots = ["hyper-rustls/webpki-roots"]
1717

1818
[dependencies]
@@ -27,7 +27,7 @@ hyper = { version = "0.14", features = ["http1", "client", "tcp", "stream", "bac
2727
hyper-util = "0.1"
2828
lazy_static = "1.4"
2929
pin-project = "1"
30-
rustls = { version = "0.23", default-features = false }
30+
rustls = { version = "0.23", default-features = false, features = ["ring"] }
3131
rustls-native-certs = { version = "0.7" }
3232
serde = { version = "1.0", features = ["derive"] }
3333
tokio = { version = "1.23", features = ["rt", "macros"] }

ddcommon-net1/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ use std::ops::Deref;
1111
use std::path::PathBuf;
1212
use std::str::FromStr;
1313

14+
pub mod deps {
15+
pub use http;
16+
}
17+
1418
pub mod connector;
1519

1620
pub type HttpClient = hyper::Client<connector::Connector, hyper::Body>;

ddtelemetry-ffi/src/builder/expanded.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod macros {
77
use ddcommon_net1::Endpoint;
88
use ddtelemetry::worker::TelemetryWorkerBuilder;
99
use ffi::slice::AsBytes;
10+
1011
#[no_mangle]
1112
#[allow(clippy::redundant_closure_call)]
1213
#[allow(clippy::missing_safety_doc)]

ddtelemetry-ffi/src/builder/macros.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// ```
1111

1212
use ddcommon_ffi as ffi;
13-
use ddcommon_net1::Endpoint;
1413
use ddtelemetry::worker::TelemetryWorkerBuilder;
1514
use ffi::slice::AsBytes;
1615

Original file line numberDiff line numberDiff line change
@@ -1,109 +1,94 @@
11
// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::slice::AsBytes;
5-
use crate::Error;
6-
use hyper::http::uri::{Authority, Parts};
4+
use ddcommon_ffi::slice::AsBytes;
5+
use ddcommon_ffi::{CharSlice, Error};
76
use std::borrow::Cow;
87
use std::str::FromStr;
98

10-
use ddcommon_net1 as net;
11-
use net::parse_uri;
9+
use ddcommon_net1 as net1;
10+
use net1::deps::*;
11+
use net1::parse_uri;
1212

13-
/// Wrapper type to generate the correct FFI name.
14-
pub struct Endpoint(net::Endpoint);
13+
use http::uri::{Authority, Parts};
1514

16-
impl From<net::Endpoint> for Endpoint {
17-
fn from(inner: net::Endpoint) -> Self {
18-
Self(inner)
19-
}
20-
}
21-
22-
impl From<Endpoint> for net::Endpoint {
23-
fn from(inner: Endpoint) -> Self {
24-
inner.0
25-
}
26-
}
15+
// Transparent so they can be used interchangeably over FFI. However, the
16+
// struct needs to be declared, or else it won't get emitted by bindgen.
17+
#[allow(dead_code)]
18+
#[repr(transparent)]
19+
pub struct Endpoint(net1::Endpoint);
2720

2821
#[no_mangle]
2922
#[must_use]
30-
pub extern "C" fn ddog_endpoint_from_url(url: crate::CharSlice) -> Option<Box<Endpoint>> {
23+
pub extern "C" fn ddog_endpoint_from_url(url: CharSlice) -> Option<Box<net1::Endpoint>> {
3124
parse_uri(url.to_utf8_lossy().as_ref())
3225
.ok()
33-
.map(|url| Box::new(net::Endpoint::from_url(url).into()))
26+
.map(|url| Box::new(net1::Endpoint::from_url(url)))
3427
}
3528

3629
#[no_mangle]
3730
#[must_use]
38-
pub extern "C" fn ddog_endpoint_from_filename(filename: crate::CharSlice) -> Option<Box<Endpoint>> {
31+
pub extern "C" fn ddog_endpoint_from_filename(filename: CharSlice) -> Option<Box<net1::Endpoint>> {
3932
let url = format!("file://{}", filename.to_utf8_lossy());
40-
Some(Box::new(net::Endpoint::from_slice(&url).into()))
33+
Some(Box::new(net1::Endpoint::from_slice(&url)))
4134
}
4235

4336
// We'll just specify the base site here. If api key provided, different intakes need to use their
4437
// own subdomains.
4538
#[no_mangle]
4639
#[must_use]
47-
pub extern "C" fn ddog_endpoint_from_api_key(api_key: crate::CharSlice) -> Box<Endpoint> {
40+
pub extern "C" fn ddog_endpoint_from_api_key(api_key: CharSlice) -> Box<net1::Endpoint> {
4841
let mut parts = Parts::default();
4942
parts.authority = Some(Authority::from_static("datadoghq.com"));
50-
Box::new(
51-
net::Endpoint {
52-
url: hyper::Uri::from_parts(parts).unwrap(),
53-
api_key: Some(api_key.to_utf8_lossy().to_string().into()),
54-
..Default::default()
55-
}
56-
.into(),
57-
)
43+
Box::new(net1::Endpoint {
44+
url: http::Uri::from_parts(parts).unwrap(),
45+
api_key: Some(api_key.to_utf8_lossy().to_string().into()),
46+
..Default::default()
47+
})
5848
}
5949

6050
// We'll just specify the base site here. If api key provided, different intakes need to use their
6151
// own subdomains.
6252
#[no_mangle]
6353
#[must_use]
6454
pub extern "C" fn ddog_endpoint_from_api_key_and_site(
65-
api_key: crate::CharSlice,
66-
site: crate::CharSlice,
67-
endpoint: &mut *mut Endpoint,
55+
api_key: CharSlice,
56+
site: CharSlice,
57+
endpoint: &mut *mut net1::Endpoint,
6858
) -> Option<Box<Error>> {
6959
let mut parts = Parts::default();
7060
parts.authority = Some(match Authority::from_str(&site.to_utf8_lossy()) {
7161
Ok(s) => s,
7262
Err(e) => return Some(Box::new(Error::from(e.to_string()))),
7363
});
74-
*endpoint = Box::into_raw(Box::new(
75-
net::Endpoint {
76-
url: hyper::Uri::from_parts(parts).unwrap(),
77-
api_key: Some(api_key.to_utf8_lossy().to_string().into()),
78-
..Default::default()
79-
}
80-
.into(),
81-
));
64+
*endpoint = Box::into_raw(Box::new(net1::Endpoint {
65+
url: http::Uri::from_parts(parts).unwrap(),
66+
api_key: Some(api_key.to_utf8_lossy().to_string().into()),
67+
..Default::default()
68+
}));
8269
None
8370
}
8471

8572
#[no_mangle]
86-
extern "C" fn ddog_endpoint_set_timeout(endpoint: &mut Endpoint, millis: u64) {
87-
endpoint.0.timeout_ms = millis;
73+
extern "C" fn ddog_endpoint_set_timeout(endpoint: &mut net1::Endpoint, millis: u64) {
74+
endpoint.timeout_ms = millis;
8875
}
8976

9077
#[no_mangle]
91-
extern "C" fn ddog_endpoint_set_test_token(endpoint: &mut Endpoint, token: crate::CharSlice) {
92-
endpoint.0.test_token = if token.is_empty() {
78+
extern "C" fn ddog_endpoint_set_test_token(endpoint: &mut net1::Endpoint, token: CharSlice) {
79+
endpoint.test_token = if token.is_empty() {
9380
None
9481
} else {
9582
Some(Cow::Owned(token.to_utf8_lossy().to_string()))
9683
};
9784
}
9885

9986
#[no_mangle]
100-
pub extern "C" fn ddog_endpoint_drop(_: Box<Endpoint>) {}
87+
pub extern "C" fn ddog_endpoint_drop(_: Box<net1::Endpoint>) {}
10188

10289
#[cfg(test)]
10390
mod tests {
10491
use super::*;
105-
use crate::CharSlice;
106-
use net::Endpoint;
10792

10893
#[test]
10994
fn test_ddog_endpoint_from_url() {
@@ -128,19 +113,19 @@ mod tests {
128113
let url = CharSlice::from("http://127.0.0.1");
129114

130115
let mut endpoint = ddog_endpoint_from_url(url);
131-
let timeout_ms = endpoint.as_ref().unwrap().0.timeout_ms;
132-
assert_eq!(timeout_ms, Endpoint::DEFAULT_TIMEOUT);
116+
let timeout_ms = endpoint.as_ref().unwrap().timeout_ms;
117+
assert_eq!(timeout_ms, net1::Endpoint::DEFAULT_TIMEOUT);
133118

134119
ddog_endpoint_set_timeout(endpoint.as_mut().unwrap(), 2000);
135-
let timeout_ms = endpoint.as_ref().unwrap().0.timeout_ms;
120+
let timeout_ms = endpoint.as_ref().unwrap().timeout_ms;
136121
assert_eq!(timeout_ms, 2000);
137122

138123
let mut endpoint_api_key = ddog_endpoint_from_api_key(CharSlice::from("test-key"));
139-
let timeout_ms = endpoint_api_key.0.timeout_ms;
140-
assert_eq!(timeout_ms, Endpoint::DEFAULT_TIMEOUT);
124+
let timeout_ms = endpoint_api_key.timeout_ms;
125+
assert_eq!(timeout_ms, net1::Endpoint::DEFAULT_TIMEOUT);
141126

142127
ddog_endpoint_set_timeout(&mut endpoint_api_key, 2000);
143-
let timeout_ms = endpoint_api_key.0.timeout_ms;
128+
let timeout_ms = endpoint_api_key.timeout_ms;
144129
assert_eq!(timeout_ms, 2000);
145130
}
146131
}

ddtelemetry-ffi/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
pub mod builder;
55
pub mod worker_handle;
66

7+
mod endpoint;
8+
79
#[allow(unused_macros)]
810
macro_rules! c_setters {
911
(

tools/docker/Dockerfile.build

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ ARG CARGO_NET_RETRY="2"
44
ARG BUILDER_IMAGE=debian_builder
55

66
### Debian builder
7-
FROM rust:1-slim-buster as debian_builder
7+
FROM rust:1-slim-buster AS debian_builder
88
ENV CARGO_HOME="/root/.cargo"
99
WORKDIR /build
1010
RUN cargo install cbindgen; mv /root/.cargo/bin/cbindgen /usr/bin/; rm -rf /root/.cargo
1111

1212
### Debian buildplatform builder
13-
FROM --platform=$BUILDPLATFORM rust:1-slim-buster as debian_builder_platform_native
13+
FROM --platform=$BUILDPLATFORM rust:1-slim-buster AS debian_builder_platform_native
1414
ENV CARGO_HOME="/root/.cargo"
1515
WORKDIR /build
1616

1717
### Alpine builder
18-
FROM ${ALPINE_BASE_IMAGE} as alpine_base
18+
FROM ${ALPINE_BASE_IMAGE} AS alpine_base
1919
ENV CARGO_HOME="/root/.cargo"
2020
WORKDIR /build
2121

@@ -43,20 +43,20 @@ SHELL ["/bin/bash", "-c"]
4343
# Also, it doesn't understand x86_64-alpine-linux-musl like the OS's cargo.
4444
#RUN rustup-init -y --no-modify-path --default-toolchain stable
4545

46-
FROM alpine_base as alpine_aws_cli
46+
FROM alpine_base AS alpine_aws_cli
4747
RUN apk add --no-cache aws-cli \
4848
&& rm -rf /var/cache/apk/*
4949

5050
RUN aws --version # Just to make sure its installed alright
5151

52-
FROM alpine_base as alpine_cbindgen
52+
FROM alpine_base AS alpine_cbindgen
5353
ENV PATH="/root/.cargo/bin:$PATH"
5454
ARG CARGO_BUILD_INCREMENTAL
5555
ARG CARGO_NET_RETRY
5656
ENV CARGO_NET_RETRY="${CARGO_NET_RETRY}"
5757
RUN cargo install cbindgen --version "^0.26" && cargo install bindgen-cli --locked && rm -rf /root/.cargo/registry /root/.cargo/git
5858

59-
FROM alpine_aws_cli as alpine_builder
59+
FROM alpine_aws_cli AS alpine_builder
6060
COPY --from=alpine_cbindgen /root/.cargo/bin/cbindgen /usr/local/bin/cbindgen
6161
COPY --from=alpine_cbindgen /root/.cargo/bin/bindgen /usr/local/bin/bindgen
6262

@@ -146,7 +146,7 @@ RUN echo \
146146
RUN cargo fetch --locked
147147

148148
# extract cargo cache
149-
FROM --platform=$BUILDPLATFORM scratch as ffi_build_platform_agnostic_cache
149+
FROM --platform=$BUILDPLATFORM scratch AS ffi_build_platform_agnostic_cache
150150
COPY --from=ffi_build_platform_agnostic_cache_build /root/.cargo /root/.cargo
151151
COPY --from=ffi_build_platform_agnostic_cache_build /build /build
152152

@@ -163,6 +163,6 @@ RUN cargo build --release --lib --workspace --exclude builder
163163
COPY ./ ./
164164
RUN cargo run --bin release --features profiling,telemetry,data-pipeline,symbolizer,crashtracker --release -- --out /build/output
165165

166-
FROM scratch as ffi_build_output
166+
FROM scratch AS ffi_build_output
167167

168168
COPY --from=ffi_build /build/output/ ./

0 commit comments

Comments
 (0)