Skip to content

Commit

Permalink
update endpoint spans
Browse files Browse the repository at this point in the history
  • Loading branch information
conradludgate committed Jan 29, 2024
1 parent 24cac26 commit ce3f99f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
5 changes: 4 additions & 1 deletion proxy/src/auth/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ async fn auth_quirks(
Err(info) => {
let res = hacks::password_hack_no_authentication(info, client, &mut ctx.latency_timer)
.await?;
ctx.set_endpoint_id(Some(res.info.endpoint.clone()));

ctx.set_endpoint_id(res.info.endpoint.clone());
tracing::Span::current().record("ep", &tracing::field::display(&res.info.endpoint));

(res.info, Some(res.keys))
}
Ok(info) => (info, None),
Expand Down
1 change: 1 addition & 0 deletions proxy/src/auth/backend/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub(super) async fn authenticate(

ctx.set_user(db_info.user.into());
ctx.set_project(db_info.aux.clone());
tracing::Span::current().record("ep", &tracing::field::display(&db_info.aux.endpoint_id));

// Backwards compatibility. pg_sni_proxy uses "--" in domain names
// while direct connections do not. Once we migrate to pg_sni_proxy
Expand Down
8 changes: 6 additions & 2 deletions proxy/src/auth/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ impl ComputeUserInfoMaybeEndpoint {
}),
}
.transpose()?;
ctx.set_endpoint_id(endpoint.clone());

if let Some(ep) = &endpoint {
ctx.set_endpoint_id(ep.clone());
tracing::Span::current().record("ep", &tracing::field::display(ep));
}

info!(%user, project = endpoint.as_deref(), "credentials");
if sni.is_some() {
Expand All @@ -150,7 +154,7 @@ impl ComputeUserInfoMaybeEndpoint {

Ok(Self {
user,
endpoint_id: endpoint.map(EndpointId::from),
endpoint_id: endpoint,
options,
})
}
Expand Down
12 changes: 5 additions & 7 deletions proxy/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,11 @@ impl RequestMonitoring {
self.project = Some(x.project_id);
}

pub fn set_endpoint_id(&mut self, endpoint_id: Option<EndpointId>) {
self.endpoint_id = endpoint_id.or_else(|| self.endpoint_id.clone());
if let Some(ep) = &self.endpoint_id {
crate::metrics::CONNECTING_ENDPOINTS
.with_label_values(&[self.protocol])
.measure(&ep);
}
pub fn set_endpoint_id(&mut self, endpoint_id: EndpointId) {
crate::metrics::CONNECTING_ENDPOINTS
.with_label_values(&[self.protocol])
.measure(&endpoint_id);
self.endpoint_id = Some(endpoint_id);
}

pub fn set_application(&mut self, app: Option<SmolStr>) {
Expand Down
19 changes: 10 additions & 9 deletions proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ pub async fn task_main(
let cancel_map = Arc::clone(&cancel_map);
let endpoint_rate_limiter = endpoint_rate_limiter.clone();

let session_span = info_span!(
"handle_client",
?session_id,
peer_addr = tracing::field::Empty,
ep = tracing::field::Empty,
);

connections.spawn(
async move {
info!("accepted postgres client connection");
Expand Down Expand Up @@ -107,15 +114,11 @@ pub async fn task_main(
)
.await
}
.instrument(info_span!(
"handle_client",
?session_id,
peer_addr = tracing::field::Empty
))
.unwrap_or_else(move |e| {
// Acknowledge that the task has finished with an error.
error!(?session_id, "per-client task finished with an error: {e:#}");
}),
error!("per-client task finished with an error: {e:#}");
})
.instrument(session_span),
);
}

Expand Down Expand Up @@ -212,8 +215,6 @@ pub async fn handle_client<S: AsyncRead + AsyncWrite + Unpin>(
Err(e) => stream.throw_error(e).await?,
};

ctx.set_endpoint_id(user_info.get_endpoint());

// check rate limit
if let Some(ep) = user_info.get_endpoint() {
if !endpoint_rate_limiter.check(ep) {
Expand Down
2 changes: 1 addition & 1 deletion proxy/src/serverless/sql_over_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn get_conn_info(
}

let endpoint = endpoint_sni(hostname, &tls.common_names)?.context("malformed endpoint")?;
ctx.set_endpoint_id(Some(endpoint.clone()));
ctx.set_endpoint_id(endpoint.clone());

let pairs = connection_url.query_pairs();

Expand Down

0 comments on commit ce3f99f

Please sign in to comment.