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
35 changes: 35 additions & 0 deletions datadog-trace-utils/src/test_utils/datadog_test_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const TEST_AGENT_PORT: u16 = 8126;
const SAMPLE_RATE_QUERY_PARAM_KEY: &str = "agent_sample_rate_by_service";
const SESSION_TEST_TOKEN_QUERY_PARAM_KEY: &str = "test_session_token";
const SESSION_START_ENDPOINT: &str = "test/session/start";
const SET_REMOTE_CONFIG_RESPONSE_PATH_ENDPOINT: &str = "test/session/responses/config/path";

#[derive(Debug)]
struct DatadogTestAgentContainer {
Expand Down Expand Up @@ -514,4 +515,38 @@ impl DatadogTestAgent {
attempts += 1;
}
}

pub async fn set_remote_config_response(&self, data: &str, snapshot_token: Option<&str>) {
let uri = self
.get_uri_for_endpoint(SET_REMOTE_CONFIG_RESPONSE_PATH_ENDPOINT, snapshot_token)
.await;

let req = Request::builder()
.method("POST")
.uri(uri)
.body(Body::from(data.as_bytes().to_vec()))
.expect("Failed to create request");

let res = self
.agent_request_with_retry(req, 5)
.await
.expect("request failed");

let status = res.status();
let body = res
.into_body()
.collect()
.await
.expect("failed to read request body")
.to_bytes();

assert_eq!(
status.as_u16(),
202,
"Expected status 200 for test agent {}, but got {}: {:?}",
SET_REMOTE_CONFIG_RESPONSE_PATH_ENDPOINT,
status.as_u16(),
String::from_utf8_lossy(&body)
);
}
}
64 changes: 63 additions & 1 deletion datadog-trace-utils/tests/test_send_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ mod tracing_integration_tests {
use datadog_trace_utils::tracer_payload::{decode_to_trace_chunks, TraceEncoding};
#[cfg(target_os = "linux")]
use ddcommon::connector::uds::socket_path_to_uri;
use ddcommon::Endpoint;
use ddcommon::{hyper_migration, Endpoint};
use http_body_util::BodyExt;
#[cfg(target_os = "linux")]
use hyper::Uri;
use serde_json::json;
Expand Down Expand Up @@ -329,4 +330,65 @@ mod tracing_integration_tests {

test_agent.assert_snapshot(snapshot_name).await;
}

#[cfg_attr(miri, ignore)]
#[tokio::test]
async fn test_remote_set_remote_config_data() {
let snapshot_name = "test_remote_set_remote_config_data";
let test_agent = DatadogTestAgent::new(None, None, &[]).await;

test_agent
.set_remote_config_response(
r##"{
"path": "2/APM_TRACING/1234/config",
"msg": {
"tracing_sampling_rules": [
{
"service": "test-service",
"name": "test-name",
"sample_rate": 0.5
}
]
}
}"##,
Some(snapshot_name),
)
.await;

let uri = test_agent
.get_uri_for_endpoint("v0.7/config", Some(snapshot_name))
.await;

let res = hyper_migration::new_default_client()
.get(uri)
.await
.expect("Failed to get remote config data from test agent");
assert_eq!(
res.status(),
200,
"Expected status 200 for remote config data, but got {}",
res.status()
);
let body = res
.into_body()
.collect()
.await
.expect("Failed to read body data")
.to_bytes();
let s = std::str::from_utf8(&body).expect("Failed to convert body to string");
let response = serde_json::de::from_str::<serde_json::Value>(s)
.expect("Failed to parse response as json");
assert_eq!(
response["client_configs"][0].as_str().unwrap(),
"2/APM_TRACING/1234/config"
);
assert_eq!(
response["target_files"][0]["path"].as_str().unwrap(),
"2/APM_TRACING/1234/config"
);
assert_eq!(
response["target_files"][0]["raw"].as_str().unwrap(),
"eyJ0cmFjaW5nX3NhbXBsaW5nX3J1bGVzIjogW3sic2VydmljZSI6ICJ0ZXN0LXNlcnZpY2UiLCAibmFtZSI6ICJ0ZXN0LW5hbWUiLCAic2FtcGxlX3JhdGUiOiAwLjV9XX0="
);
}
}
Loading