Skip to content

Commit

Permalink
test: fix removal of config:: items
Browse files Browse the repository at this point in the history
  • Loading branch information
morrisonlevi committed Nov 19, 2024
1 parent 2a72da1 commit dc5aeaa
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions profiling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
46 changes: 45 additions & 1 deletion profiling/src/exporter/config.rs
Original file line number Diff line number Diff line change
@@ -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<str>,
api_key: Cow<'static, str>,
) -> http::Result<Endpoint>;
fn profiling_agent<U: TryInto<Uri>>(uri: U) -> Result<Endpoint, http::Error>
where
http::Error: From<U::Error>;
}

impl ProfilingEndpoint for Endpoint {
fn profiling_agentless(
site: impl AsRef<str>,
api_key: Cow<'static, str>,
) -> http::Result<Endpoint> {
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<U: TryInto<Uri>>(uri: U) -> Result<Endpoint, http::Error>
where
http::Error: From<U::Error>,
{
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,
})
}
}
19 changes: 11 additions & 8 deletions profiling/tests/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ 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<Tag> {
vec![tag!("service", "php"), tag!("host", "bits")]
}

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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dc5aeaa

Please sign in to comment.