mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 06:47:56 +01:00
Add a connection-specific span to each API handler
This commit is contained in:
parent
fac0a9ba94
commit
13bbe2bee9
@ -8,12 +8,14 @@ use crate::session::SessionManager;
|
|||||||
use capnp::capability::Promise;
|
use capnp::capability::Promise;
|
||||||
use capnp_rpc::pry;
|
use capnp_rpc::pry;
|
||||||
use rsasl::mechname::Mechname;
|
use rsasl::mechname::Mechname;
|
||||||
|
use tracing::Span;
|
||||||
|
|
||||||
/// Cap'n Proto API Handler
|
/// Cap'n Proto API Handler
|
||||||
pub struct BootCap {
|
pub struct BootCap {
|
||||||
peer_addr: SocketAddr,
|
peer_addr: SocketAddr,
|
||||||
authentication: AuthenticationHandle,
|
authentication: AuthenticationHandle,
|
||||||
sessionmanager: SessionManager,
|
sessionmanager: SessionManager,
|
||||||
|
span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BootCap {
|
impl BootCap {
|
||||||
@ -21,12 +23,14 @@ impl BootCap {
|
|||||||
peer_addr: SocketAddr,
|
peer_addr: SocketAddr,
|
||||||
authentication: AuthenticationHandle,
|
authentication: AuthenticationHandle,
|
||||||
sessionmanager: SessionManager,
|
sessionmanager: SessionManager,
|
||||||
|
span: Span,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
tracing::trace!(%peer_addr, "bootstrapping RPC");
|
tracing::trace!(parent: &span, %peer_addr, "bootstrapping RPC");
|
||||||
Self {
|
Self {
|
||||||
peer_addr,
|
peer_addr,
|
||||||
authentication,
|
authentication,
|
||||||
sessionmanager,
|
sessionmanager,
|
||||||
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use futures_util::{stream, AsyncRead, AsyncWrite, FutureExt, StreamExt};
|
|||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::{IpAddr, SocketAddr};
|
||||||
|
|
||||||
use crate::authentication::AuthenticationHandle;
|
use crate::authentication::AuthenticationHandle;
|
||||||
use crate::session::SessionManager;
|
use crate::session::SessionManager;
|
||||||
@ -145,12 +145,35 @@ impl APIServer {
|
|||||||
peer_addr: SocketAddr,
|
peer_addr: SocketAddr,
|
||||||
stream: impl Future<Output = io::Result<TlsStream<IO>>>,
|
stream: impl Future<Output = io::Result<TlsStream<IO>>>,
|
||||||
) {
|
) {
|
||||||
tracing::debug!("handling new API connection");
|
let span = tracing::trace_span!("api.handle");
|
||||||
|
let _guard = span.enter();
|
||||||
|
|
||||||
|
struct Peer {
|
||||||
|
ip: IpAddr,
|
||||||
|
port: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
let peer = Peer {
|
||||||
|
ip: peer_addr.ip(),
|
||||||
|
port: peer_addr.port(),
|
||||||
|
};
|
||||||
|
tracing::debug!(
|
||||||
|
%peer.ip,
|
||||||
|
peer.port,
|
||||||
|
"spawning api handler"
|
||||||
|
);
|
||||||
|
|
||||||
|
let connection_span = tracing::info_span!(
|
||||||
|
"rpcsystem",
|
||||||
|
%peer.ip,
|
||||||
|
peer.port,
|
||||||
|
);
|
||||||
let f = async move {
|
let f = async move {
|
||||||
|
tracing::trace!(parent: &connection_span, "starting tls exchange");
|
||||||
let stream = match stream.await {
|
let stream = match stream.await {
|
||||||
Ok(stream) => stream,
|
Ok(stream) => stream,
|
||||||
Err(e) => {
|
Err(error) => {
|
||||||
tracing::error!("TLS handshake failed: {}", e);
|
tracing::error!(parent: &connection_span, %error, "TLS handshake failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -161,10 +184,15 @@ impl APIServer {
|
|||||||
peer_addr,
|
peer_addr,
|
||||||
self.authentication.clone(),
|
self.authentication.clone(),
|
||||||
self.sessionmanager.clone(),
|
self.sessionmanager.clone(),
|
||||||
|
connection_span.clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
if let Err(e) = RpcSystem::new(Box::new(vat), Some(bootstrap.client)).await {
|
if let Err(error) = RpcSystem::new(Box::new(vat), Some(bootstrap.client)).await {
|
||||||
tracing::error!("Error during RPC handling: {}", e);
|
tracing::error!(
|
||||||
|
parent: &connection_span,
|
||||||
|
%error,
|
||||||
|
"error occured during rpc handling",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let cgroup = SupervisionRegistry::with(SupervisionRegistry::new_group);
|
let cgroup = SupervisionRegistry::with(SupervisionRegistry::new_group);
|
||||||
|
@ -43,7 +43,7 @@ mod tls;
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use futures_util::StreamExt;
|
use futures_util::{FutureExt, StreamExt};
|
||||||
use miette::{Context, IntoDiagnostic, Report};
|
use miette::{Context, IntoDiagnostic, Report};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
@ -94,9 +94,7 @@ impl Diflouroborane {
|
|||||||
}
|
}
|
||||||
tracing::info!("Server is being spawned");
|
tracing::info!("Server is being spawned");
|
||||||
let handle = executor.spawn(server.serve());
|
let handle = executor.spawn(server.serve());
|
||||||
std::thread::spawn(move || {
|
executor.spawn(handle.map(|result| match result {
|
||||||
let result = async_io::block_on(handle);
|
|
||||||
match result {
|
|
||||||
Some(Ok(())) => {
|
Some(Ok(())) => {
|
||||||
tracing::info!("console server finished without error");
|
tracing::info!("console server finished without error");
|
||||||
}
|
}
|
||||||
@ -106,8 +104,7 @@ impl Diflouroborane {
|
|||||||
None => {
|
None => {
|
||||||
tracing::info!("console server finished with panic");
|
tracing::info!("console server finished with panic");
|
||||||
}
|
}
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
let env = StateDB::open_env(&config.db_path)?;
|
let env = StateDB::open_env(&config.db_path)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user