aKode fase 2c: eliminato il codice di invio dati (crate analytics, otel-trace-websocket, sentry, esportatori OTLP); /feedback salva solo in locale; chiavi legacy [analytics]/[otel] accettate e ignorate; test di analytics/OTLP/upload rimossi
Some checks failed
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
Some checks failed
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
This commit is contained in:
@@ -45,7 +45,6 @@ use predicates::str::contains;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
use tokio::io::AsyncBufReadExt;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::io::BufReader;
|
||||
use tokio::net::TcpListener;
|
||||
@@ -457,12 +456,6 @@ async fn remote_exec_server_gracefully_stops_when_parent_stdin_closes() -> Resul
|
||||
const EXECUTOR_REGISTRATION_ID: &str = "registration-parent-lifetime";
|
||||
const TEST_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
|
||||
let collector = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/v1/metrics"))
|
||||
.respond_with(ResponseTemplate::new(202))
|
||||
.mount(&collector)
|
||||
.await;
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await?;
|
||||
let rendezvous_url = format!("ws://{}", listener.local_addr()?);
|
||||
let registry = MockServer::start().await;
|
||||
@@ -489,21 +482,9 @@ async fn remote_exec_server_gracefully_stops_when_parent_stdin_closes() -> Resul
|
||||
.await;
|
||||
|
||||
let codex_home = TempDir::new()?;
|
||||
let collector_url = collector.uri();
|
||||
std::fs::write(
|
||||
codex_home.path().join("config.toml"),
|
||||
format!(
|
||||
r#"
|
||||
cli_auth_credentials_store = "file"
|
||||
|
||||
[analytics]
|
||||
enabled = true
|
||||
|
||||
[otel]
|
||||
environment = "test"
|
||||
metrics_exporter = {{ otlp-http = {{ endpoint = "{collector_url}/v1/metrics", protocol = "json" }} }}
|
||||
"#
|
||||
),
|
||||
"cli_auth_credentials_store = \"file\"\n",
|
||||
)?;
|
||||
let package = TempDir::new()?;
|
||||
let bin_dir = package.path().join("bin");
|
||||
@@ -685,29 +666,6 @@ metrics_exporter = {{ otlp-http = {{ endpoint = "{collector_url}/v1/metrics", pr
|
||||
relay_task.abort();
|
||||
let _ = relay_task.await;
|
||||
|
||||
let requests = collector
|
||||
.received_requests()
|
||||
.await
|
||||
.ok_or_else(|| anyhow::anyhow!("failed to read OTLP collector requests"))?;
|
||||
let metrics = requests
|
||||
.iter()
|
||||
.filter(|request| request.url.path() == "/v1/metrics")
|
||||
.map(|request| serde_json::from_slice::<serde_json::Value>(&request.body))
|
||||
.collect::<serde_json::Result<Vec<_>>>()?;
|
||||
assert_metric_point(&metrics, "exec_server_processes_active", &[], Some(0));
|
||||
assert_metric_point(
|
||||
&metrics,
|
||||
"exec_server_processes_finished_total",
|
||||
&[("result", "terminated")],
|
||||
Some(1),
|
||||
);
|
||||
assert_metric_point(
|
||||
&metrics,
|
||||
"exec_server_requests_total",
|
||||
&[("method", "process/start"), ("result", "success")],
|
||||
Some(1),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -804,8 +762,6 @@ async fn remote_exec_server_scoped_credentials_authenticate_only_register_and_va
|
||||
home.path().join("config.toml"),
|
||||
format!(
|
||||
r#"
|
||||
[analytics]
|
||||
enabled = true
|
||||
[otel]
|
||||
metrics_exporter = {{ otlp-http = {{ endpoint = "{}/v1/metrics", protocol = "json", headers = {{ Authorization = "general-telemetry-token" }} }} }}
|
||||
"#,
|
||||
@@ -1087,155 +1043,6 @@ async fn proxy_parent_lifetime_relay(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn local_exec_server_flushes_telemetry_on_stdio_disconnect() -> Result<()> {
|
||||
let collector = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/v1/metrics"))
|
||||
.respond_with(ResponseTemplate::new(202))
|
||||
.mount(&collector)
|
||||
.await;
|
||||
let codex_home = TempDir::new()?;
|
||||
let base_url = collector.uri();
|
||||
std::fs::write(
|
||||
codex_home.path().join("config.toml"),
|
||||
format!(
|
||||
r#"
|
||||
[analytics]
|
||||
enabled = true
|
||||
|
||||
[otel]
|
||||
environment = "test"
|
||||
metrics_exporter = {{ otlp-http = {{ endpoint = "{base_url}/v1/metrics", protocol = "json" }} }}
|
||||
"#
|
||||
),
|
||||
)?;
|
||||
|
||||
let cwd = url::Url::from_directory_path(std::env::current_dir()?)
|
||||
.map_err(|()| anyhow::anyhow!("could not convert cwd to file URL"))?;
|
||||
#[cfg(windows)]
|
||||
let argv = vec!["ping.exe", "-n", "61", "127.0.0.1"];
|
||||
#[cfg(not(windows))]
|
||||
let argv = vec!["/bin/sleep", "60"];
|
||||
let codex_bin = codex_utils_cargo_bin::cargo_bin("codex")?;
|
||||
let codex_home = codex_home.path().to_path_buf();
|
||||
let subprocess = async move {
|
||||
let mut command = tokio::process::Command::new(codex_bin);
|
||||
command
|
||||
.env("CODEX_HOME", codex_home)
|
||||
.env("NO_PROXY", "127.0.0.1,localhost")
|
||||
.env("no_proxy", "127.0.0.1,localhost")
|
||||
.args(["exec-server", "--listen", "stdio"])
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.kill_on_drop(true);
|
||||
let mut child = command.spawn()?;
|
||||
let mut stdin = child
|
||||
.stdin
|
||||
.take()
|
||||
.ok_or_else(|| anyhow::anyhow!("exec-server stdin was not piped"))?;
|
||||
let stdout = child
|
||||
.stdout
|
||||
.take()
|
||||
.ok_or_else(|| anyhow::anyhow!("exec-server stdout was not piped"))?;
|
||||
let mut stdout = BufReader::new(stdout);
|
||||
send_json_line(
|
||||
&mut stdin,
|
||||
&serde_json::json!({
|
||||
"id": 1,
|
||||
"method": "initialize",
|
||||
"params": {"clientName": "otel-test", "resumeSessionId": null}
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
wait_for_response(&mut stdout, /*expected_id*/ 1).await?;
|
||||
send_json_line(
|
||||
&mut stdin,
|
||||
&serde_json::json!({"method": "initialized", "params": {}}),
|
||||
)
|
||||
.await?;
|
||||
send_json_line(
|
||||
&mut stdin,
|
||||
&serde_json::json!({
|
||||
"id": 2,
|
||||
"method": "process/start",
|
||||
"params": {
|
||||
"processId": "otel-process",
|
||||
"argv": argv,
|
||||
"cwd": cwd,
|
||||
"env": {},
|
||||
"tty": false,
|
||||
"pipeStdin": false,
|
||||
"arg0": null
|
||||
}
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
wait_for_response(&mut stdout, /*expected_id*/ 2).await?;
|
||||
drop(stdin);
|
||||
let mut remaining_stdout = String::new();
|
||||
stdout.read_to_string(&mut remaining_stdout).await?;
|
||||
let status = child.wait().await?;
|
||||
anyhow::ensure!(
|
||||
status.success(),
|
||||
"exec-server exited with {status}; remaining stdout: {remaining_stdout}"
|
||||
);
|
||||
Ok::<(), anyhow::Error>(())
|
||||
};
|
||||
let subprocess_result = tokio::time::timeout(Duration::from_secs(30), subprocess)
|
||||
.await
|
||||
.map_err(|_| anyhow::anyhow!("exec-server subprocess timed out"))?;
|
||||
subprocess_result?;
|
||||
|
||||
let requests = collector
|
||||
.received_requests()
|
||||
.await
|
||||
.ok_or_else(|| anyhow::anyhow!("failed to read OTLP collector requests"))?;
|
||||
let metrics = requests
|
||||
.iter()
|
||||
.filter(|request| request.url.path() == "/v1/metrics")
|
||||
.map(|request| serde_json::from_slice::<serde_json::Value>(&request.body))
|
||||
.collect::<serde_json::Result<Vec<_>>>()?;
|
||||
assert_metric_point(
|
||||
&metrics,
|
||||
"exec_server_connections_active",
|
||||
&[("transport", "stdio")],
|
||||
Some(0),
|
||||
);
|
||||
assert_metric_point(
|
||||
&metrics,
|
||||
"exec_server_connections_total",
|
||||
&[("transport", "stdio")],
|
||||
Some(1),
|
||||
);
|
||||
assert_metric_point(
|
||||
&metrics,
|
||||
"exec_server_requests_total",
|
||||
&[("method", "process/start"), ("result", "success")],
|
||||
Some(1),
|
||||
);
|
||||
assert_metric_point(&metrics, "exec_server_processes_active", &[], Some(0));
|
||||
assert_metric_point(
|
||||
&metrics,
|
||||
"exec_server_processes_finished_total",
|
||||
&[("result", "terminated")],
|
||||
Some(1),
|
||||
);
|
||||
assert_metric_point(
|
||||
&metrics,
|
||||
"exec_server_request_duration_seconds",
|
||||
&[("method", "process/start"), ("result", "success")],
|
||||
/*value*/ None,
|
||||
);
|
||||
assert_metric_point(
|
||||
&metrics,
|
||||
"exec_server_process_duration_seconds",
|
||||
&[("result", "terminated")],
|
||||
/*value*/ None,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn send_json_line(
|
||||
stdin: &mut (impl tokio::io::AsyncWrite + Unpin),
|
||||
message: &serde_json::Value,
|
||||
@@ -1314,45 +1121,3 @@ async fn wait_for_response(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_metric_point(
|
||||
payloads: &[serde_json::Value],
|
||||
name: &str,
|
||||
attributes: &[(&str, &str)],
|
||||
value: Option<i64>,
|
||||
) {
|
||||
let found = payloads
|
||||
.iter()
|
||||
.flat_map(|payload| payload["resourceMetrics"].as_array().into_iter().flatten())
|
||||
.flat_map(|resource| resource["scopeMetrics"].as_array().into_iter().flatten())
|
||||
.flat_map(|scope| scope["metrics"].as_array().into_iter().flatten())
|
||||
.filter(|metric| metric["name"].as_str() == Some(name))
|
||||
.flat_map(|metric| {
|
||||
["gauge", "sum", "histogram"]
|
||||
.into_iter()
|
||||
.find_map(|kind| metric[kind]["dataPoints"].as_array())
|
||||
.into_iter()
|
||||
.flatten()
|
||||
})
|
||||
.any(|point| {
|
||||
let actual_attributes = point["attributes"]
|
||||
.as_array()
|
||||
.map(Vec::as_slice)
|
||||
.unwrap_or_default();
|
||||
let attributes_match = actual_attributes.len() == attributes.len()
|
||||
&& attributes.iter().all(|(expected_key, expected_value)| {
|
||||
actual_attributes.iter().any(|actual| {
|
||||
actual["key"].as_str() == Some(*expected_key)
|
||||
&& actual["value"]["stringValue"].as_str() == Some(*expected_value)
|
||||
})
|
||||
});
|
||||
let actual_value = point["asInt"]
|
||||
.as_i64()
|
||||
.or_else(|| point["asInt"].as_str()?.parse().ok());
|
||||
attributes_match && value.is_none_or(|expected| actual_value == Some(expected))
|
||||
});
|
||||
assert!(
|
||||
found,
|
||||
"metric {name} with attributes {attributes:?} and value {value:?} missing"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user