From b7138174b30443c03c47300128ef58f119094473 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Tue, 26 Nov 2024 12:52:49 -0700 Subject: [PATCH] refactor: split networking from ddcommon into ddcommon-net1 The name "net1" is here because I intend to make net2 shortly in a stacked PR. The splitting out of this networking code from the core common code is to allow this to happen. --- Cargo.lock | 55 +++-- Cargo.toml | 1 + LICENSE-3rdparty.yml | 86 +------- bin_tests/Cargo.toml | 1 + bin_tests/src/bin/crashtracker_bin_test.rs | 3 +- crashtracker-ffi/Cargo.toml | 1 + crashtracker-ffi/src/collector/datatypes.rs | 2 +- crashtracker-ffi/src/crash_info/api.rs | 2 +- crashtracker/Cargo.toml | 3 +- crashtracker/src/collector/api.rs | 12 +- crashtracker/src/crash_info/mod.rs | 4 +- crashtracker/src/crash_info/telemetry.rs | 12 +- crashtracker/src/rfc5_crash_info/mod.rs | 4 +- crashtracker/src/rfc5_crash_info/telemetry.rs | 8 +- crashtracker/src/shared/configuration.rs | 2 +- data-pipeline/Cargo.toml | 1 + data-pipeline/src/agent_info/fetcher.rs | 7 +- data-pipeline/src/stats_exporter.rs | 10 +- data-pipeline/src/trace_exporter/mod.rs | 3 +- data-pipeline/tests/test_fetch_info.rs | 2 +- ddcommon-ffi/Cargo.toml | 1 + ddcommon-ffi/src/endpoint.rs | 69 ++++-- ddcommon-net1/Cargo.toml | 57 +++++ .../src/connector/conn_stream.rs | 0 .../src/connector/errors.rs | 0 .../src/connector/mod.rs | 0 .../src/connector/named_pipe.rs | 0 .../src/connector/uds.rs | 0 ddcommon-net1/src/lib.rs | 208 ++++++++++++++++++ ddcommon/Cargo.toml | 37 ---- ddcommon/src/config.rs | 7 - ddcommon/src/lib.rs | 203 ----------------- ddtelemetry-ffi/Cargo.toml | 1 + ddtelemetry-ffi/src/builder/expanded.rs | 2 +- ddtelemetry-ffi/src/builder/macros.rs | 2 +- ddtelemetry-ffi/src/lib.rs | 2 +- ddtelemetry/Cargo.toml | 1 + .../examples/tm-metrics-worker-test.rs | 2 +- ddtelemetry/examples/tm-ping.rs | 2 +- ddtelemetry/examples/tm-send-sketch.rs | 4 +- ddtelemetry/examples/tm-worker-test.rs | 4 +- ddtelemetry/src/config.rs | 13 +- ddtelemetry/src/worker/builder.rs | 2 +- ddtelemetry/src/worker/http_client.rs | 10 +- ddtelemetry/src/worker/mod.rs | 4 +- dogstatsd-client/Cargo.toml | 1 + dogstatsd-client/src/lib.rs | 22 +- live-debugger-ffi/Cargo.toml | 1 + live-debugger-ffi/src/sender.rs | 2 +- live-debugger/Cargo.toml | 1 + live-debugger/src/sender.rs | 3 +- profiling-ffi/Cargo.toml | 3 +- profiling-ffi/src/exporter.rs | 4 +- profiling/Cargo.toml | 3 +- profiling/src/exporter/config.rs | 15 +- profiling/src/exporter/mod.rs | 23 +- remote-config/Cargo.toml | 1 + remote-config/examples/remote_config_fetch.rs | 2 +- remote-config/src/fetch/fetcher.rs | 4 +- remote-config/src/fetch/test_server.rs | 2 +- sidecar-ffi/Cargo.toml | 1 + sidecar-ffi/src/lib.rs | 2 +- sidecar-ffi/tests/sidecar.rs | 2 +- sidecar/Cargo.toml | 1 + sidecar/src/agent_remote_config.rs | 2 +- sidecar/src/config.rs | 2 +- sidecar/src/service/agent_info.rs | 3 +- sidecar/src/service/mod.rs | 2 +- sidecar/src/service/sidecar_server.rs | 2 +- sidecar/src/service/tracing/trace_flusher.rs | 3 +- sidecar/src/tracer.rs | 2 +- tools/docker/Dockerfile.build | 1 + trace-mini-agent/Cargo.toml | 1 + trace-mini-agent/src/config.rs | 2 +- trace-mini-agent/src/trace_processor.rs | 2 +- trace-utils/Cargo.toml | 3 +- trace-utils/src/send_data/mod.rs | 6 +- trace-utils/src/stats_utils.rs | 3 +- .../src/test_utils/datadog_test_agent.rs | 2 +- trace-utils/src/test_utils/mod.rs | 4 +- trace-utils/tests/test_send_data.rs | 2 +- 81 files changed, 502 insertions(+), 483 deletions(-) create mode 100644 ddcommon-net1/Cargo.toml rename {ddcommon => ddcommon-net1}/src/connector/conn_stream.rs (100%) rename {ddcommon => ddcommon-net1}/src/connector/errors.rs (100%) rename {ddcommon => ddcommon-net1}/src/connector/mod.rs (100%) rename {ddcommon => ddcommon-net1}/src/connector/named_pipe.rs (100%) rename {ddcommon => ddcommon-net1}/src/connector/uds.rs (100%) create mode 100644 ddcommon-net1/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 741d8468e..c8b86ad44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -482,6 +482,7 @@ dependencies = [ "datadog-crashtracker", "datadog-profiling", "ddcommon", + "ddcommon-net1", "libc", "nix 0.27.1", "once_cell", @@ -1303,6 +1304,7 @@ dependencies = [ "datadog-trace-protobuf", "datadog-trace-utils", "ddcommon", + "ddcommon-net1", "dogstatsd-client", "either", "futures", @@ -1351,6 +1353,7 @@ dependencies = [ "blazesym", "chrono", "ddcommon", + "ddcommon-net1", "ddtelemetry", "http 0.2.12", "hyper 0.14.31", @@ -1377,6 +1380,7 @@ dependencies = [ "datadog-crashtracker", "ddcommon", "ddcommon-ffi", + "ddcommon-net1", "function_name", "hyper 0.14.31", "libc", @@ -1471,6 +1475,7 @@ dependencies = [ "anyhow", "constcat", "ddcommon", + "ddcommon-net1", "hyper 0.14.31", "json", "lazy_static", @@ -1493,6 +1498,7 @@ dependencies = [ "datadog-live-debugger", "ddcommon", "ddcommon-ffi", + "ddcommon-net1", "log", "percent-encoding", "serde_json", @@ -1515,6 +1521,7 @@ dependencies = [ "criterion", "datadog-alloc", "ddcommon", + "ddcommon-net1", "derivative", "futures", "futures-core", @@ -1550,6 +1557,7 @@ dependencies = [ "datadog-profiling", "ddcommon", "ddcommon-ffi", + "ddcommon-net1", "ddtelemetry-ffi", "futures", "hyper 0.14.31", @@ -1595,6 +1603,7 @@ dependencies = [ "datadog-live-debugger", "datadog-trace-protobuf", "ddcommon", + "ddcommon-net1", "futures", "futures-util", "http 0.2.12", @@ -1652,6 +1661,7 @@ dependencies = [ "datadog-trace-protobuf", "datadog-trace-utils", "ddcommon", + "ddcommon-net1", "ddtelemetry", "dogstatsd-client", "futures", @@ -1705,6 +1715,7 @@ dependencies = [ "datadog-trace-utils", "ddcommon", "ddcommon-ffi", + "ddcommon-net1", "ddtelemetry", "ddtelemetry-ffi", "dogstatsd-client", @@ -1733,6 +1744,7 @@ dependencies = [ "datadog-trace-protobuf", "datadog-trace-utils", "ddcommon", + "ddcommon-net1", "duplicate", "hyper 0.14.31", "rmp-serde", @@ -1801,6 +1813,7 @@ dependencies = [ "datadog-trace-protobuf", "datadog-trace-utils", "ddcommon", + "ddcommon-net1", "flate2", "futures", "httpmock", @@ -1826,27 +1839,13 @@ version = "14.3.1" dependencies = [ "anyhow", "cc", - "futures", - "futures-core", - "futures-util", - "hex", - "http 0.2.12", - "hyper 0.14.31", - "hyper-rustls 0.27.3", - "hyper-util", "indexmap 2.6.0", "lazy_static", "libc", - "log", "maplit", - "pin-project", "regex", - "rustls 0.23.18", - "rustls-native-certs 0.7.3", "serde", "static_assertions", - "tokio", - "tokio-rustls 0.26.0", "windows-sys 0.52.0", ] @@ -1860,10 +1859,35 @@ dependencies = [ "chrono", "crossbeam-queue", "ddcommon", + "ddcommon-net1", "hyper 0.14.31", "serde", ] +[[package]] +name = "ddcommon-net1" +version = "14.3.1" +dependencies = [ + "anyhow", + "ddcommon", + "futures", + "futures-core", + "futures-util", + "hex", + "http 0.2.12", + "hyper 0.14.31", + "hyper-rustls 0.27.3", + "hyper-util", + "lazy_static", + "pin-project", + "rustls 0.23.18", + "rustls-native-certs 0.7.3", + "serde", + "tokio", + "tokio-rustls 0.26.0", + "windows-sys 0.52.0", +] + [[package]] name = "ddsketch-agent" version = "0.1.0" @@ -1883,6 +1907,7 @@ dependencies = [ "base64 0.22.1", "datadog-ddsketch", "ddcommon", + "ddcommon-net1", "futures", "hashbrown 0.14.5", "http 0.2.12", @@ -1908,6 +1933,7 @@ dependencies = [ "build_common", "ddcommon", "ddcommon-ffi", + "ddcommon-net1", "ddtelemetry", "libc", "paste", @@ -2080,6 +2106,7 @@ dependencies = [ "datadog-trace-normalization", "datadog-trace-protobuf", "ddcommon", + "ddcommon-net1", "http 0.2.12", "serde", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 52437ded3..592b908a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ members = [ "profiling-replayer", "ddcommon", "ddcommon-ffi", + "ddcommon-net1", "ddtelemetry", "ddtelemetry-ffi", "dogstatsd", diff --git a/LICENSE-3rdparty.yml b/LICENSE-3rdparty.yml index 2aa1a2cf0..b819f086f 100644 --- a/LICENSE-3rdparty.yml +++ b/LICENSE-3rdparty.yml @@ -1,4 +1,4 @@ -root_name: datadog-alloc, builder, build_common, tools, datadog-crashtracker, ddcommon, ddtelemetry, datadog-ddsketch, datadog-crashtracker-ffi, ddcommon-ffi, datadog-profiling, datadog-profiling-ffi, data-pipeline-ffi, data-pipeline, datadog-trace-normalization, datadog-trace-protobuf, datadog-trace-obfuscation, datadog-trace-utils, tinybytes, dogstatsd-client, datadog-library-config-ffi, datadog-library-config, ddtelemetry-ffi, symbolizer-ffi, datadog-profiling-replayer, dogstatsd, datadog-ipc, datadog-ipc-macros, tarpc, tarpc-plugins, spawn_worker, cc_utils, datadog-live-debugger, datadog-live-debugger-ffi, datadog-remote-config, datadog-dynamic-configuration, datadog-sidecar, datadog-sidecar-macros, datadog-sidecar-ffi, sidecar_mockgen, test_spawn_from_lib, datadog-serverless-trace-mini-agent, datadog-trace-mini-agent +root_name: datadog-alloc, builder, build_common, tools, datadog-crashtracker, ddcommon, ddcommon-net1, ddtelemetry, datadog-ddsketch, datadog-crashtracker-ffi, ddcommon-ffi, datadog-profiling, datadog-profiling-ffi, data-pipeline-ffi, data-pipeline, datadog-trace-normalization, datadog-trace-protobuf, datadog-trace-obfuscation, datadog-trace-utils, tinybytes, dogstatsd-client, datadog-library-config-ffi, datadog-library-config, ddtelemetry-ffi, symbolizer-ffi, datadog-profiling-replayer, dogstatsd, datadog-ipc, datadog-ipc-macros, tarpc, tarpc-plugins, spawn_worker, cc_utils, datadog-live-debugger, datadog-live-debugger-ffi, datadog-remote-config, datadog-dynamic-configuration, datadog-sidecar, datadog-sidecar-macros, datadog-sidecar-ffi, sidecar_mockgen, test_spawn_from_lib, datadog-serverless-trace-mini-agent, datadog-trace-mini-agent third_party_libraries: - package_name: addr2line package_version: 0.24.2 @@ -24419,37 +24419,7 @@ third_party_libraries: limitations under the License. - license: BSD-3-Clause - text: |+ - BSD 3-Clause License - - Copyright (c) 2019, Standard Cognition - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + text: NOT FOUND - package_name: serde package_version: 1.0.214 repository: https://github.com/serde-rs/serde @@ -42656,31 +42626,7 @@ third_party_libraries: license: BSD-2-Clause OR Apache-2.0 OR MIT licenses: - license: BSD-2-Clause - text: | - Copyright 2019 The Fuchsia Authors. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + text: NOT FOUND - license: Apache-2.0 text: |2+ Apache License @@ -42919,31 +42865,7 @@ third_party_libraries: license: BSD-2-Clause OR Apache-2.0 OR MIT licenses: - license: BSD-2-Clause - text: | - Copyright 2019 The Fuchsia Authors. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + text: NOT FOUND - license: Apache-2.0 text: |2+ Apache License diff --git a/bin_tests/Cargo.toml b/bin_tests/Cargo.toml index b673af163..9b6a7531c 100644 --- a/bin_tests/Cargo.toml +++ b/bin_tests/Cargo.toml @@ -15,6 +15,7 @@ current_platform = "0.2.0" datadog-profiling = { path = "../profiling" } datadog-crashtracker = { path = "../crashtracker" } ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } tempfile = "3.3" serde_json = { version = "1.0" } strum = { version = "0.26.2", features = ["derive"] } diff --git a/bin_tests/src/bin/crashtracker_bin_test.rs b/bin_tests/src/bin/crashtracker_bin_test.rs index 425240b8e..cf93b9128 100644 --- a/bin_tests/src/bin/crashtracker_bin_test.rs +++ b/bin_tests/src/bin/crashtracker_bin_test.rs @@ -20,7 +20,8 @@ mod unix { self as crashtracker, CrashtrackerConfiguration, CrashtrackerMetadata, CrashtrackerReceiverConfig, }; - use ddcommon::{tag, Endpoint}; + use ddcommon::tag; + use ddcommon_net1::Endpoint; const TEST_COLLECTOR_TIMEOUT_MS: u32 = 10_000; diff --git a/crashtracker-ffi/Cargo.toml b/crashtracker-ffi/Cargo.toml index 75c86a32f..1551318a4 100644 --- a/crashtracker-ffi/Cargo.toml +++ b/crashtracker-ffi/Cargo.toml @@ -28,6 +28,7 @@ anyhow = "1.0" datadog-crashtracker = { path = "../crashtracker" } ddcommon = { path = "../ddcommon" } ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false } +ddcommon-net1 = { path = "../ddcommon-net1" } hyper = {version = "0.14", features = ["backports", "deprecated"], default-features = false} symbolic-demangle = { version = "12.8.0", default-features = false, features = ["rust", "cpp", "msvc"], optional = true } symbolic-common = { version = "12.8.0", default-features = false, optional = true } diff --git a/crashtracker-ffi/src/collector/datatypes.rs b/crashtracker-ffi/src/collector/datatypes.rs index 847b910d0..9b33a71fd 100644 --- a/crashtracker-ffi/src/collector/datatypes.rs +++ b/crashtracker-ffi/src/collector/datatypes.rs @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 pub use datadog_crashtracker::{OpTypes, StacktraceCollection}; -use ddcommon::Endpoint; use ddcommon_ffi::slice::{AsBytes, CharSlice}; use ddcommon_ffi::{Error, Slice}; +use ddcommon_net1::Endpoint; #[repr(C)] pub struct EnvVar<'a> { diff --git a/crashtracker-ffi/src/crash_info/api.rs b/crashtracker-ffi/src/crash_info/api.rs index 4ced394f8..3814a9ea0 100644 --- a/crashtracker-ffi/src/crash_info/api.rs +++ b/crashtracker-ffi/src/crash_info/api.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use datadog_crashtracker::rfc5_crash_info::CrashInfo; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use ddcommon_ffi::{wrap_with_void_ffi_result, Handle, ToInner, VoidResult}; use function_name::named; diff --git a/crashtracker/Cargo.toml b/crashtracker/Cargo.toml index 085765102..32d958043 100644 --- a/crashtracker/Cargo.toml +++ b/crashtracker/Cargo.toml @@ -31,7 +31,8 @@ blazesym = "0.2.0-rc.2" anyhow = "1.0" backtrace = "0.3.74" chrono = {version = "0.4", default-features = false, features = ["std", "clock", "serde"]} -ddcommon = {path = "../ddcommon"} +ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } hyper = {version = "0.14", features = ["client", "backports", "deprecated"], default-features = false} libc = "0.2" nix = { version = "0.27.1", features = ["poll", "signal", "socket"] } diff --git a/crashtracker/src/collector/api.rs b/crashtracker/src/collector/api.rs index 5b5098e1b..b4fd9e373 100644 --- a/crashtracker/src/collector/api.rs +++ b/crashtracker/src/collector/api.rs @@ -98,7 +98,7 @@ fn test_crash() -> anyhow::Result<()> { use crate::{begin_op, StacktraceCollection}; use chrono::Utc; use ddcommon::tag; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; use std::time::Duration; let time = Utc::now().to_rfc3339(); @@ -165,7 +165,7 @@ fn test_crash() -> anyhow::Result<()> { fn test_altstack_paradox() -> anyhow::Result<()> { use crate::StacktraceCollection; use chrono::Utc; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; let time = Utc::now().to_rfc3339(); let dir = "/tmp/crashreports/"; @@ -224,7 +224,7 @@ fn test_altstack_use_create() -> anyhow::Result<()> { // taken. use crate::StacktraceCollection; use chrono::Utc; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; let time = Utc::now().to_rfc3339(); let dir = "/tmp/crashreports/"; @@ -351,7 +351,7 @@ fn test_altstack_use_nocreate() -> anyhow::Result<()> { // the main process state. use crate::StacktraceCollection; use chrono::Utc; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; let time = Utc::now().to_rfc3339(); let dir = "/tmp/crashreports/"; @@ -478,7 +478,7 @@ fn test_altstack_nouse() -> anyhow::Result<()> { // This checks that when we do not request the altstack, we do not get the altstack use crate::StacktraceCollection; use chrono::Utc; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; let time = Utc::now().to_rfc3339(); let dir = "/tmp/crashreports/"; @@ -640,7 +640,7 @@ fn test_waitall_nohang() -> anyhow::Result<()> { // options are used. use crate::StacktraceCollection; use chrono::Utc; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; let time = Utc::now().to_rfc3339(); let dir = "/tmp/crashreports/"; diff --git a/crashtracker/src/crash_info/mod.rs b/crashtracker/src/crash_info/mod.rs index 5c933a541..632c91f43 100644 --- a/crashtracker/src/crash_info/mod.rs +++ b/crashtracker/src/crash_info/mod.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 mod metadata; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; pub use metadata::*; mod stacktrace; pub use stacktrace::*; @@ -267,7 +267,7 @@ impl CrashInfo { // If we're debugging to a file, dump the actual crashinfo into a json if let Some(endpoint) = endpoint { if Some("file") == endpoint.url.scheme_str() { - let path = ddcommon::decode_uri_path_in_authority(&endpoint.url) + let path = ddcommon_net1::decode_uri_path_in_authority(&endpoint.url) .context("crash output file was not correctly formatted")?; self.to_file(&path)?; let new_path = path.with_extension("rfc5.json"); diff --git a/crashtracker/src/crash_info/telemetry.rs b/crashtracker/src/crash_info/telemetry.rs index fa58e7c1f..b1058d1b9 100644 --- a/crashtracker/src/crash_info/telemetry.rs +++ b/crashtracker/src/crash_info/telemetry.rs @@ -7,7 +7,7 @@ use std::time::SystemTime; use super::{CrashInfo, CrashtrackerMetadata, StackFrame}; use anyhow::{Context, Ok}; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use ddtelemetry::{ build_host, data::{self, Application, LogLevel}, @@ -72,7 +72,7 @@ impl TelemetryCrashUploader { // ignore result because what are we going to do? let _ = if endpoint.url.scheme_str() == Some("file") { - let path = ddcommon::decode_uri_path_in_authority(&endpoint.url) + let path = ddcommon_net1::decode_uri_path_in_authority(&endpoint.url) .context("file path is not valid")?; cfg.set_host_from_url(&format!("file://{}.telemetry", path.display())) } else { @@ -164,7 +164,7 @@ impl TelemetryCrashUploader { .method(http::Method::POST) .header( http::header::CONTENT_TYPE, - ddcommon::header::APPLICATION_JSON, + ddcommon_net1::header::APPLICATION_JSON, ) .header( ddtelemetry::worker::http_client::header::API_VERSION, @@ -216,11 +216,11 @@ mod tests { fs, }; + use super::TelemetryCrashUploader; use crate::SigInfo; use chrono::DateTime; - use ddcommon::{tag, Endpoint}; - - use super::TelemetryCrashUploader; + use ddcommon::tag; + use ddcommon_net1::Endpoint; fn new_test_uploader() -> TelemetryCrashUploader { TelemetryCrashUploader::new( diff --git a/crashtracker/src/rfc5_crash_info/mod.rs b/crashtracker/src/rfc5_crash_info/mod.rs index 68494d48a..a88f43c70 100644 --- a/crashtracker/src/rfc5_crash_info/mod.rs +++ b/crashtracker/src/rfc5_crash_info/mod.rs @@ -14,7 +14,7 @@ mod test_utils; mod unknown_value; pub use builder::*; -use ddcommon::Endpoint; +use ddcommon_net1::{decode_uri_path_in_authority, Endpoint}; pub use error_data::*; pub use metadata::Metadata; pub use os_info::*; @@ -167,7 +167,7 @@ impl CrashInfo { // If we're debugging to a file, dump the actual crashinfo into a json if let Some(endpoint) = endpoint { if Some("file") == endpoint.url.scheme_str() { - let path = ddcommon::decode_uri_path_in_authority(&endpoint.url) + let path = decode_uri_path_in_authority(&endpoint.url) .context("crash output file path was not correctly formatted")?; self.to_file(&path)?; } diff --git a/crashtracker/src/rfc5_crash_info/telemetry.rs b/crashtracker/src/rfc5_crash_info/telemetry.rs index 8d6376d6e..364f168ef 100644 --- a/crashtracker/src/rfc5_crash_info/telemetry.rs +++ b/crashtracker/src/rfc5_crash_info/telemetry.rs @@ -5,7 +5,7 @@ use std::{fmt::Write, time::SystemTime}; use super::{CrashInfo, Metadata}; use anyhow::{Context, Ok}; use chrono::{DateTime, Utc}; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use ddtelemetry::{ build_host, data::{self, Application, LogLevel}, @@ -57,7 +57,7 @@ impl TelemetryCrashUploader { // ignore result because what are we going to do? let _ = if endpoint.url.scheme_str() == Some("file") { - let path = ddcommon::decode_uri_path_in_authority(&endpoint.url) + let path = ddcommon_net1::decode_uri_path_in_authority(&endpoint.url) .context("file path is not valid")?; cfg.set_host_from_url(&format!("file://{}.telemetry", path.display())) } else { @@ -143,7 +143,7 @@ impl TelemetryCrashUploader { .method(http::Method::POST) .header( http::header::CONTENT_TYPE, - ddcommon::header::APPLICATION_JSON, + ddcommon_net1::header::APPLICATION_JSON, ) .header( ddtelemetry::worker::http_client::header::API_VERSION, @@ -212,7 +212,7 @@ fn extract_crash_info_tags(crash_info: &CrashInfo) -> anyhow::Result { mod tests { use super::TelemetryCrashUploader; use crate::rfc5_crash_info::{test_utils::TestInstance, CrashInfo, Metadata, StackTrace}; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; use std::{collections::HashSet, fs}; fn new_test_uploader(seed: u64) -> TelemetryCrashUploader { diff --git a/crashtracker/src/shared/configuration.rs b/crashtracker/src/shared/configuration.rs index 8decbe594..07a1151da 100644 --- a/crashtracker/src/shared/configuration.rs +++ b/crashtracker/src/shared/configuration.rs @@ -1,7 +1,7 @@ // Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 use crate::shared::constants; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use serde::{Deserialize, Serialize}; /// Stacktrace collection occurs in the context of a crashing process. diff --git a/data-pipeline/Cargo.toml b/data-pipeline/Cargo.toml index 5586311ef..e381bd7bb 100644 --- a/data-pipeline/Cargo.toml +++ b/data-pipeline/Cargo.toml @@ -23,6 +23,7 @@ either = "1.13.0" tokio = { version = "1.23", features = ["rt", "test-util", "time"], default-features = false } ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } datadog-trace-protobuf = { path = "../trace-protobuf" } datadog-trace-utils = { path = "../trace-utils" } datadog-trace-normalization = { path = "../trace-normalization" } diff --git a/data-pipeline/src/agent_info/fetcher.rs b/data-pipeline/src/agent_info/fetcher.rs index 895eb3621..a690cfd7f 100644 --- a/data-pipeline/src/agent_info/fetcher.rs +++ b/data-pipeline/src/agent_info/fetcher.rs @@ -6,7 +6,7 @@ use super::{schema::AgentInfo, AgentInfoArc}; use anyhow::{anyhow, Result}; use arc_swap::ArcSwapOption; -use ddcommon::{connector::Connector, Endpoint}; +use ddcommon_net1::{connector::Connector, Endpoint}; use hyper::body::HttpBody; use hyper::{self, body::Buf, header::HeaderName}; use log::{error, info}; @@ -69,7 +69,7 @@ pub async fn fetch_info_with_state( /// # #[tokio::main] /// # async fn main() -> Result<()> { /// // Define the endpoint -/// let endpoint = ddcommon::Endpoint::from_url("http://localhost:8126/info".parse().unwrap()); +/// let endpoint = ddcommon_net1::Endpoint::from_url("http://localhost:8126/info".parse().unwrap()); /// // Fetch the info /// let agent_info = data_pipeline::agent_info::fetch_info(&endpoint) /// .await @@ -98,7 +98,7 @@ pub async fn fetch_info(info_endpoint: &Endpoint) -> Result> { /// # #[tokio::main] /// # async fn main() -> Result<()> { /// // Define the endpoint -/// let endpoint = ddcommon::Endpoint::from_url("http://localhost:8126/info".parse().unwrap()); +/// let endpoint = ddcommon_net1::Endpoint::from_url("http://localhost:8126/info".parse().unwrap()); /// // Create the fetcher /// let fetcher = data_pipeline::agent_info::AgentInfoFetcher::new( /// endpoint, @@ -174,6 +174,7 @@ impl AgentInfoFetcher { #[cfg(test)] mod tests { use super::*; + use ddcommon_net1::Endpoint; use httpmock::prelude::*; const TEST_INFO: &str = r#"{ diff --git a/data-pipeline/src/stats_exporter.rs b/data-pipeline/src/stats_exporter.rs index fac027ef2..bb4a7a4c2 100644 --- a/data-pipeline/src/stats_exporter.rs +++ b/data-pipeline/src/stats_exporter.rs @@ -11,14 +11,13 @@ use std::{ time, }; +use crate::{span_concentrator::SpanConcentrator, trace_exporter::TracerMetadata}; use datadog_trace_protobuf::pb; -use ddcommon::{connector, Endpoint}; +use ddcommon_net1::{connector, Endpoint}; use hyper; use tokio::select; use tokio_util::sync::CancellationToken; -use crate::{span_concentrator::SpanConcentrator, trace_exporter::TracerMetadata}; - const STATS_ENDPOINT_PATH: &str = "/v0.6/stats"; /// An exporter that concentrates and sends stats to the agent @@ -29,7 +28,7 @@ pub struct StatsExporter { endpoint: Endpoint, meta: TracerMetadata, sequence_id: AtomicU64, - client: ddcommon::HttpClient, + client: ddcommon_net1::HttpClient, cancellation_token: CancellationToken, } @@ -89,7 +88,7 @@ impl StatsExporter { .into_request_builder(concat!("Libdatadog/", env!("CARGO_PKG_VERSION")))? .header( hyper::header::CONTENT_TYPE, - ddcommon::header::APPLICATION_MSGPACK, + ddcommon_net1::header::APPLICATION_MSGPACK, ) .method(hyper::Method::POST); @@ -188,6 +187,7 @@ pub fn stats_url_from_agent_url(agent_url: &str) -> anyhow::Result { mod tests { use super::*; use datadog_trace_utils::span_v04::{trace_utils, Span}; + use ddcommon_net1::Endpoint; use httpmock::prelude::*; use httpmock::MockServer; use time::Duration; diff --git a/data-pipeline/src/trace_exporter/mod.rs b/data-pipeline/src/trace_exporter/mod.rs index fc843e6af..1ff42a9ee 100644 --- a/data-pipeline/src/trace_exporter/mod.rs +++ b/data-pipeline/src/trace_exporter/mod.rs @@ -17,8 +17,9 @@ use datadog_trace_utils::span_v04::{ use datadog_trace_utils::trace_utils::{self, SendData, TracerHeaderTags}; use datadog_trace_utils::tracer_payload::TraceCollection; use datadog_trace_utils::{msgpack_decoder, tracer_payload}; +use ddcommon::tag; use ddcommon::tag::Tag; -use ddcommon::{connector, tag, Endpoint}; +use ddcommon_net1::{connector, Endpoint}; use dogstatsd_client::{new_flusher, Client, DogStatsDAction}; use either::Either; use hyper::body::HttpBody; diff --git a/data-pipeline/tests/test_fetch_info.rs b/data-pipeline/tests/test_fetch_info.rs index 260c30f6b..b12ba5504 100644 --- a/data-pipeline/tests/test_fetch_info.rs +++ b/data-pipeline/tests/test_fetch_info.rs @@ -6,7 +6,7 @@ mod tracing_integration_tests { use arc_swap::access::Access; use data_pipeline::agent_info::{fetch_info, AgentInfoFetcher}; use datadog_trace_utils::test_utils::datadog_test_agent::DatadogTestAgent; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; use std::time::Duration; #[cfg_attr(miri, ignore)] diff --git a/ddcommon-ffi/Cargo.toml b/ddcommon-ffi/Cargo.toml index e92eb51e1..2a5a1c9fa 100644 --- a/ddcommon-ffi/Cargo.toml +++ b/ddcommon-ffi/Cargo.toml @@ -23,6 +23,7 @@ anyhow = "1.0" chrono = { version = "0.4.38", features = ["std"] } crossbeam-queue = "0.3.11" ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } hyper = {version = "0.14", features = ["backports", "deprecated"], default-features = false} serde = "1.0" diff --git a/ddcommon-ffi/src/endpoint.rs b/ddcommon-ffi/src/endpoint.rs index 8bea28a7b..186ac9ff2 100644 --- a/ddcommon-ffi/src/endpoint.rs +++ b/ddcommon-ffi/src/endpoint.rs @@ -3,24 +3,41 @@ use crate::slice::AsBytes; use crate::Error; -use ddcommon::{parse_uri, Endpoint}; use hyper::http::uri::{Authority, Parts}; use std::borrow::Cow; use std::str::FromStr; +use ddcommon_net1 as net; +use net::parse_uri; + +/// Wrapper type to generate the correct FFI name. +pub struct Endpoint(net::Endpoint); + +impl From for Endpoint { + fn from(inner: net::Endpoint) -> Self { + Self(inner) + } +} + +impl From for net::Endpoint { + fn from(inner: Endpoint) -> Self { + inner.0 + } +} + #[no_mangle] #[must_use] pub extern "C" fn ddog_endpoint_from_url(url: crate::CharSlice) -> Option> { parse_uri(url.to_utf8_lossy().as_ref()) .ok() - .map(|url| Box::new(Endpoint::from_url(url))) + .map(|url| Box::new(net::Endpoint::from_url(url).into())) } #[no_mangle] #[must_use] pub extern "C" fn ddog_endpoint_from_filename(filename: crate::CharSlice) -> Option> { let url = format!("file://{}", filename.to_utf8_lossy()); - Some(Box::new(Endpoint::from_slice(&url))) + Some(Box::new(net::Endpoint::from_slice(&url).into())) } // We'll just specify the base site here. If api key provided, different intakes need to use their @@ -30,11 +47,14 @@ pub extern "C" fn ddog_endpoint_from_filename(filename: crate::CharSlice) -> Opt pub extern "C" fn ddog_endpoint_from_api_key(api_key: crate::CharSlice) -> Box { let mut parts = Parts::default(); parts.authority = Some(Authority::from_static("datadoghq.com")); - Box::new(Endpoint { - url: hyper::Uri::from_parts(parts).unwrap(), - api_key: Some(api_key.to_utf8_lossy().to_string().into()), - ..Default::default() - }) + Box::new( + net::Endpoint { + url: hyper::Uri::from_parts(parts).unwrap(), + api_key: Some(api_key.to_utf8_lossy().to_string().into()), + ..Default::default() + } + .into(), + ) } // We'll just specify the base site here. If api key provided, different intakes need to use their @@ -51,22 +71,25 @@ pub extern "C" fn ddog_endpoint_from_api_key_and_site( Ok(s) => s, Err(e) => return Some(Box::new(Error::from(e.to_string()))), }); - *endpoint = Box::into_raw(Box::new(Endpoint { - url: hyper::Uri::from_parts(parts).unwrap(), - api_key: Some(api_key.to_utf8_lossy().to_string().into()), - ..Default::default() - })); + *endpoint = Box::into_raw(Box::new( + net::Endpoint { + url: hyper::Uri::from_parts(parts).unwrap(), + api_key: Some(api_key.to_utf8_lossy().to_string().into()), + ..Default::default() + } + .into(), + )); None } #[no_mangle] extern "C" fn ddog_endpoint_set_timeout(endpoint: &mut Endpoint, millis: u64) { - endpoint.timeout_ms = millis; + endpoint.0.timeout_ms = millis; } #[no_mangle] extern "C" fn ddog_endpoint_set_test_token(endpoint: &mut Endpoint, token: crate::CharSlice) { - endpoint.test_token = if token.is_empty() { + endpoint.0.test_token = if token.is_empty() { None } else { Some(Cow::Owned(token.to_utf8_lossy().to_string())) @@ -80,6 +103,7 @@ pub extern "C" fn ddog_endpoint_drop(_: Box) {} mod tests { use super::*; use crate::CharSlice; + use net::Endpoint; #[test] fn test_ddog_endpoint_from_url() { @@ -110,18 +134,19 @@ mod tests { let url = CharSlice::from("http://127.0.0.1"); let mut endpoint = ddog_endpoint_from_url(url); - assert_eq!( - endpoint.as_ref().unwrap().timeout_ms, - Endpoint::DEFAULT_TIMEOUT - ); + let timeout_ms = endpoint.as_ref().unwrap().0.timeout_ms; + assert_eq!(timeout_ms, Endpoint::DEFAULT_TIMEOUT); ddog_endpoint_set_timeout(endpoint.as_mut().unwrap(), 2000); - assert_eq!(endpoint.unwrap().timeout_ms, 2000); + let timeout_ms = endpoint.as_ref().unwrap().0.timeout_ms; + assert_eq!(timeout_ms, 2000); let mut endpoint_api_key = ddog_endpoint_from_api_key(CharSlice::from("test-key")); - assert_eq!(endpoint_api_key.timeout_ms, Endpoint::DEFAULT_TIMEOUT); + let timeout_ms = endpoint_api_key.0.timeout_ms; + assert_eq!(timeout_ms, Endpoint::DEFAULT_TIMEOUT); ddog_endpoint_set_timeout(&mut endpoint_api_key, 2000); - assert_eq!(endpoint_api_key.timeout_ms, 2000); + let timeout_ms = endpoint_api_key.0.timeout_ms; + assert_eq!(timeout_ms, 2000); } } diff --git a/ddcommon-net1/Cargo.toml b/ddcommon-net1/Cargo.toml new file mode 100644 index 000000000..504b97562 --- /dev/null +++ b/ddcommon-net1/Cargo.toml @@ -0,0 +1,57 @@ +# Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ +# SPDX-License-Identifier: Apache-2.0 + +[package] +name = "ddcommon-net1" +rust-version.workspace = true +edition.workspace = true +version.workspace = true +license.workspace = true + +[lib] +bench = false + +[features] +default = [] +use_webpki_roots = ["hyper-rustls/webpki-roots"] + +[dependencies] +anyhow = "1" +ddcommon = { path = "../ddcommon" } +futures = "0.3" +futures-core = { version = "0.3.0", default-features = false } +futures-util = { version = "0.3.0", default-features = false } +hex = "0.4" +http = "0.2" +hyper = { version = "0.14", features = ["http1", "client", "tcp", "stream", "backports", "deprecated"], default-features = false } +hyper-util = "0.1" +lazy_static = "1.4" +pin-project = "1" +rustls = { version = "0.23", default-features = false } +rustls-native-certs = { version = "0.7" } +serde = { version = "1.0", features = ["derive"] } +tokio = { version = "1.23", features = ["rt", "macros"] } +tokio-rustls = { version = "0.26", default-features = false } + +[target.'cfg(windows)'.dependencies.windows-sys] +version = "0.52" +features = [ + "Win32_Foundation", + "Win32_System_Performance", +] + +[target.'cfg(unix)'.dependencies] +hyper-rustls = { version = "0.27", default-features = false, features = [ + "aws-lc-rs", + "http1", + "native-tokio", + "tls12", +] } + +[target.'cfg(not(unix))'.dependencies] +hyper-rustls = { version = "0.27", default-features = false, features = [ + "http1", + "native-tokio", + "ring", + "tls12", +] } diff --git a/ddcommon/src/connector/conn_stream.rs b/ddcommon-net1/src/connector/conn_stream.rs similarity index 100% rename from ddcommon/src/connector/conn_stream.rs rename to ddcommon-net1/src/connector/conn_stream.rs diff --git a/ddcommon/src/connector/errors.rs b/ddcommon-net1/src/connector/errors.rs similarity index 100% rename from ddcommon/src/connector/errors.rs rename to ddcommon-net1/src/connector/errors.rs diff --git a/ddcommon/src/connector/mod.rs b/ddcommon-net1/src/connector/mod.rs similarity index 100% rename from ddcommon/src/connector/mod.rs rename to ddcommon-net1/src/connector/mod.rs diff --git a/ddcommon/src/connector/named_pipe.rs b/ddcommon-net1/src/connector/named_pipe.rs similarity index 100% rename from ddcommon/src/connector/named_pipe.rs rename to ddcommon-net1/src/connector/named_pipe.rs diff --git a/ddcommon/src/connector/uds.rs b/ddcommon-net1/src/connector/uds.rs similarity index 100% rename from ddcommon/src/connector/uds.rs rename to ddcommon-net1/src/connector/uds.rs diff --git a/ddcommon-net1/src/lib.rs b/ddcommon-net1/src/lib.rs new file mode 100644 index 000000000..2dee51be8 --- /dev/null +++ b/ddcommon-net1/src/lib.rs @@ -0,0 +1,208 @@ +// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ +// SPDX-License-Identifier: Apache-2.0 + +use ddcommon::entity_id; +use http::{uri, HeaderValue}; +use serde::de::{Deserializer, Error}; +use serde::ser::Serializer; +use serde::{Deserialize, Serialize}; +use std::borrow::Cow; +use std::ops::Deref; +use std::path::PathBuf; +use std::str::FromStr; + +pub mod connector; + +pub type HttpClient = hyper::Client; +pub type HttpResponse = hyper::Response; +pub type HttpRequestBuilder = hyper::http::request::Builder; + +#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)] +pub struct Endpoint { + #[serde(serialize_with = "serialize_uri", deserialize_with = "deserialize_uri")] + pub url: hyper::Uri, + pub api_key: Option>, + pub timeout_ms: u64, + /// Sets X-Datadog-Test-Session-Token header on any request + pub test_token: Option>, +} + +impl Default for Endpoint { + fn default() -> Self { + Endpoint { + url: hyper::Uri::default(), + api_key: None, + timeout_ms: Self::DEFAULT_TIMEOUT, + test_token: None, + } + } +} + +#[derive(serde::Deserialize, serde::Serialize)] +struct SerializedUri<'a> { + scheme: Option>, + authority: Option>, + path_and_query: Option>, +} + +fn serialize_uri(uri: &hyper::Uri, serializer: S) -> Result +where + S: Serializer, +{ + let parts = uri.clone().into_parts(); + let uri = SerializedUri { + scheme: parts.scheme.as_ref().map(|s| Cow::Borrowed(s.as_str())), + authority: parts.authority.as_ref().map(|s| Cow::Borrowed(s.as_str())), + path_and_query: parts + .path_and_query + .as_ref() + .map(|s| Cow::Borrowed(s.as_str())), + }; + uri.serialize(serializer) +} + +fn deserialize_uri<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let uri = SerializedUri::deserialize(deserializer)?; + let mut builder = hyper::Uri::builder(); + if let Some(v) = uri.authority { + builder = builder.authority(v.deref()); + } + if let Some(v) = uri.scheme { + builder = builder.scheme(v.deref()); + } + if let Some(v) = uri.path_and_query { + builder = builder.path_and_query(v.deref()); + } + + builder.build().map_err(Error::custom) +} + +/// TODO: we should properly handle malformed urls +/// * For windows and unix schemes: +/// * For compatibility reasons with existing implementation this parser stores the encoded path +/// in authority section as there is no existing standard [see](https://github.com/whatwg/url/issues/577) +/// that covers this. We need to pick one hack or another +/// * For windows, interprets everything after windows: as path +/// * For unix, interprets everything after unix:// as path +/// * For file scheme implementation will simply backfill missing authority section +pub fn parse_uri(uri: &str) -> anyhow::Result { + if let Some(path) = uri.strip_prefix("unix://") { + encode_uri_path_in_authority("unix", path) + } else if let Some(path) = uri.strip_prefix("windows:") { + encode_uri_path_in_authority("windows", path) + } else if let Some(path) = uri.strip_prefix("file://") { + encode_uri_path_in_authority("file", path) + } else { + Ok(hyper::Uri::from_str(uri)?) + } +} + +fn encode_uri_path_in_authority(scheme: &str, path: &str) -> anyhow::Result { + let mut parts = uri::Parts::default(); + parts.scheme = uri::Scheme::from_str(scheme).ok(); + + let path = hex::encode(path); + + parts.authority = uri::Authority::from_str(path.as_str()).ok(); + parts.path_and_query = Some(uri::PathAndQuery::from_static("")); + Ok(hyper::Uri::from_parts(parts)?) +} + +pub fn decode_uri_path_in_authority(uri: &hyper::Uri) -> anyhow::Result { + let path = hex::decode( + uri.authority() + .ok_or_else(|| anyhow::anyhow!("missing uri authority"))? + .as_str(), + )?; + #[cfg(unix)] + { + use std::os::unix::ffi::OsStringExt; + Ok(PathBuf::from(std::ffi::OsString::from_vec(path))) + } + #[cfg(not(unix))] + { + match String::from_utf8(path) { + Ok(s) => Ok(PathBuf::from(s.as_str())), + _ => Err(anyhow::anyhow!("file uri should be utf-8")), + } + } +} + +impl Endpoint { + /// Default value for the timeout field in milliseconds. + pub const DEFAULT_TIMEOUT: u64 = 3_000; + + /// Return a request builder with the following headers: + /// - User agent + /// - Api key + /// - Container Id/Entity Id + pub fn into_request_builder(&self, user_agent: &str) -> anyhow::Result { + let mut builder = hyper::Request::builder() + .uri(self.url.clone()) + .header(hyper::header::USER_AGENT, user_agent); + + // Add the Api key header if available + if let Some(api_key) = &self.api_key { + builder = builder.header(header::DATADOG_API_KEY, HeaderValue::from_str(api_key)?); + } + + // Add the test session token if available + if let Some(token) = &self.test_token { + builder = builder.header( + header::X_DATADOG_TEST_SESSION_TOKEN, + HeaderValue::from_str(token)?, + ); + } + + // Add the Container Id header if available + if let Some(container_id) = entity_id::get_container_id() { + builder = builder.header(header::DATADOG_CONTAINER_ID, container_id); + } + + // Add the Entity Id header if available + if let Some(entity_id) = entity_id::get_entity_id() { + builder = builder.header(header::DATADOG_ENTITY_ID, entity_id); + } + + // Add the External Env header if available + if let Some(external_env) = entity_id::get_external_env() { + builder = builder.header(header::DATADOG_EXTERNAL_ENV, external_env); + } + + Ok(builder) + } + + #[inline] + pub fn from_slice(url: &str) -> Endpoint { + Endpoint { + url: parse_uri(url).unwrap(), + ..Default::default() + } + } + + #[inline] + pub fn from_url(url: hyper::Uri) -> Endpoint { + Endpoint { + url, + ..Default::default() + } + } +} + +pub mod header { + #![allow(clippy::declare_interior_mutable_const)] + use hyper::{header::HeaderName, http::HeaderValue}; + + pub const DATADOG_CONTAINER_ID: HeaderName = HeaderName::from_static("datadog-container-id"); + pub const DATADOG_ENTITY_ID: HeaderName = HeaderName::from_static("datadog-entity-id"); + pub const DATADOG_EXTERNAL_ENV: HeaderName = HeaderName::from_static("datadog-external-env"); + pub const DATADOG_TRACE_COUNT: HeaderName = HeaderName::from_static("x-datadog-trace-count"); + pub const DATADOG_API_KEY: HeaderName = HeaderName::from_static("dd-api-key"); + pub const APPLICATION_JSON: HeaderValue = HeaderValue::from_static("application/json"); + pub const APPLICATION_MSGPACK: HeaderValue = HeaderValue::from_static("application/msgpack"); + pub const X_DATADOG_TEST_SESSION_TOKEN: HeaderName = + HeaderName::from_static("x-datadog-test-session-token"); +} diff --git a/ddcommon/Cargo.toml b/ddcommon/Cargo.toml index df68d7e9d..2cca8a693 100644 --- a/ddcommon/Cargo.toml +++ b/ddcommon/Cargo.toml @@ -14,29 +14,9 @@ bench =false [dependencies] anyhow = "1.0" -futures = "0.3" -futures-core = { version = "0.3.0", default-features = false } -futures-util = { version = "0.3.0", default-features = false } -hex = "0.4" -http = "0.2" -hyper = { version = "0.14", features = [ - "http1", - "client", - "tcp", - "stream", - "backports", - "deprecated" -], default-features = false } cc = "1.1.31" -hyper-util = "0.1.3" lazy_static = "1.4" -log = { version = "0.4" } -pin-project = "1" regex = "1.5" -rustls = { version = "0.23", default-features = false } -rustls-native-certs = { version = "0.7" } -tokio = { version = "1.23", features = ["rt", "macros"] } -tokio-rustls = { version = "0.26", default-features = false } serde = { version = "1.0", features = ["derive"] } static_assertions = "1.1.0" libc = "0.2" @@ -48,29 +28,12 @@ features = [ "Win32_System_Performance", ] -[target.'cfg(unix)'.dependencies] -hyper-rustls = { version = "0.27", default-features = false, features = [ - "native-tokio", - "http1", - "tls12", - "aws-lc-rs", -] } - -[target.'cfg(not(unix))'.dependencies] -hyper-rustls = { version = "0.27", default-features = false, features = [ - "native-tokio", - "http1", - "tls12", - "ring", -] } - [dev-dependencies] indexmap = "2.2" maplit = "1.0" [features] default = [] -use_webpki_roots = ["hyper-rustls/webpki-roots"] # Enable this feature to enable stubbing of cgroup # php directly import this crate and uses functions gated by this feature for their test cgroup_testing = [] diff --git a/ddcommon/src/config.rs b/ddcommon/src/config.rs index 0019fd6b4..9518a4236 100644 --- a/ddcommon/src/config.rs +++ b/ddcommon/src/config.rs @@ -2,11 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 pub mod parse_env { - use http::Uri; use std::{env, str::FromStr, time::Duration}; - use crate::parse_uri; - pub fn duration(name: &str) -> Option { Some(Duration::from_secs_f32( env::var(name).ok()?.parse::().ok()?, @@ -25,8 +22,4 @@ pub mod parse_env { pub fn str_not_empty(name: &str) -> Option { env::var(name).ok().filter(|s| !s.is_empty()) } - - pub fn uri(name: &str) -> Option { - parse_uri(&str_not_empty(name)?).ok() - } } diff --git a/ddcommon/src/lib.rs b/ddcommon/src/lib.rs index c0243ed02..fe48f82ed 100644 --- a/ddcommon/src/lib.rs +++ b/ddcommon/src/lib.rs @@ -1,213 +1,10 @@ // Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -use std::{borrow::Cow, ops::Deref, path::PathBuf, str::FromStr}; - -use hyper::{ - header::HeaderValue, - http::uri::{self}, -}; -use serde::de::Error; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; - pub mod azure_app_services; -pub mod connector; pub mod entity_id; #[macro_use] pub mod cstr; pub mod config; pub mod rate_limiter; pub mod tag; - -pub mod header { - #![allow(clippy::declare_interior_mutable_const)] - use hyper::{header::HeaderName, http::HeaderValue}; - pub const DATADOG_CONTAINER_ID: HeaderName = HeaderName::from_static("datadog-container-id"); - pub const DATADOG_ENTITY_ID: HeaderName = HeaderName::from_static("datadog-entity-id"); - pub const DATADOG_EXTERNAL_ENV: HeaderName = HeaderName::from_static("datadog-external-env"); - pub const DATADOG_TRACE_COUNT: HeaderName = HeaderName::from_static("x-datadog-trace-count"); - pub const DATADOG_API_KEY: HeaderName = HeaderName::from_static("dd-api-key"); - pub const APPLICATION_JSON: HeaderValue = HeaderValue::from_static("application/json"); - pub const APPLICATION_MSGPACK: HeaderValue = HeaderValue::from_static("application/msgpack"); - pub const X_DATADOG_TEST_SESSION_TOKEN: HeaderName = - HeaderName::from_static("x-datadog-test-session-token"); -} - -pub type HttpClient = hyper::Client; -pub type HttpResponse = hyper::Response; -pub type HttpRequestBuilder = hyper::http::request::Builder; - -#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)] -pub struct Endpoint { - #[serde(serialize_with = "serialize_uri", deserialize_with = "deserialize_uri")] - pub url: hyper::Uri, - pub api_key: Option>, - pub timeout_ms: u64, - /// Sets X-Datadog-Test-Session-Token header on any request - pub test_token: Option>, -} - -impl Default for Endpoint { - fn default() -> Self { - Endpoint { - url: hyper::Uri::default(), - api_key: None, - timeout_ms: Self::DEFAULT_TIMEOUT, - test_token: None, - } - } -} - -#[derive(serde::Deserialize, serde::Serialize)] -struct SerializedUri<'a> { - scheme: Option>, - authority: Option>, - path_and_query: Option>, -} - -fn serialize_uri(uri: &hyper::Uri, serializer: S) -> Result -where - S: Serializer, -{ - let parts = uri.clone().into_parts(); - let uri = SerializedUri { - scheme: parts.scheme.as_ref().map(|s| Cow::Borrowed(s.as_str())), - authority: parts.authority.as_ref().map(|s| Cow::Borrowed(s.as_str())), - path_and_query: parts - .path_and_query - .as_ref() - .map(|s| Cow::Borrowed(s.as_str())), - }; - uri.serialize(serializer) -} - -fn deserialize_uri<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let uri = SerializedUri::deserialize(deserializer)?; - let mut builder = hyper::Uri::builder(); - if let Some(v) = uri.authority { - builder = builder.authority(v.deref()); - } - if let Some(v) = uri.scheme { - builder = builder.scheme(v.deref()); - } - if let Some(v) = uri.path_and_query { - builder = builder.path_and_query(v.deref()); - } - - builder.build().map_err(Error::custom) -} - -/// TODO: we should properly handle malformed urls -/// * For windows and unix schemes: -/// * For compatibility reasons with existing implementation this parser stores the encoded path -/// in authority section as there is no existing standard [see](https://github.com/whatwg/url/issues/577) -/// that covers this. We need to pick one hack or another -/// * For windows, interprets everything after windows: as path -/// * For unix, interprets everything after unix:// as path -/// * For file scheme implementation will simply backfill missing authority section -pub fn parse_uri(uri: &str) -> anyhow::Result { - if let Some(path) = uri.strip_prefix("unix://") { - encode_uri_path_in_authority("unix", path) - } else if let Some(path) = uri.strip_prefix("windows:") { - encode_uri_path_in_authority("windows", path) - } else if let Some(path) = uri.strip_prefix("file://") { - encode_uri_path_in_authority("file", path) - } else { - Ok(hyper::Uri::from_str(uri)?) - } -} - -fn encode_uri_path_in_authority(scheme: &str, path: &str) -> anyhow::Result { - let mut parts = uri::Parts::default(); - parts.scheme = uri::Scheme::from_str(scheme).ok(); - - let path = hex::encode(path); - - parts.authority = uri::Authority::from_str(path.as_str()).ok(); - parts.path_and_query = Some(uri::PathAndQuery::from_static("")); - Ok(hyper::Uri::from_parts(parts)?) -} - -pub fn decode_uri_path_in_authority(uri: &hyper::Uri) -> anyhow::Result { - let path = hex::decode( - uri.authority() - .ok_or_else(|| anyhow::anyhow!("missing uri authority"))? - .as_str(), - )?; - #[cfg(unix)] - { - use std::os::unix::ffi::OsStringExt; - Ok(PathBuf::from(std::ffi::OsString::from_vec(path))) - } - #[cfg(not(unix))] - { - match String::from_utf8(path) { - Ok(s) => Ok(PathBuf::from(s.as_str())), - _ => Err(anyhow::anyhow!("file uri should be utf-8")), - } - } -} - -impl Endpoint { - /// Default value for the timeout field in milliseconds. - pub const DEFAULT_TIMEOUT: u64 = 3_000; - - /// Return a request builder with the following headers: - /// - User agent - /// - Api key - /// - Container Id/Entity Id - pub fn into_request_builder(&self, user_agent: &str) -> anyhow::Result { - let mut builder = hyper::Request::builder() - .uri(self.url.clone()) - .header(hyper::header::USER_AGENT, user_agent); - - // Add the Api key header if available - if let Some(api_key) = &self.api_key { - builder = builder.header(header::DATADOG_API_KEY, HeaderValue::from_str(api_key)?); - } - - // Add the test session token if available - if let Some(token) = &self.test_token { - builder = builder.header( - header::X_DATADOG_TEST_SESSION_TOKEN, - HeaderValue::from_str(token)?, - ); - } - - // Add the Container Id header if available - if let Some(container_id) = entity_id::get_container_id() { - builder = builder.header(header::DATADOG_CONTAINER_ID, container_id); - } - - // Add the Entity Id header if available - if let Some(entity_id) = entity_id::get_entity_id() { - builder = builder.header(header::DATADOG_ENTITY_ID, entity_id); - } - - // Add the External Env header if available - if let Some(external_env) = entity_id::get_external_env() { - builder = builder.header(header::DATADOG_EXTERNAL_ENV, external_env); - } - - Ok(builder) - } - - #[inline] - pub fn from_slice(url: &str) -> Endpoint { - Endpoint { - url: parse_uri(url).unwrap(), - ..Default::default() - } - } - - #[inline] - pub fn from_url(url: hyper::Uri) -> Endpoint { - Endpoint { - url, - ..Default::default() - } - } -} diff --git a/ddtelemetry-ffi/Cargo.toml b/ddtelemetry-ffi/Cargo.toml index fc7255975..0875107cd 100644 --- a/ddtelemetry-ffi/Cargo.toml +++ b/ddtelemetry-ffi/Cargo.toml @@ -24,6 +24,7 @@ build_common = { path = "../build-common" } ddtelemetry = { path = "../ddtelemetry" } ddcommon = { path = "../ddcommon" } ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false } +ddcommon-net1 = { path = "../ddcommon-net1" } paste = "1" libc = "0.2" diff --git a/ddtelemetry-ffi/src/builder/expanded.rs b/ddtelemetry-ffi/src/builder/expanded.rs index a15784514..fcfe35146 100644 --- a/ddtelemetry-ffi/src/builder/expanded.rs +++ b/ddtelemetry-ffi/src/builder/expanded.rs @@ -3,8 +3,8 @@ pub use macros::*; mod macros { - use ddcommon::Endpoint; use ddcommon_ffi as ffi; + use ddcommon_net1::Endpoint; use ddtelemetry::worker::TelemetryWorkerBuilder; use ffi::slice::AsBytes; #[no_mangle] diff --git a/ddtelemetry-ffi/src/builder/macros.rs b/ddtelemetry-ffi/src/builder/macros.rs index de4fa05ce..2dd9070df 100644 --- a/ddtelemetry-ffi/src/builder/macros.rs +++ b/ddtelemetry-ffi/src/builder/macros.rs @@ -9,8 +9,8 @@ // sed 's/::alloc::fmt::format/std::fmt::format/' >> $EXPANDED && cargo fmt // ``` -use ddcommon::Endpoint; use ddcommon_ffi as ffi; +use ddcommon_net1::Endpoint; use ddtelemetry::worker::TelemetryWorkerBuilder; use ffi::slice::AsBytes; diff --git a/ddtelemetry-ffi/src/lib.rs b/ddtelemetry-ffi/src/lib.rs index bc8c6aac2..4509ba688 100644 --- a/ddtelemetry-ffi/src/lib.rs +++ b/ddtelemetry-ffi/src/lib.rs @@ -107,8 +107,8 @@ pub(crate) use c_setters; #[cfg(test)] mod tests { use crate::{builder::*, worker_handle::*}; - use ddcommon::Endpoint; use ddcommon_ffi as ffi; + use ddcommon_net1::Endpoint; use ddtelemetry::{ data::metrics::{MetricNamespace, MetricType}, worker::{TelemetryWorkerBuilder, TelemetryWorkerHandle}, diff --git a/ddtelemetry/Cargo.toml b/ddtelemetry/Cargo.toml index d6a790e73..f3fbd0998 100644 --- a/ddtelemetry/Cargo.toml +++ b/ddtelemetry/Cargo.toml @@ -16,6 +16,7 @@ tracing = ["tracing/std"] [dependencies] anyhow = { version = "1.0" } ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } datadog-ddsketch = { path = "../ddsketch" } base64 = "0.22" futures = { version = "0.3", default-features = false } diff --git a/ddtelemetry/examples/tm-metrics-worker-test.rs b/ddtelemetry/examples/tm-metrics-worker-test.rs index 9f6a795b6..1367479d4 100644 --- a/ddtelemetry/examples/tm-metrics-worker-test.rs +++ b/ddtelemetry/examples/tm-metrics-worker-test.rs @@ -33,7 +33,7 @@ fn main() -> Result<(), Box> { "none".into(), ); builder.config.telemetry_debug_logging_enabled = Some(true); - builder.config.endpoint = Some(ddcommon::Endpoint::from_slice( + builder.config.endpoint = Some(ddcommon_net1::Endpoint::from_slice( "file://./tm-metrics-worker-test.output", )); builder.config.telemetry_hearbeat_interval = Some(Duration::from_secs(1)); diff --git a/ddtelemetry/examples/tm-ping.rs b/ddtelemetry/examples/tm-ping.rs index cbea147f4..d8f9b1b90 100644 --- a/ddtelemetry/examples/tm-ping.rs +++ b/ddtelemetry/examples/tm-ping.rs @@ -47,7 +47,7 @@ pub async fn push_telemetry(telemetry: &Telemetry<'_>) -> anyhow::Result<()> { let client = ddtelemetry::worker::http_client::from_config(config); let req = request_builder(config)? .method(http::Method::POST) - .header(CONTENT_TYPE, ddcommon::header::APPLICATION_JSON) + .header(CONTENT_TYPE, ddcommon_net1::header::APPLICATION_JSON) .body(serde_json::to_string(telemetry)?.into())?; let resp = client.request(req).await?; diff --git a/ddtelemetry/examples/tm-send-sketch.rs b/ddtelemetry/examples/tm-send-sketch.rs index ee4bfe464..a0eeb5fbe 100644 --- a/ddtelemetry/examples/tm-send-sketch.rs +++ b/ddtelemetry/examples/tm-send-sketch.rs @@ -9,7 +9,7 @@ use std::{ time::SystemTime, }; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use ddtelemetry::{ build_host, config::Config, @@ -44,7 +44,7 @@ pub async fn push_telemetry(config: &Config, telemetry: &Telemetry<'_>) -> anyho let client = ddtelemetry::worker::http_client::from_config(config); let req = request_builder(config)? .method(http::Method::POST) - .header(CONTENT_TYPE, ddcommon::header::APPLICATION_JSON) + .header(CONTENT_TYPE, ddcommon_net1::header::APPLICATION_JSON) .header("dd-telemetry-debug-enabled", "true") .body(serde_json::to_string(telemetry)?.into())?; diff --git a/ddtelemetry/examples/tm-worker-test.rs b/ddtelemetry/examples/tm-worker-test.rs index 9cbcedb71..31ca1d27c 100644 --- a/ddtelemetry/examples/tm-worker-test.rs +++ b/ddtelemetry/examples/tm-worker-test.rs @@ -36,8 +36,8 @@ fn main() -> Result<(), Box> { "none".into(), ); builder.config.telemetry_debug_logging_enabled = Some(true); - builder.config.endpoint = Some(ddcommon::Endpoint { - url: ddcommon::parse_uri("file://./tm-worker-test.output").unwrap(), + builder.config.endpoint = Some(ddcommon_net1::Endpoint { + url: ddcommon_net1::parse_uri("file://./tm-worker-test.output").unwrap(), ..Default::default() }); builder.config.telemetry_hearbeat_interval = Some(Duration::from_secs(1)); diff --git a/ddtelemetry/src/config.rs b/ddtelemetry/src/config.rs index 882612382..f72271b6c 100644 --- a/ddtelemetry/src/config.rs +++ b/ddtelemetry/src/config.rs @@ -1,9 +1,10 @@ // Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -use ddcommon::{config::parse_env, parse_uri, Endpoint}; +use ddcommon::config::parse_env; use std::{borrow::Cow, time::Duration}; +use ddcommon_net1::{parse_uri, Endpoint}; use http::{uri::PathAndQuery, Uri}; use lazy_static::lazy_static; @@ -272,14 +273,12 @@ impl Config { #[cfg(test)] mod tests { + use super::{Config, Settings}; + use ddcommon_net1::connector::named_pipe; use std::path::Path; #[cfg(unix)] - use ddcommon::connector::uds; - - use ddcommon::connector::named_pipe; - - use super::{Config, Settings}; + use ddcommon_net1::connector::uds; #[test] fn test_agent_host_detection_trace_agent_url_should_take_precedence() { @@ -417,7 +416,7 @@ mod tests { ); assert_eq!( Path::new(expected), - ddcommon::decode_uri_path_in_authority(&cfg.endpoint.unwrap().url).unwrap(), + ddcommon_net1::decode_uri_path_in_authority(&cfg.endpoint.unwrap().url).unwrap(), ); } } diff --git a/ddtelemetry/src/worker/builder.rs b/ddtelemetry/src/worker/builder.rs index 37afda72f..b3d90cfa0 100644 --- a/ddtelemetry/src/worker/builder.rs +++ b/ddtelemetry/src/worker/builder.rs @@ -4,7 +4,7 @@ use std::time::Duration; use crate::config::Config; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; #[derive(Default, Debug)] pub struct ConfigBuilder { diff --git a/ddtelemetry/src/worker/http_client.rs b/ddtelemetry/src/worker/http_client.rs index d1a42447b..79f522885 100644 --- a/ddtelemetry/src/worker/http_client.rs +++ b/ddtelemetry/src/worker/http_client.rs @@ -1,7 +1,7 @@ // Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -use ddcommon::HttpRequestBuilder; +use ddcommon_net1::{connector, HttpRequestBuilder}; use http::{Request, Response}; use hyper::body::HttpBody; use hyper::Body; @@ -43,7 +43,7 @@ pub fn request_builder(c: &Config) -> anyhow::Result { pub fn from_config(c: &Config) -> Box { match &c.endpoint { Some(e) if e.url.scheme_str() == Some("file") => { - let file_path = ddcommon::decode_uri_path_in_authority(&e.url) + let file_path = ddcommon_net1::decode_uri_path_in_authority(&e.url) .expect("file urls should always have been encoded in authority"); return Box::new(MockClient { file: Arc::new(Mutex::new(Box::new( @@ -60,12 +60,12 @@ pub fn from_config(c: &Config) -> Box { Box::new(HyperClient { inner: hyper::Client::builder() .pool_idle_timeout(std::time::Duration::from_secs(30)) - .build(ddcommon::connector::Connector::default()), + .build(connector::Connector::default()), }) } pub struct HyperClient { - inner: ddcommon::HttpClient, + inner: ddcommon_net1::HttpClient, } impl HttpClient for HyperClient { @@ -101,7 +101,7 @@ impl HttpClient for MockClient { #[cfg(test)] mod tests { - use ddcommon::HttpRequestBuilder; + use ddcommon_net1::HttpRequestBuilder; use super::*; diff --git a/ddtelemetry/src/worker/mod.rs b/ddtelemetry/src/worker/mod.rs index 0cbab21a0..0b76f2085 100644 --- a/ddtelemetry/src/worker/mod.rs +++ b/ddtelemetry/src/worker/mod.rs @@ -13,7 +13,7 @@ use crate::{ worker::builder::ConfigBuilder, }; use ddcommon::tag::Tag; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use std::iter::Sum; use std::ops::Add; @@ -176,7 +176,7 @@ mod serialize { use crate::data; use http::HeaderValue; #[allow(clippy::declare_interior_mutable_const)] - pub const CONTENT_TYPE_VALUE: HeaderValue = ddcommon::header::APPLICATION_JSON; + pub const CONTENT_TYPE_VALUE: HeaderValue = ddcommon_net1::header::APPLICATION_JSON; pub fn serialize(telemetry: &data::Telemetry) -> anyhow::Result> { Ok(serde_json::to_vec(telemetry)?) } diff --git a/dogstatsd-client/Cargo.toml b/dogstatsd-client/Cargo.toml index cc50c2122..611dc6fca 100644 --- a/dogstatsd-client/Cargo.toml +++ b/dogstatsd-client/Cargo.toml @@ -11,6 +11,7 @@ bench = false [dependencies] ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } datadog-trace-protobuf = { path = "../trace-protobuf" } datadog-trace-normalization = { path = "../trace-normalization" } datadog-ddsketch = { path = "../ddsketch"} diff --git a/dogstatsd-client/src/lib.rs b/dogstatsd-client/src/lib.rs index ffa186aa8..5c7533c98 100644 --- a/dogstatsd-client/src/lib.rs +++ b/dogstatsd-client/src/lib.rs @@ -5,20 +5,20 @@ //! dogstatsd-client implements a client to emit metrics to a dogstatsd server. //! This is made use of in at least the data-pipeline and sidecar crates. +use anyhow::anyhow; +use cadence::prelude::*; +use cadence::{Metric, MetricBuilder, QueuingMetricSink, StatsdClient, UdpMetricSink}; use ddcommon::tag::Tag; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use serde::{Deserialize, Serialize}; use std::fmt::Debug; +use std::net::{ToSocketAddrs, UdpSocket}; use tracing::{debug, error, info}; -use anyhow::anyhow; -use cadence::prelude::*; #[cfg(unix)] use cadence::UnixMetricSink; -use cadence::{Metric, MetricBuilder, QueuingMetricSink, StatsdClient, UdpMetricSink}; #[cfg(unix)] -use ddcommon::connector::uds::socket_path_from_uri; -use std::net::{ToSocketAddrs, UdpSocket}; +use ddcommon_net1::connector::uds::socket_path_from_uri; #[cfg(unix)] use std::os::unix::net::UnixDatagram; @@ -228,15 +228,17 @@ fn create_client(endpoint: &Endpoint) -> anyhow::Result { #[cfg(test)] mod test { + use super::*; use crate::DogStatsDAction::{Count, Distribution, Gauge, Histogram, Set}; use crate::{create_client, new_flusher, DogStatsDActionOwned}; + use ddcommon::tag; + use std::net; + use std::time::Duration; + #[cfg(unix)] - use ddcommon::connector::uds::socket_path_to_uri; - use ddcommon::{tag, Endpoint}; + use ddcommon_net1::connector::uds::socket_path_to_uri; #[cfg(unix)] use http::Uri; - use std::net; - use std::time::Duration; #[test] #[cfg_attr(miri, ignore)] diff --git a/live-debugger-ffi/Cargo.toml b/live-debugger-ffi/Cargo.toml index c6397fb04..abf49c689 100644 --- a/live-debugger-ffi/Cargo.toml +++ b/live-debugger-ffi/Cargo.toml @@ -13,6 +13,7 @@ bench = false [dependencies] datadog-live-debugger = { path = "../live-debugger" } ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false } percent-encoding = "2.1" uuid = { version = "1.7.0", features = ["v4"] } diff --git a/live-debugger-ffi/src/sender.rs b/live-debugger-ffi/src/sender.rs index 2a7057ad0..edb28589d 100644 --- a/live-debugger-ffi/src/sender.rs +++ b/live-debugger-ffi/src/sender.rs @@ -6,9 +6,9 @@ use datadog_live_debugger::debugger_defs::DebuggerPayload; use datadog_live_debugger::sender; use datadog_live_debugger::sender::{generate_tags, Config, DebuggerType}; use ddcommon::tag::Tag; -use ddcommon::Endpoint; use ddcommon_ffi::slice::AsBytes; use ddcommon_ffi::{CharSlice, MaybeError}; +use ddcommon_net1::Endpoint; use log::{debug, warn}; use percent_encoding::{percent_encode, CONTROLS}; use std::sync::Arc; diff --git a/live-debugger/Cargo.toml b/live-debugger/Cargo.toml index 501671208..415b61055 100644 --- a/live-debugger/Cargo.toml +++ b/live-debugger/Cargo.toml @@ -7,6 +7,7 @@ version = "0.0.1" [dependencies] anyhow = "1.0" ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } lazy_static = "1.4" hyper = { version = "0.14", features = ["client", "backports", "deprecated"] } regex = "1.9.3" diff --git a/live-debugger/src/sender.rs b/live-debugger/src/sender.rs index da3bbf12d..9fed4bcc5 100644 --- a/live-debugger/src/sender.rs +++ b/live-debugger/src/sender.rs @@ -3,9 +3,8 @@ use crate::debugger_defs::{DebuggerData, DebuggerPayload}; use constcat::concat; -use ddcommon::connector::Connector; use ddcommon::tag::Tag; -use ddcommon::Endpoint; +use ddcommon_net1::{connector::Connector, Endpoint}; use hyper::body::{Bytes, HttpBody, Sender}; use hyper::client::ResponseFuture; use hyper::http::uri::PathAndQuery; diff --git a/profiling-ffi/Cargo.toml b/profiling-ffi/Cargo.toml index 570a68e39..e46330bb8 100644 --- a/profiling-ffi/Cargo.toml +++ b/profiling-ffi/Cargo.toml @@ -36,8 +36,9 @@ anyhow = "1.0" datadog-crashtracker-ffi = { path = "../crashtracker-ffi", default-features = false, optional = true} datadog-profiling = { path = "../profiling" } hyper = { version = "0.14", features = ["backports", "deprecated"], default-features = false } -ddcommon = { path = "../ddcommon"} +ddcommon = { path = "../ddcommon" } ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false } +ddcommon-net1 = { path = "../ddcommon-net1" } ddtelemetry-ffi = { path = "../ddtelemetry-ffi", default-features = false, optional = true, features = ["expanded_builder_macros"] } libc = "0.2" tokio-util = "0.7.1" diff --git a/profiling-ffi/src/exporter.rs b/profiling-ffi/src/exporter.rs index 8f9ea79a3..bba105f39 100644 --- a/profiling-ffi/src/exporter.rs +++ b/profiling-ffi/src/exporter.rs @@ -106,7 +106,9 @@ unsafe fn try_to_url(slice: CharSlice) -> anyhow::Result { Ok(hyper::Uri::from_str(str)?) } -pub unsafe fn try_to_endpoint(endpoint: ProfilingEndpoint) -> anyhow::Result { +pub unsafe fn try_to_endpoint( + endpoint: ProfilingEndpoint, +) -> anyhow::Result { // convert to utf8 losslessly -- URLs and API keys should all be ASCII, so // a failed result is likely to be an error. match endpoint { diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index 667bb8bcb..048d7cc81 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -23,7 +23,8 @@ bitmaps = "3.2.0" bytes = "1.1" chrono = {version = "0.4", default-features = false, features = ["std", "clock"]} datadog-alloc = {path = "../alloc"} -ddcommon = {path = "../ddcommon"} +ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } derivative = "2.2.0" futures = { version = "0.3", default-features = false } futures-core = {version = "0.3.0", default-features = false} diff --git a/profiling/src/exporter/config.rs b/profiling/src/exporter/config.rs index affb49d2a..51a71b8bd 100644 --- a/profiling/src/exporter/config.rs +++ b/profiling/src/exporter/config.rs @@ -1,17 +1,18 @@ // Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -#[cfg(unix)] -use ddcommon::connector::uds; -use ddcommon::Endpoint; - -#[cfg(windows)] -use ddcommon::connector::named_pipe; - use http::Uri; use std::borrow::Cow; use std::str::FromStr; +use ddcommon_net1::Endpoint; + +#[cfg(unix)] +use ddcommon_net1::connector::uds; + +#[cfg(windows)] +use ddcommon_net1::connector::named_pipe; + /// Creates an Endpoint for talking to the Datadog agent. /// /// # Arguments diff --git a/profiling/src/exporter/mod.rs b/profiling/src/exporter/mod.rs index 14c985109..57d97ee91 100644 --- a/profiling/src/exporter/mod.rs +++ b/profiling/src/exporter/mod.rs @@ -1,24 +1,27 @@ // Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -use std::borrow::Cow; -use std::future; -use std::io::{Cursor, Write}; +pub mod config; + +mod errors; use bytes::Bytes; -pub use chrono::{DateTime, Utc}; -pub use ddcommon::tag::Tag; -pub use hyper::Uri; use hyper_multipart_rfc7578::client::multipart; use lz4_flex::frame::FrameEncoder; use serde_json::json; +use std::borrow::Cow; +use std::future; +use std::io::{Cursor, Write}; use tokio::runtime::Runtime; use tokio_util::sync::CancellationToken; -use ddcommon::{azure_app_services, connector, Endpoint, HttpClient, HttpResponse}; +use crate::internal::ProfiledEndpointsStats; +use ddcommon::azure_app_services; +use ddcommon_net1::{connector, Endpoint, HttpClient, HttpResponse}; -pub mod config; -mod errors; +pub use chrono::{DateTime, Utc}; +pub use ddcommon::tag::Tag; +pub use hyper::Uri; #[cfg(unix)] pub use connector::uds::{socket_path_from_uri, socket_path_to_uri}; @@ -26,8 +29,6 @@ pub use connector::uds::{socket_path_from_uri, socket_path_to_uri}; #[cfg(windows)] pub use connector::named_pipe::{named_pipe_path_from_uri, named_pipe_path_to_uri}; -use crate::internal::ProfiledEndpointsStats; - const DURATION_ZERO: std::time::Duration = std::time::Duration::from_millis(0); pub struct Exporter { diff --git a/remote-config/Cargo.toml b/remote-config/Cargo.toml index cce5fc6b2..f9220970a 100644 --- a/remote-config/Cargo.toml +++ b/remote-config/Cargo.toml @@ -10,6 +10,7 @@ test = [] [dependencies] anyhow = { version = "1.0" } ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } datadog-dynamic-configuration = { path = "../dynamic-configuration" } datadog-trace-protobuf = { path = "../trace-protobuf" } datadog-live-debugger = { path = "../live-debugger" } diff --git a/remote-config/examples/remote_config_fetch.rs b/remote-config/examples/remote_config_fetch.rs index 7158ab925..1ea6b3431 100644 --- a/remote-config/examples/remote_config_fetch.rs +++ b/remote-config/examples/remote_config_fetch.rs @@ -7,7 +7,7 @@ use datadog_remote_config::file_storage::ParsedFileStorage; use datadog_remote_config::RemoteConfigProduct::ApmTracing; use datadog_remote_config::{RemoteConfigData, Target}; use ddcommon::tag::Tag; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use std::time::Duration; use tokio::time::sleep; diff --git a/remote-config/src/fetch/fetcher.rs b/remote-config/src/fetch/fetcher.rs index fefe0c40f..a863e66d2 100644 --- a/remote-config/src/fetch/fetcher.rs +++ b/remote-config/src/fetch/fetcher.rs @@ -11,7 +11,7 @@ use datadog_trace_protobuf::remoteconfig::{ ClientGetConfigsRequest, ClientGetConfigsResponse, ClientState, ClientTracer, ConfigState, TargetFileHash, TargetFileMeta, }; -use ddcommon::{connector, Endpoint}; +use ddcommon_net1::{connector, Endpoint}; use http::uri::Scheme; use hyper::body::HttpBody; use hyper::http::uri::PathAndQuery; @@ -308,7 +308,7 @@ impl ConfigFetcher { .method(http::Method::POST) .header( http::header::CONTENT_TYPE, - ddcommon::header::APPLICATION_JSON, + ddcommon_net1::header::APPLICATION_JSON, ) .body(serde_json::to_string(&config_req)?)?; let response = tokio::time::timeout( diff --git a/remote-config/src/fetch/test_server.rs b/remote-config/src/fetch/test_server.rs index 0e6804f11..2ed9cbe78 100644 --- a/remote-config/src/fetch/test_server.rs +++ b/remote-config/src/fetch/test_server.rs @@ -8,7 +8,7 @@ use base64::Engine; use datadog_trace_protobuf::remoteconfig::{ ClientGetConfigsRequest, ClientGetConfigsResponse, File, }; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use http::{Request, Response}; use hyper::body::HttpBody; use hyper::service::{make_service_fn, service_fn}; diff --git a/sidecar-ffi/Cargo.toml b/sidecar-ffi/Cargo.toml index c30f0c1be..f32e84c24 100644 --- a/sidecar-ffi/Cargo.toml +++ b/sidecar-ffi/Cargo.toml @@ -17,6 +17,7 @@ datadog-trace-utils = { path = "../trace-utils" } datadog-ipc = { path = "../ipc" } ddcommon = { path = "../ddcommon" } ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false } +ddcommon-net1 = { path = "../ddcommon-net1" } ddtelemetry-ffi = { path = "../ddtelemetry-ffi", default-features = false } datadog-remote-config = { path = "../remote-config" } datadog-live-debugger = { path = "../live-debugger" } diff --git a/sidecar-ffi/src/lib.rs b/sidecar-ffi/src/lib.rs index ebf359e3b..2efa102cc 100644 --- a/sidecar-ffi/src/lib.rs +++ b/sidecar-ffi/src/lib.rs @@ -21,9 +21,9 @@ use datadog_sidecar::service::{ }; use datadog_sidecar::shm_remote_config::{path_for_remote_config, RemoteConfigReader}; use ddcommon::tag::Tag; -use ddcommon::Endpoint; use ddcommon_ffi as ffi; use ddcommon_ffi::{CharSlice, MaybeError}; +use ddcommon_net1::Endpoint; use ddtelemetry::{ data::{self, Dependency, Integration}, worker::{LifecycleAction, TelemetryActions}, diff --git a/sidecar-ffi/tests/sidecar.rs b/sidecar-ffi/tests/sidecar.rs index 50b55a803..37e6558ce 100644 --- a/sidecar-ffi/tests/sidecar.rs +++ b/sidecar-ffi/tests/sidecar.rs @@ -11,7 +11,7 @@ macro_rules! assert_maybe_no_error { }; } -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use std::ptr::{null, null_mut}; use std::time::Duration; #[cfg(unix)] diff --git a/sidecar/Cargo.toml b/sidecar/Cargo.toml index 8389d69ab..db1de84dc 100644 --- a/sidecar/Cargo.toml +++ b/sidecar/Cargo.toml @@ -18,6 +18,7 @@ arrayref = "0.3.7" bytes = "1.4" priority-queue = "2.1.1" ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } datadog-sidecar-macros = { path = "macros" } ddtelemetry = { path = "../ddtelemetry", features = ["tracing"] } diff --git a/sidecar/src/agent_remote_config.rs b/sidecar/src/agent_remote_config.rs index 42f325f63..703be1c22 100644 --- a/sidecar/src/agent_remote_config.rs +++ b/sidecar/src/agent_remote_config.rs @@ -6,7 +6,7 @@ use crate::one_way_shared_memory::{ }; use crate::primary_sidecar_identifier; use datadog_ipc::platform::{FileBackedHandle, MappedMem, NamedShmHandle, ShmHandle}; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use std::ffi::CString; use std::hash::{Hash, Hasher}; use std::io; diff --git a/sidecar/src/config.rs b/sidecar/src/config.rs index aeeea7668..fc9f3dab8 100644 --- a/sidecar/src/config.rs +++ b/sidecar/src/config.rs @@ -5,7 +5,7 @@ use http::uri::{PathAndQuery, Scheme}; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, path::PathBuf, time::Duration}; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use spawn_worker::LibDependency; const ENV_SIDECAR_IPC_MODE: &str = "_DD_DEBUG_SIDECAR_IPC_MODE"; diff --git a/sidecar/src/service/agent_info.rs b/sidecar/src/service/agent_info.rs index 226fc1a0d..a18f5a340 100644 --- a/sidecar/src/service/agent_info.rs +++ b/sidecar/src/service/agent_info.rs @@ -15,7 +15,7 @@ use base64::Engine; use data_pipeline::agent_info::schema::AgentInfoStruct; use data_pipeline::agent_info::{fetch_info_with_state, FetchInfoStatus}; use datadog_ipc::platform::NamedShmHandle; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use futures::future::Shared; use futures::FutureExt; use http::uri::PathAndQuery; @@ -197,6 +197,7 @@ impl AgentInfoReader { #[cfg(test)] mod tests { use super::*; + use ddcommon_net1::Endpoint; use httpmock::prelude::*; const TEST_INFO: &str = r#"{ diff --git a/sidecar/src/service/mod.rs b/sidecar/src/service/mod.rs index b28d73a8f..245bcad1a 100644 --- a/sidecar/src/service/mod.rs +++ b/sidecar/src/service/mod.rs @@ -6,7 +6,7 @@ use crate::config; use crate::service::telemetry::enqueued_telemetry_data::EnqueuedTelemetryData; use datadog_remote_config::{RemoteConfigCapabilities, RemoteConfigProduct}; use ddcommon::tag::Tag; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use ddtelemetry::metrics::MetricContext; use ddtelemetry::worker::TelemetryActions; use serde::{Deserialize, Serialize}; diff --git a/sidecar/src/service/sidecar_server.rs b/sidecar/src/service/sidecar_server.rs index 364584083..af1b64b2f 100644 --- a/sidecar/src/service/sidecar_server.rs +++ b/sidecar/src/service/sidecar_server.rs @@ -18,7 +18,7 @@ use datadog_ipc::transport::Transport; use datadog_trace_utils::trace_utils::SendData; use datadog_trace_utils::tracer_payload; use datadog_trace_utils::tracer_payload::TraceEncoding; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use ddtelemetry::worker::{ LifecycleAction, TelemetryActions, TelemetryWorkerBuilder, TelemetryWorkerStats, }; diff --git a/sidecar/src/service/tracing/trace_flusher.rs b/sidecar/src/service/tracing/trace_flusher.rs index 1121ac8c1..bd1617171 100644 --- a/sidecar/src/service/tracing/trace_flusher.rs +++ b/sidecar/src/service/tracing/trace_flusher.rs @@ -7,7 +7,7 @@ use datadog_ipc::platform::NamedShmHandle; use datadog_trace_utils::trace_utils; use datadog_trace_utils::trace_utils::SendData; use datadog_trace_utils::trace_utils::SendDataResult; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use futures::future::join_all; use hyper::body::HttpBody; use manual_future::{ManualFuture, ManualFutureCompleter}; @@ -311,6 +311,7 @@ impl TraceFlusher { mod tests { use super::*; use datadog_trace_utils::test_utils::{create_send_data, poll_for_mock_hit}; + use ddcommon_net1::Endpoint; use httpmock::MockServer; use std::sync::Arc; diff --git a/sidecar/src/tracer.rs b/sidecar/src/tracer.rs index 56e473ec9..1867ea1be 100644 --- a/sidecar/src/tracer.rs +++ b/sidecar/src/tracer.rs @@ -4,7 +4,7 @@ use crate::primary_sidecar_identifier; use datadog_ipc::rate_limiter::ShmLimiterMemory; use datadog_trace_utils::config_utils::trace_intake_url_prefixed; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use http::uri::PathAndQuery; use lazy_static::lazy_static; use std::ffi::CString; diff --git a/tools/docker/Dockerfile.build b/tools/docker/Dockerfile.build index e239a1520..ff9ad7e48 100644 --- a/tools/docker/Dockerfile.build +++ b/tools/docker/Dockerfile.build @@ -74,6 +74,7 @@ COPY "crashtracker/Cargo.toml" "crashtracker/" COPY "crashtracker-ffi/Cargo.toml" "crashtracker-ffi/" COPY "ddcommon/Cargo.toml" "ddcommon/" COPY "ddcommon-ffi/Cargo.toml" "ddcommon-ffi/" +COPY "ddcommon-net1/Cargo.toml" "ddcommon-net1/" COPY "ddtelemetry/Cargo.toml" "ddtelemetry/" COPY "ddtelemetry-ffi/Cargo.toml" "ddtelemetry-ffi/" COPY "ddsketch/Cargo.toml" "ddsketch/" diff --git a/trace-mini-agent/Cargo.toml b/trace-mini-agent/Cargo.toml index 381691fa5..07ee6cbf0 100644 --- a/trace-mini-agent/Cargo.toml +++ b/trace-mini-agent/Cargo.toml @@ -19,6 +19,7 @@ tracing = { version = "0.1", default-features = false } serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0" ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1" } datadog-trace-protobuf = { path = "../trace-protobuf" } datadog-trace-utils = { path = "../trace-utils", features = ["proxy"] } datadog-trace-normalization = { path = "../trace-normalization" } diff --git a/trace-mini-agent/src/config.rs b/trace-mini-agent/src/config.rs index 4bb943eaa..9582e3302 100644 --- a/trace-mini-agent/src/config.rs +++ b/trace-mini-agent/src/config.rs @@ -1,7 +1,7 @@ // Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use std::borrow::Cow; use std::env; use std::str::FromStr; diff --git a/trace-mini-agent/src/trace_processor.rs b/trace-mini-agent/src/trace_processor.rs index 14564e7d8..3e884737a 100644 --- a/trace-mini-agent/src/trace_processor.rs +++ b/trace-mini-agent/src/trace_processor.rs @@ -142,7 +142,7 @@ mod tests { use datadog_trace_utils::{ test_utils::create_test_json_span, trace_utils, tracer_payload::TracerPayloadCollection, }; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; fn get_current_timestamp_nanos() -> i64 { UNIX_EPOCH.elapsed().unwrap().as_nanos() as i64 diff --git a/trace-utils/Cargo.toml b/trace-utils/Cargo.toml index 2f5415a49..22a43f6c8 100644 --- a/trace-utils/Cargo.toml +++ b/trace-utils/Cargo.toml @@ -26,7 +26,8 @@ log = "0.4" serde_json = "1.0" flate2 = "1.0" futures = { version = "0.3", default-features = false } -ddcommon = { path = "../ddcommon", features = ["use_webpki_roots"] } +ddcommon = { path = "../ddcommon" } +ddcommon-net1 = { path = "../ddcommon-net1", features = ["use_webpki_roots"] } datadog-trace-protobuf = { path = "../trace-protobuf" } datadog-trace-normalization = { path = "../trace-normalization" } tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/trace-utils/src/send_data/mod.rs b/trace-utils/src/send_data/mod.rs index e2ed00508..c32ccd956 100644 --- a/trace-utils/src/send_data/mod.rs +++ b/trace-utils/src/send_data/mod.rs @@ -11,7 +11,7 @@ use crate::tracer_payload::TracerPayloadCollection; use anyhow::{anyhow, Context}; use bytes::Bytes; use datadog_trace_protobuf::pb::{AgentPayload, TracerPayload}; -use ddcommon::{connector, Endpoint, HttpRequestBuilder}; +use ddcommon_net1::{connector, Endpoint, HttpRequestBuilder}; use futures::stream::FuturesUnordered; use futures::StreamExt; use hyper::header::HeaderValue; @@ -86,7 +86,7 @@ pub(crate) enum RequestResult { /// }; /// use datadog_trace_utils::trace_utils::TracerHeaderTags; /// use datadog_trace_utils::tracer_payload::TracerPayloadCollection; -/// use ddcommon::Endpoint; +/// use ddcommon_net1::Endpoint; /// /// #[cfg_attr(miri, ignore)] /// async fn update_send_results_example() { @@ -506,7 +506,7 @@ mod tests { use crate::trace_utils::{construct_trace_chunk, construct_tracer_payload, RootSpanTags}; use crate::tracer_header_tags::TracerHeaderTags; use datadog_trace_protobuf::pb::Span; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; use httpmock::prelude::*; use httpmock::MockServer; use std::collections::HashMap; diff --git a/trace-utils/src/stats_utils.rs b/trace-utils/src/stats_utils.rs index 1be89fee4..5bc1ef960 100644 --- a/trace-utils/src/stats_utils.rs +++ b/trace-utils/src/stats_utils.rs @@ -8,8 +8,7 @@ use log::debug; use std::io::Write; use datadog_trace_protobuf::pb; -use ddcommon::connector::Connector; -use ddcommon::Endpoint; +use ddcommon_net1::{connector::Connector, Endpoint}; pub async fn get_stats_from_request_body(body: Body) -> anyhow::Result { let buffer = body.collect().await?.aggregate(); diff --git a/trace-utils/src/test_utils/datadog_test_agent.rs b/trace-utils/src/test_utils/datadog_test_agent.rs index dee192938..f97d97245 100644 --- a/trace-utils/src/test_utils/datadog_test_agent.rs +++ b/trace-utils/src/test_utils/datadog_test_agent.rs @@ -108,7 +108,7 @@ impl DatadogTestAgentContainer { /// use datadog_trace_utils::test_utils::datadog_test_agent::DatadogTestAgent; /// use datadog_trace_utils::trace_utils::TracerHeaderTags; /// use datadog_trace_utils::tracer_payload::TracerPayloadCollection; -/// use ddcommon::Endpoint; +/// use ddcommon_net1::Endpoint; /// /// use tokio; /// diff --git a/trace-utils/src/test_utils/mod.rs b/trace-utils/src/test_utils/mod.rs index 47848cd82..bb2586133 100644 --- a/trace-utils/src/test_utils/mod.rs +++ b/trace-utils/src/test_utils/mod.rs @@ -11,7 +11,7 @@ use crate::span_v04::Span; use crate::trace_utils::TracerHeaderTags; use crate::tracer_payload::TracerPayloadCollection; use datadog_trace_protobuf::pb; -use ddcommon::Endpoint; +use ddcommon_net1::Endpoint; use httpmock::Mock; use serde_json::json; use tinybytes::BytesString; @@ -329,7 +329,7 @@ pub async fn poll_for_mock_hit( /// /// ``` /// use datadog_trace_utils::test_utils::create_send_data; -/// use ddcommon::Endpoint; +/// use ddcommon_net1::Endpoint; /// /// let size = 512; /// let target_endpoint = Endpoint { diff --git a/trace-utils/tests/test_send_data.rs b/trace-utils/tests/test_send_data.rs index 81bad5a51..3a461aa0c 100644 --- a/trace-utils/tests/test_send_data.rs +++ b/trace-utils/tests/test_send_data.rs @@ -8,7 +8,7 @@ mod tracing_integration_tests { use datadog_trace_utils::test_utils::datadog_test_agent::DatadogTestAgent; use datadog_trace_utils::trace_utils::TracerHeaderTags; use datadog_trace_utils::tracer_payload::TracerPayloadCollection; - use ddcommon::Endpoint; + use ddcommon_net1::Endpoint; use tinybytes::BytesString; #[cfg_attr(miri, ignore)]