mirror of
https://github.com/openai/codex.git
synced 2026-11-06 20:20:34 +00:00
## What changed - Add `GetProcessMetrics` and provider sampling APIs for process ID, start time, cumulative CPU time, and resident memory, exposed through `ThreadManager` without creating a thread or session. - Distinguish unsupported collection, a locally absent host, and sampling failures. Process-owned providers never start or replace a host when sampling. - Bound gRPC sampling to one second without retries or explicit connection resets. Run optional collectors on a detached worker with at most one collection in flight, so stalled collection cannot block the HTTP/2 driver or runtime shutdown. ## Testing Add coverage for snapshots, collector errors and panics, deadlines, overload, and shutdown with a stuck collector. Extend lifecycle tests to check that sampling preserves session state and keepalive behavior without starting or restarting local hosts. GitOrigin-RevId: eeafe275891d0464636f28a29345a87aed1a12dc
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
use std::net::SocketAddr;
|
|
|
|
use anyhow::Context;
|
|
use anyhow::Result;
|
|
|
|
use crate::grpc_transport;
|
|
|
|
/// The default transport retains the standalone host's original stdio behavior.
|
|
pub const DEFAULT_LISTEN_URL: &str = "stdio";
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
enum ListenTransport {
|
|
Stdio,
|
|
GrpcStdio,
|
|
Grpc(SocketAddr),
|
|
}
|
|
|
|
pub(crate) async fn run_transport(listen_url: &str, host: crate::GrpcCodeModeHost) -> Result<()> {
|
|
match parse_listen_url(listen_url)? {
|
|
ListenTransport::Stdio => crate::run_stdio().await,
|
|
ListenTransport::GrpcStdio => crate::grpc_stdio::run(host).await,
|
|
ListenTransport::Grpc(bind_address) => {
|
|
grpc_transport::run_tcp_listener(bind_address, host).await
|
|
}
|
|
}
|
|
}
|
|
|
|
fn parse_listen_url(listen_url: &str) -> Result<ListenTransport> {
|
|
if listen_url == "grpc+stdio://" {
|
|
return Ok(ListenTransport::GrpcStdio);
|
|
}
|
|
if matches!(listen_url, "stdio" | "stdio://") {
|
|
return Ok(ListenTransport::Stdio);
|
|
}
|
|
|
|
if let Some(socket_addr) = listen_url.strip_prefix("grpc://") {
|
|
return socket_addr
|
|
.parse::<SocketAddr>()
|
|
.map(ListenTransport::Grpc)
|
|
.with_context(|| {
|
|
format!("invalid gRPC --listen URL `{listen_url}`; expected `grpc://IP:PORT`")
|
|
});
|
|
}
|
|
|
|
anyhow::bail!(
|
|
"unsupported --listen URL `{listen_url}`; expected `grpc://IP:PORT`, `grpc+stdio://`, `stdio`, or `stdio://`"
|
|
);
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "transport_tests.rs"]
|
|
mod tests;
|