From dc5aeaadbe9dfcd5ad163b1329bc1ae2108d822a Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Tue, 19 Nov 2024 11:27:56 -0700 Subject: [PATCH] test: fix removal of config:: items --- Cargo.lock | 2 ++ profiling/Cargo.toml | 2 ++ profiling/src/exporter/config.rs | 46 +++++++++++++++++++++++++++++++- profiling/tests/form.rs | 19 +++++++------ 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22c72c35e..ef1e1cd86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1520,7 +1520,9 @@ dependencies = [ "ddcommon", "ddcommon-net", "derivative", + "futures", "hashbrown 0.14.3", + "http-body-util", "hyper-multipart-rfc7578", "indexmap 2.2.6", "libc", diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index 25c40c56a..6677ba568 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -46,3 +46,5 @@ tokio-util = "0.7.1" bolero = "0.10.1" bolero-generator = "0.10.2" criterion = "0.5.1" +futures = { version = "0.3", default-features = false } +http-body-util = "0.1" diff --git a/profiling/src/exporter/config.rs b/profiling/src/exporter/config.rs index ac08263b4..978601418 100644 --- a/profiling/src/exporter/config.rs +++ b/profiling/src/exporter/config.rs @@ -1,4 +1,48 @@ // Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -// todo: delete file; Exporter has been removed +use crate::exporter::Uri; +use ddcommon_net::compat::Endpoint; +use ddcommon_net::dep::http; +use std::borrow::Cow; +use std::str::FromStr; + +pub trait ProfilingEndpoint { + fn profiling_agentless( + site: impl AsRef, + api_key: Cow<'static, str>, + ) -> http::Result; + fn profiling_agent>(uri: U) -> Result + where + http::Error: From; +} + +impl ProfilingEndpoint for Endpoint { + fn profiling_agentless( + site: impl AsRef, + api_key: Cow<'static, str>, + ) -> http::Result { + let intake_url = format!("https://intake.profile.{}/api/v2/profile", site.as_ref()); + Ok(Self { + url: Uri::try_from(intake_url)?, + api_key: Some(api_key), + timeout_ms: 0, + test_token: None, + }) + } + + fn profiling_agent>(uri: U) -> Result + where + http::Error: From, + { + let mut parts = uri.try_into()?.into_parts(); + parts.path_and_query = Some(http::uri::PathAndQuery::from_str("/profiling/v1/input")?); + let url = Uri::from_parts(parts)?; + Ok(Self { + url, + api_key: None, + timeout_ms: 0, + test_token: None, + }) + } +} diff --git a/profiling/tests/form.rs b/profiling/tests/form.rs index 4eed33d21..4ba692f54 100644 --- a/profiling/tests/form.rs +++ b/profiling/tests/form.rs @@ -59,9 +59,9 @@ fn multipart( #[cfg(test)] mod tests { use crate::multipart; + use datadog_profiling::exporter::config::ProfilingEndpoint; use datadog_profiling::exporter::*; use ddcommon::tag; - use hyper::body::HttpBody; use serde_json::json; fn default_tags() -> Vec { @@ -69,6 +69,7 @@ mod tests { } fn parsed_event_json(request: Request) -> serde_json::Value { + use http_body_util::BodyExt; // Really hacky way of getting the event.json file contents, because I didn't want to // implement a full multipart parser and didn't find a particularly good // alternative. If you do figure out a better way, there's another copy of this code @@ -96,8 +97,8 @@ mod tests { fn multipart_agent() { let profiling_library_name = "dd-trace-foo"; let profiling_library_version = "1.2.3"; - let base_url = "http://localhost:8126".parse().expect("url to parse"); - let endpoint = config::agent(base_url).expect("endpoint to construct"); + let endpoint = + Endpoint::profiling_agent("http://localhost:8126").expect("endpoint to construct"); let mut exporter = ProfileExporter::new( profiling_library_name, profiling_library_version, @@ -145,8 +146,8 @@ mod tests { fn including_internal_metadata() { let profiling_library_name = "dd-trace-foo"; let profiling_library_version = "1.2.3"; - let base_url = "http://localhost:8126".parse().expect("url to parse"); - let endpoint = config::agent(base_url).expect("endpoint to construct"); + let endpoint = + Endpoint::profiling_agent("http://localhost:8126").expect("endpoint to construct"); let mut exporter = ProfileExporter::new( profiling_library_name, profiling_library_version, @@ -174,8 +175,8 @@ mod tests { fn including_info() { let profiling_library_name = "dd-trace-foo"; let profiling_library_version = "1.2.3"; - let base_url = "http://localhost:8126".parse().expect("url to parse"); - let endpoint = config::agent(base_url).expect("endpoint to construct"); + let endpoint = + Endpoint::profiling_agent("http://localhost:8126").expect("endpoint to construct"); let mut exporter = ProfileExporter::new( profiling_library_name, profiling_library_version, @@ -214,8 +215,10 @@ mod tests { fn multipart_agentless() { let profiling_library_name = "dd-trace-foo"; let profiling_library_version = "1.2.3"; + let site = "datadoghq.com"; let api_key = "1234567890123456789012"; - let endpoint = config::agentless("datadoghq.com", api_key).expect("endpoint to construct"); + let endpoint = + Endpoint::profiling_agentless(site, api_key.into()).expect("endpoint to construct"); let mut exporter = ProfileExporter::new( profiling_library_name, profiling_library_version,