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::Error;
use capnp_rpc::pry;
use rsasl::mechname::Mechname;
use rsasl::property::AuthId;
use rsasl::session::{Session, Step};
use std::fmt;
@ -23,8 +24,18 @@ pub struct Authentication {
}
impl Authentication {
pub fn new(session: Session, sessionmanager: SessionManager) -> Self {
let span = tracing::info_span!(target: TARGET, "Authentication",);
pub fn new(
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!(
target: TARGET,
parent: &span,
@ -121,7 +132,7 @@ impl AuthenticationSystem for Authentication {
"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");
capnp::Error::failed("Failed to lookup the given user".to_string())
}));

View File

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

View File

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

View File

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

View File

@ -17,11 +17,12 @@ impl SessionManager {
}
// 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();
if let Some(user) = self.users.get_user(uid) {
let span = tracing::info_span!(
target: "bffh::api",
parent: parent,
"session",
uid = uid,
);