Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions bottlecap/Cargo.lock

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

12 changes: 6 additions & 6 deletions bottlecap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ indexmap = {version = "2.11.0", default-features = false}
# be found in the clippy.toml file adjacent to this Cargo.toml.
datadog-protos = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki/", rev = "f863626dbfe3c59bb390985fa6530b0621c2a0a2"}
ddsketch-agent = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki/", rev = "f863626dbfe3c59bb390985fa6530b0621c2a0a2"}
libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "158b59471f1132e3cb36023fa3c46ccb2dd0eda1" }
libdd-trace-protobuf = { git = "https://github.com/DataDog/libdatadog", rev = "158b59471f1132e3cb36023fa3c46ccb2dd0eda1" }
libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "158b59471f1132e3cb36023fa3c46ccb2dd0eda1" , features = ["mini_agent"] }
libdd-trace-normalization = { git = "https://github.com/DataDog/libdatadog", rev = "158b59471f1132e3cb36023fa3c46ccb2dd0eda1" }
libdd-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "158b59471f1132e3cb36023fa3c46ccb2dd0eda1" }
libdd-trace-stats = { git = "https://github.com/DataDog/libdatadog", rev = "158b59471f1132e3cb36023fa3c46ccb2dd0eda1" }
libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "c8121f422d2c8d219f8d421ff3cdb1fcbe9e8b09" }
libdd-trace-protobuf = { git = "https://github.com/DataDog/libdatadog", rev = "c8121f422d2c8d219f8d421ff3cdb1fcbe9e8b09" }
libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "c8121f422d2c8d219f8d421ff3cdb1fcbe9e8b09" , features = ["mini_agent"] }
libdd-trace-normalization = { git = "https://github.com/DataDog/libdatadog", rev = "c8121f422d2c8d219f8d421ff3cdb1fcbe9e8b09" }
libdd-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "c8121f422d2c8d219f8d421ff3cdb1fcbe9e8b09" }
libdd-trace-stats = { git = "https://github.com/DataDog/libdatadog", rev = "c8121f422d2c8d219f8d421ff3cdb1fcbe9e8b09" }
dogstatsd = { git = "https://github.com/DataDog/serverless-components", rev = "2eb009a59ed07ffcaf174db1c31af413365e9bc6", default-features = false }
datadog-fips = { git = "https://github.com/DataDog/serverless-components", rev = "2eb009a59ed07ffcaf174db1c31af413365e9bc6", default-features = false }
libddwaf = { version = "1.28.1", git = "https://github.com/DataDog/libddwaf-rust", rev = "d1534a158d976bd4f747bf9fcc58e0712d2d17fc", default-features = false, features = ["serde"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

//! Hyper-based HTTP client for trace and stats flushers.
//! HTTP client for trace and stats flushers.
//!
//! This module provides the HTTP client type required by `libdd_trace_utils`
//! for sending traces and stats to Datadog intake endpoints.

use hyper_http_proxy;
use hyper_rustls::HttpsConnectorBuilder;
use libdd_common::{GenericHttpClient, hyper_migration};
use libdd_common::{GenericHttpClient, http_common};
use rustls::RootCertStore;
use rustls_pki_types::CertificateDer;
use std::error::Error;
Expand All @@ -20,7 +20,7 @@ use tracing::debug;
/// Type alias for the HTTP client used by trace and stats flushers.
///
/// This is the client type expected by `libdd_trace_utils::SendData::send()`.
pub type HyperClient =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an upgrade is it? This is a change in libraries we are using?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libdatadog switches away from having to having a dependency on hyper clients as its expecting to use reqwest instead, what we normally use everywhere else here, this just renames the previous client which was hyper tied to just be a "generic" type HttpClient because we are not concerned of what it is, and they're exporting it as an http helper library

pub type HttpClient =
GenericHttpClient<hyper_http_proxy::ProxyConnector<libdd_common::connector::Connector>>;

/// Initialize the crypto provider needed for setting custom root certificates.
Expand All @@ -35,7 +35,7 @@ fn ensure_crypto_provider_initialized() {
let () = &*INIT_CRYPTO_PROVIDER;
}

/// Creates a new hyper-based HTTP client with the given configuration.
/// Creates a new HTTP client with the given configuration.
///
/// This client is compatible with `libdd_trace_utils` and supports:
/// - HTTPS proxy configuration
Expand All @@ -54,7 +54,7 @@ fn ensure_crypto_provider_initialized() {
pub fn create_client(
proxy_https: Option<&String>,
tls_cert_file: Option<&String>,
) -> Result<HyperClient, Box<dyn Error>> {
) -> Result<HttpClient, Box<dyn Error>> {
// Create the base connector with optional custom TLS config
let connector = if let Some(ca_cert_path) = tls_cert_file {
// Ensure crypto provider is initialized before creating TLS config
Expand Down Expand Up @@ -84,10 +84,7 @@ pub fn create_client(
.enable_http1()
.build();

debug!(
"HYPER_CLIENT | Added root certificate from {}",
ca_cert_path
);
debug!("HTTP_CLIENT | Added root certificate from {}", ca_cert_path);

// Construct the Connector::Https variant directly
libdd_common::connector::Connector::Https(https_connector)
Expand All @@ -100,14 +97,14 @@ pub fn create_client(
let proxy =
hyper_http_proxy::Proxy::new(hyper_http_proxy::Intercept::Https, proxy.parse()?);
let proxy_connector = hyper_http_proxy::ProxyConnector::from_proxy(connector, proxy)?;
let client = hyper_migration::client_builder().build(proxy_connector);
let client = http_common::client_builder().build(proxy_connector);
debug!(
"HYPER_CLIENT | Proxy connector created with proxy: {:?}",
"HTTP_CLIENT | Proxy connector created with proxy: {:?}",
proxy_https
);
Ok(client)
} else {
let proxy_connector = hyper_http_proxy::ProxyConnector::new(connector)?;
Ok(hyper_migration::client_builder().build(proxy_connector))
Ok(http_common::client_builder().build(proxy_connector))
}
}
2 changes: 1 addition & 1 deletion bottlecap/src/traces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

pub mod context;
pub mod hyper_client;
pub mod http_client;
pub mod propagation;
pub mod proxy_aggregator;
pub mod proxy_flusher;
Expand Down
9 changes: 5 additions & 4 deletions bottlecap/src/traces/stats_flusher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio::sync::OnceCell;

use crate::config;
use crate::lifecycle::invocation::processor::S_TO_MS;
use crate::traces::hyper_client::{self, HyperClient};
use crate::traces::http_client::{self, HttpClient};
use crate::traces::stats_aggregator::StatsAggregator;
use dogstatsd::api_key::ApiKeyFactory;
use libdd_common::Endpoint;
Expand All @@ -24,7 +24,7 @@ pub struct StatsFlusher {
/// Cached HTTP client, lazily initialized on first use.
/// TODO: `StatsFlusher` and `TraceFlusher` both hit trace.agent.datadoghq.{site} and could
/// share a single HTTP client for better connection pooling.
http_client: OnceCell<HyperClient>,
http_client: OnceCell<HttpClient>,
}

impl StatsFlusher {
Expand Down Expand Up @@ -72,6 +72,7 @@ impl StatsFlusher {
api_key: Some(api_key_clone.into()),
timeout_ms: self.config.flush_timeout * S_TO_MS,
test_token: None,
use_system_resolver: false,
}
}
})
Expand Down Expand Up @@ -176,11 +177,11 @@ impl StatsFlusher {
///
/// Returns `None` if client creation fails. The error is logged but not cached,
/// allowing retry on subsequent calls.
async fn get_or_init_http_client(&self) -> Option<&HyperClient> {
async fn get_or_init_http_client(&self) -> Option<&HttpClient> {
match self
.http_client
.get_or_try_init(|| async {
hyper_client::create_client(
http_client::create_client(
self.config.proxy_https.as_ref(),
self.config.tls_cert_file.as_ref(),
)
Expand Down
6 changes: 3 additions & 3 deletions bottlecap/src/traces/stats_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use axum::{
use tokio::sync::mpsc::Sender;
use tracing::{debug, error};

use libdd_common::hyper_migration;
use libdd_common::http_common;
use libdd_trace_protobuf::pb;
use libdd_trace_utils::stats_utils;

use super::trace_agent::MAX_CONTENT_LENGTH;
use crate::http::extract_request_body;
use crate::traces::trace_agent::MAX_CONTENT_LENGTH;

#[async_trait]
pub trait StatsProcessor {
Expand Down Expand Up @@ -66,7 +66,7 @@ impl StatsProcessor for ServerlessStatsProcessor {
// deserialize trace stats from the request body, convert to protobuf structs (see
// trace-protobuf crate)
let mut stats: pb::ClientStatsPayload =
match stats_utils::get_stats_from_request_body(hyper_migration::Body::from_bytes(body))
match stats_utils::get_stats_from_request_body(http_common::Body::from_bytes(body))
.await
{
Ok(result) => result,
Expand Down
30 changes: 15 additions & 15 deletions bottlecap/src/traces/trace_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::{
trace_processor,
},
};
use libdd_common::hyper_migration;
use libdd_common::http_common;
use libdd_trace_protobuf::pb;
use libdd_trace_utils::trace_utils::{self};

Expand Down Expand Up @@ -503,22 +503,22 @@ impl TraceAgent {

let tracer_header_tags = (&parts.headers).into();

let (body_size, mut traces) = match version {
ApiVersion::V04 => match trace_utils::get_traces_from_request_body(
hyper_migration::Body::from_bytes(body),
)
.await
{
Ok(result) => result,
Err(err) => {
return error_response(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Error deserializing trace from request body: {err}"),
);
let (body_size, mut traces): (usize, Vec<Vec<pb::Span>>) = match version {
ApiVersion::V04 => {
match trace_utils::get_traces_from_request_body(http_common::Body::from_bytes(body))
.await
{
Ok(result) => result,
Err(err) => {
return error_response(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Error deserializing trace from request body: {err}"),
);
}
}
},
}
ApiVersion::V05 => match trace_utils::get_v05_traces_from_request_body(
hyper_migration::Body::from_bytes(body),
http_common::Body::from_bytes(body),
)
.await
{
Expand Down
Loading
Loading