Output plentiful trace info for API calls

This commit is contained in:
Nadja Reitzenstein 2022-06-24 14:35:19 +02:00
parent 1ff3f2afb7
commit 257fbf5506
5 changed files with 43 additions and 12 deletions

View File

@ -1,6 +1,7 @@
use capnp::capability::Promise; use capnp::capability::Promise;
use capnp::Error; use capnp::Error;
use capnp_rpc::pry; use capnp_rpc::pry;
use rsasl::mechname::Mechname;
use rsasl::property::AuthId; use rsasl::property::AuthId;
use rsasl::session::{Session, Step}; use rsasl::session::{Session, Step};
use std::fmt; use std::fmt;
@ -23,8 +24,18 @@ pub struct Authentication {
} }
impl Authentication { impl Authentication {
pub fn new(session: Session, sessionmanager: SessionManager) -> Self { pub fn new(
let span = tracing::info_span!(target: TARGET, "Authentication",); parent: &Span,
mechanism: &Mechname, /* TODO: this is stored in session as well, get it out of there. */
session: Session,
sessionmanager: SessionManager,
) -> Self {
let span = tracing::info_span!(
target: TARGET,
parent: parent,
"Authentication",
mechanism = mechanism.as_str()
);
tracing::trace!( tracing::trace!(
target: TARGET, target: TARGET,
parent: &span, parent: &span,
@ -121,7 +132,7 @@ impl AuthenticationSystem for Authentication {
"Authentication didn't provide an authid as required".to_string(), "Authentication didn't provide an authid as required".to_string(),
) )
})); }));
let session = pry!(manager.open(uid.as_ref()).ok_or_else(|| { let session = pry!(manager.open(&self.span, uid.as_ref()).ok_or_else(|| {
tracing::warn!(uid = uid.as_str(), "Failed to lookup the given user"); tracing::warn!(uid = uid.as_str(), "Failed to lookup the given user");
capnp::Error::failed("Failed to lookup the given user".to_string()) capnp::Error::failed("Failed to lookup the given user".to_string())
})); }));

View File

@ -90,7 +90,7 @@ impl bootstrap::Server for BootCap {
"mechanisms", "mechanisms",
) )
.entered(); .entered();
tracing::trace!("method call"); tracing::trace!(target: "bffh::api", "method call");
let builder = result.get(); let builder = result.get();
let mechs: Vec<_> = self let mechs: Vec<_> = self
@ -149,7 +149,7 @@ impl bootstrap::Server for BootCap {
let mechname = Mechname::new(mechanism.as_bytes()); let mechname = Mechname::new(mechanism.as_bytes());
let auth = if let Ok(mechname) = mechname { let auth = if let Ok(mechname) = mechname {
if let Ok(session) = self.authentication.start(mechname) { if let Ok(session) = self.authentication.start(mechname) {
Authentication::new(session, self.sessionmanager.clone()) Authentication::new(&self.span, mechname, session, self.sessionmanager.clone())
} else { } else {
Authentication::invalid_mechanism() Authentication::invalid_mechanism()
} }

View File

@ -165,7 +165,7 @@ impl APIServer {
let connection_span = tracing::info_span!( let connection_span = tracing::info_span!(
target: "bffh::api", target: "bffh::api",
"Bootstrap", "connection",
%peer.ip, %peer.ip,
peer.port, peer.port,
); );

View File

@ -17,6 +17,7 @@ use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use std::time::Duration; use std::time::Duration;
use tracing::Span;
use url::Url; use url::Url;
mod dummy; mod dummy;
@ -33,12 +34,17 @@ pub trait Initiator: Future<Output = ()> {
#[derive(Clone)] #[derive(Clone)]
pub struct InitiatorCallbacks { pub struct InitiatorCallbacks {
span: Span,
resource: Resource, resource: Resource,
sessions: SessionManager, sessions: SessionManager,
} }
impl InitiatorCallbacks { impl InitiatorCallbacks {
pub fn new(resource: Resource, sessions: SessionManager) -> Self { pub fn new(span: Span, resource: Resource, sessions: SessionManager) -> Self {
Self { resource, sessions } Self {
span,
resource,
sessions,
}
} }
pub async fn try_update(&mut self, session: SessionHandle, status: Status) { pub async fn try_update(&mut self, session: SessionHandle, status: Status) {
@ -46,17 +52,19 @@ impl InitiatorCallbacks {
} }
pub fn open_session(&self, uid: &str) -> Option<SessionHandle> { pub fn open_session(&self, uid: &str) -> Option<SessionHandle> {
self.sessions.open(uid) self.sessions.open(&self.span, uid)
} }
} }
pub struct InitiatorDriver { pub struct InitiatorDriver {
span: Span,
name: String, name: String,
initiator: Box<dyn Initiator + Unpin + Send>, initiator: Box<dyn Initiator + Unpin + Send>,
} }
impl InitiatorDriver { impl InitiatorDriver {
pub fn new<I>( pub fn new<I>(
span: Span,
name: String, name: String,
params: &HashMap<String, String>, params: &HashMap<String, String>,
resource: Resource, resource: Resource,
@ -65,9 +73,13 @@ impl InitiatorDriver {
where where
I: 'static + Initiator + Unpin + Send, I: 'static + Initiator + Unpin + Send,
{ {
let callbacks = InitiatorCallbacks::new(resource, sessions); let callbacks = InitiatorCallbacks::new(span.clone(), resource, sessions);
let initiator = Box::new(I::new(params, callbacks)?); let initiator = Box::new(I::new(params, callbacks)?);
Ok(Self { name, initiator }) Ok(Self {
span,
name,
initiator,
})
} }
} }
@ -133,15 +145,22 @@ fn load_single(
resource: Resource, resource: Resource,
sessions: &SessionManager, sessions: &SessionManager,
) -> Option<InitiatorDriver> { ) -> Option<InitiatorDriver> {
let span = tracing::info_span!(
"initiator",
name = %name,
module = %module_name,
);
tracing::info!(%name, %module_name, ?params, "Loading initiator"); tracing::info!(%name, %module_name, ?params, "Loading initiator");
let o = match module_name.as_ref() { let o = match module_name.as_ref() {
"Dummy" => Some(InitiatorDriver::new::<Dummy>( "Dummy" => Some(InitiatorDriver::new::<Dummy>(
span,
name.clone(), name.clone(),
params, params,
resource, resource,
sessions.clone(), sessions.clone(),
)), )),
"Process" => Some(InitiatorDriver::new::<Process>( "Process" => Some(InitiatorDriver::new::<Process>(
span,
name.clone(), name.clone(),
params, params,
resource, resource,

View File

@ -17,11 +17,12 @@ impl SessionManager {
} }
// TODO: make infallible // TODO: make infallible
pub fn open(&self, uid: impl AsRef<str>) -> Option<SessionHandle> { pub fn open(&self, parent: &Span, uid: impl AsRef<str>) -> Option<SessionHandle> {
let uid = uid.as_ref(); let uid = uid.as_ref();
if let Some(user) = self.users.get_user(uid) { if let Some(user) = self.users.get_user(uid) {
let span = tracing::info_span!( let span = tracing::info_span!(
target: "bffh::api", target: "bffh::api",
parent: parent,
"session", "session",
uid = uid, uid = uid,
); );