Skip to content
Draft
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
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use stargate_runtime::{OwnedTask, TASK_SHUTDOWN_TIMEOUT};
use tracing::warn;

use super::grpc_endpoint::{
StargateGrpcEndpoint, log_stargate_grpc_certificate_failure, log_stargate_grpc_connect_attempt,
StargateGrpcEndpoint, grpc_error_chain, log_stargate_grpc_certificate_failure,
};
use super::topology::{RegistrationRouterTopology, publish_registration_router_topology};

Expand Down Expand Up @@ -165,23 +165,32 @@ async fn watch_stargate_endpoint(
return;
}

log_stargate_grpc_connect_attempt(&target, "watch_stargates", "lazy");
tracing::debug!(
transport = "grpc",
operation = "watch_stargates",
endpoint = %target,
connect_mode = "lazy",
"attempting Stargate gRPC connection"
);
let stream = match target.channel_endpoint(grpc_tls_ca_cert_pem.as_deref()) {
Ok(endpoint) => {
let mut client = StargateControlPlaneClient::new(endpoint.connect_lazy());
tokio::select! {
response = client.watch_stargates(WatchStargatesRequest {}) => {
match response {
Ok(response) => {
last_certificate_failure = None;
Some(response.into_inner())
}
Err(error) => {
last_certificate_failure = log_stargate_grpc_certificate_failure(
&target,
"watch_stargates",
&error,
last_certificate_failure,
&target, "watch_stargates", &error, last_certificate_failure,
);
warn!(
transport = "grpc",
operation = "watch_stargates",
endpoint = %target,
error = %grpc_error_chain(&error),
"Stargate gRPC operation failed"
);
None
}
Expand All @@ -197,6 +206,13 @@ async fn watch_stargate_endpoint(
error.as_ref(),
last_certificate_failure,
);
warn!(
transport = "grpc",
operation = "watch_stargates",
endpoint = %target,
error = %grpc_error_chain(error.as_ref()),
"Stargate gRPC operation failed"
);
None
}
};
Expand All @@ -206,16 +222,26 @@ async fn watch_stargate_endpoint(
return;
};
let snapshot = match message {
Ok(response) => response.map(|response| {
Ok(Some(response)) => {
last_certificate_failure = None;
watch_endpoint_snapshot_from_response(&watch_url, response)
}),
Some(watch_endpoint_snapshot_from_response(&watch_url, response))
}
Ok(None) => {
warn!(
transport = "grpc",
operation = "watch_stargates_stream",
endpoint = %target,
"Stargate discovery response stream ended"
);
None
}
Err(error) => {
last_certificate_failure = log_stargate_grpc_certificate_failure(
&target,
"watch_stargates_stream",
&error,
last_certificate_failure,
warn!(
transport = "grpc",
operation = "watch_stargates_stream",
endpoint = %target,
error = %grpc_error_chain(&error),
"Stargate gRPC operation failed"
);
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,19 @@ pub(super) fn grpc_origin_uri(

impl fmt::Display for StargateGrpcEndpoint {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let safe_endpoint = |endpoint: &str| match stargate_grpc_debug_target(endpoint) {
Ok(target) => format!("{}://{}:{}", target.scheme, target.host, target.port),
Err(_) => "<invalid endpoint>".to_string(),
};
let authority = safe_endpoint(&self.authority_endpoint());
if self.uses_authority_override() {
write!(f, "{} via {}", self.authority_addr, self.dial_addr)
write!(
f,
"{authority} via {}",
safe_endpoint(&self.dial_endpoint())
)
} else {
write!(f, "{}", self.authority_addr)
f.write_str(&authority)
}
}
}
Expand Down Expand Up @@ -164,12 +173,23 @@ pub(super) async fn connect_stargate_grpc_channel(
grpc_tls_ca_cert_pem: Option<&[u8]>,
operation: &'static str,
) -> anyhow::Result<Channel> {
log_stargate_grpc_connect_attempt(router_endpoint, operation, "eager");
tracing::debug!(
transport = "grpc",
operation,
endpoint = %router_endpoint,
connect_mode = "eager",
"attempting Stargate gRPC connection"
);
let channel = router_endpoint
.channel_endpoint(grpc_tls_ca_cert_pem)?
.connect()
.await?;
log_stargate_grpc_channel_connected(router_endpoint, operation);
tracing::debug!(
transport = "grpc",
operation,
endpoint = %router_endpoint,
"Stargate gRPC channel connected"
);
Ok(channel)
}

Expand Down Expand Up @@ -287,65 +307,37 @@ pub(super) fn log_stargate_grpc_certificate_failure(
Some(failure)
}

macro_rules! log_stargate_grpc_target {
($target:expr, $operation:expr, [$($extra:tt)*], $message:literal, $error_message:literal) => {{
if !tracing::enabled!(tracing::Level::DEBUG) {
return;
}
let dial_endpoint = $target.dial_endpoint();
let authority_endpoint = $target.authority_endpoint();
let override_authority = dial_endpoint != authority_endpoint;
match (
stargate_grpc_debug_target(&dial_endpoint),
stargate_grpc_debug_target(&authority_endpoint),
) {
(Ok(dial), Ok(authority)) => tracing::debug!(
transport = "grpc",
operation = $operation,
http_version = "h2",
dial_scheme = %dial.scheme,
tls = dial.scheme == "https",
dial_host = %dial.host,
dial_port = dial.port,
authority_host = %authority.host,
authority_port = authority.port,
override_authority,
$($extra)*
$message
),
(Err(_), _) | (_, Err(_)) => tracing::debug!(
transport = "grpc",
operation = $operation,
override_authority,
$($extra)*
$error_message
),
pub(super) fn grpc_error_chain(error: &(dyn Error + 'static)) -> String {
let mut causes = Vec::new();
for error in anyhow::Chain::new(error) {
// Parser diagnostics can include input excerpts from token files.
let detail = if let Some(error) = error.downcast_ref::<sonic_rs::Error>() {
format!(
"invalid JSON at line {} column {}",
error.line(),
error.column()
)
} else if let Some(status) = error.downcast_ref::<tonic::Status>() {
// Metadata and binary details are not needed to diagnose the RPC.
format!("gRPC {:?}: {}", status.code(), status.message())
} else if let Some(error) = error.downcast_ref::<reqwest::Error>() {
// Token-issuer URLs can contain credentials or sensitive queries.
// Keep the failure category and its sources without displaying the URL.
if error.is_timeout() {
"HTTP request timed out".into()
} else if error.is_connect() {
"HTTP connection failed".into()
} else {
"HTTP request failed".into()
}
} else {
error.to_string()
};
if causes.last() != Some(&detail) {
causes.push(detail);
}
}};
}

pub(super) fn log_stargate_grpc_connect_attempt(
target: &StargateGrpcEndpoint,
operation: &'static str,
connect_mode: &'static str,
) {
log_stargate_grpc_target!(
target,
operation,
[connect_mode,],
"attempting Stargate gRPC connection",
"could not parse Stargate gRPC endpoint for connection debug logging"
);
}

fn log_stargate_grpc_channel_connected(target: &StargateGrpcEndpoint, operation: &'static str) {
log_stargate_grpc_target!(
target,
operation,
[],
"Stargate gRPC channel connected",
"Stargate gRPC channel connected but endpoint metadata could not be parsed"
);
}
causes.join(": ")
}

fn normalize_addr_with_default_scheme(addr: &str, default_scheme: &str) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use stargate_proto::pb::{InferenceServerAck, InferenceServerRegistration, Infere
use stargate_runtime::{OwnedTask, TASK_SHUTDOWN_TIMEOUT};

use super::grpc_endpoint::{
StargateGrpcEndpoint, connect_stargate_grpc_channel, log_stargate_grpc_certificate_failure,
StargateGrpcEndpoint, connect_stargate_grpc_channel, grpc_error_chain,
log_stargate_grpc_certificate_failure,
};
use super::reverse_tunnel::{
ReverseTunnelState, reverse_tunnel_endpoint_from_ack, run_reverse_tunnel_loop,
Expand Down Expand Up @@ -58,17 +59,22 @@ pub(super) async fn run_router_registration_stream(
) => connection,
};
let (mut ack_stream, update_tx) = match connection {
Ok(connection) => {
last_certificate_failure = None;
connection
}
Ok(connection) => connection,
Err(error) => {
last_certificate_failure = log_stargate_grpc_certificate_failure(
&router_endpoint,
"register_inference_server",
error.as_ref(),
last_certificate_failure,
);
tracing::warn!(
transport = "grpc",
operation = "register_inference_server",
endpoint = %router_endpoint,
cluster_id = %config.cluster_id,
error = %grpc_error_chain(error.as_ref()),
"Stargate gRPC operation failed"
);
if stop
.run_until_cancelled(tokio::time::sleep(Duration::from_secs(1)))
.await
Expand Down Expand Up @@ -160,8 +166,32 @@ pub(super) async fn run_router_registration_stream(
connected
}
maybe_ack = ack_stream.message() => {
let Ok(Some(ack)) = maybe_ack else {
break false;
let ack = match maybe_ack {
Ok(Some(ack)) => {
last_certificate_failure = None;
ack
}
Ok(None) => {
tracing::warn!(
transport = "grpc",
operation = "register_inference_server_stream",
endpoint = %router_endpoint,
cluster_id = %config.cluster_id,
"Stargate registration response stream ended"
);
break false;
}
Err(error) => {
tracing::warn!(
transport = "grpc",
operation = "register_inference_server_stream",
endpoint = %router_endpoint,
cluster_id = %config.cluster_id,
error = %grpc_error_chain(&error),
"Stargate gRPC operation failed"
);
break false;
}
};
if config.reverse_tunnel {
let endpoint = reverse_tunnel_endpoint_from_ack(&ack);
Expand All @@ -185,7 +215,12 @@ pub(super) async fn run_router_registration_stream(
if let Some(task) = reverse_task {
task.shutdown(TASK_SHUTDOWN_TIMEOUT).await;
}
if stopped {
if stopped
|| stop
.run_until_cancelled(tokio::time::sleep(Duration::from_secs(1)))
.await
.is_none()
{
return;
}
}
Expand Down Expand Up @@ -298,7 +333,10 @@ pub(super) async fn open_registration_stream(
min_update_interval.as_millis().to_string().parse()?,
);
if let Some(provider) = auth_token_provider {
let token = provider.resolve_token().await?;
let token = provider
.resolve_token()
.await
.context("failed to resolve registration token")?;
request.metadata_mut().insert(
"authorization",
format!("Bearer {token}")
Expand Down
Loading
Loading