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
59 changes: 56 additions & 3 deletions datadog-trace-utils/src/send_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,16 @@ impl SendData {
self.retry_strategy = retry_strategy;
}

/// Overrides the set target Endpoint.
/// Returns a clone of the SendData with the user-defined endpoint.
///
/// # Arguments
///
/// * `endpoint`: The new endpoint to be used.
pub fn set_target(&mut self, endpoint: Endpoint) {
self.target = endpoint;
pub fn with_endpoint(&self, endpoint: Endpoint) -> SendData {
Comment thread
shreyamalpani marked this conversation as resolved.
SendData {
target: endpoint,
..self.clone()
}
}

/// Sends the data to the target endpoint.
Expand Down Expand Up @@ -977,4 +980,54 @@ mod tests {
assert_eq!(res.bytes_sent, 0);
assert_eq!(res.responses_count_per_code.len(), 0);
}

#[test]
fn test_with_endpoint() {
let header_tags = HEADER_TAGS;
let payload = setup_payload(&header_tags);
let original_endpoint = Endpoint {
api_key: Some(std::borrow::Cow::Borrowed("original-key")),
url: "http://originalexample.com/".parse::<hyper::Uri>().unwrap(),
timeout_ms: 1000,
..Endpoint::default()
};

let original_data = SendData::new(
100,
TracerPayloadCollection::V07(vec![payload]),
header_tags,
&original_endpoint,
);

let new_endpoint = Endpoint {
api_key: Some(std::borrow::Cow::Borrowed("new-key")),
url: "http://newexample.com/".parse::<hyper::Uri>().unwrap(),
timeout_ms: 2000,
..Endpoint::default()
};

let new_data = original_data.with_endpoint(new_endpoint.clone());

assert_eq!(new_data.target.api_key, new_endpoint.api_key);
assert_eq!(new_data.target.url, new_endpoint.url);
assert_eq!(new_data.target.timeout_ms, new_endpoint.timeout_ms);

assert_eq!(new_data.size, original_data.size);
assert_eq!(new_data.headers, original_data.headers);
assert_eq!(new_data.retry_strategy, original_data.retry_strategy);
assert_eq!(
new_data.tracer_payloads.size(),
original_data.tracer_payloads.size()
);

assert_eq!(original_data.target.api_key, original_endpoint.api_key);
assert_eq!(original_data.target.url, original_endpoint.url);
assert_eq!(
original_data.target.timeout_ms,
original_endpoint.timeout_ms
);

#[cfg(feature = "compression")]
assert!(matches!(new_data.compression, Compression::None));
}
}
2 changes: 2 additions & 0 deletions datadog-trace-utils/src/send_with_retry/retry_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tokio::time::sleep;
/// Enum representing the type of backoff to use for the delay between retries.
/// ```
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub enum RetryBackoffType {
/// Increases the delay by a fixed increment each attempt.
Linear,
Expand All @@ -24,6 +25,7 @@ pub enum RetryBackoffType {
/// It includes the maximum number of retries, the delay between retries, the type of backoff to
/// use, and an optional jitter to add randomness to the delay.
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub struct RetryStrategy {
/// The maximum number of retries to attempt.
max_retries: u32,
Expand Down
Loading