Skip to content

Commit

Permalink
chore: Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nickamzol committed Apr 16, 2024
1 parent a7c3738 commit bc1fd69
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/backend/dimse/association/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ impl ClientAssociation {
};

while let Some(command) = rx.blocking_recv() {
debug!("{command:?}");
let result = match command {
Command::Send(pdu, reply_to) => {
let send_result = Self::chunked_send(&mut association, &pdu);
Expand Down
2 changes: 0 additions & 2 deletions src/backend/dimse/association/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ impl ServerAssociation {
};

while let Some(command) = rx.blocking_recv() {
debug!("{command:?}");

let result = match command {
Command::Send(pdu, response) => {
let send_result = association.send(&pdu).map_err(|e| e.into());
Expand Down
3 changes: 3 additions & 0 deletions src/backend/dimse/cfind/findscu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use dicom::object::InMemDicomObject;
use futures::Stream;
use std::time::Duration;
use thiserror::Error;
use tracing::{debug, trace};

pub struct FindServiceClassUser {
pool: AssociationPool,
Expand Down Expand Up @@ -71,10 +72,12 @@ impl FindServiceClassUser {
let association = self.pool.get(presentation).await?;
let request = CompositeFindRequest::from(options);
association.write_message(request, self.timeout).await?;
trace!("Sent C-FIND-RQ");

loop {
let response = association.read_message(self.timeout).await?;
let response = CompositeFindResponse::try_from(response)?;
trace!("Received C-FIND-RSP");

if let Some(data) = response.data {
yield data;
Expand Down
9 changes: 6 additions & 3 deletions src/backend/dimse/cmove/movescu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use dicom::dictionary_std::{tags, uids};
use dicom::object::mem::InMemElement;
use std::time::Duration;
use thiserror::Error;
use tracing::{debug, trace};
use tracing::{debug, error, info, instrument, trace};

pub struct MoveServiceClassUser {
pool: AssociationPool,
Expand All @@ -27,6 +27,7 @@ impl MoveServiceClassUser {
self
}

#[instrument(skip_all, name = "MOVE-SCU")]
pub async fn invoke(&self, request: CompositeMoveRequest) -> Result<(), MoveError> {
let association = self
.pool
Expand All @@ -39,9 +40,11 @@ impl MoveServiceClassUser {
.await?;

association.write_message(request, self.timeout).await?;
trace!("Sent C-MOVE-RQ");

loop {
let response = association.read_message(self.timeout).await?;
trace!("Received C-MOVE-RSP");

let status_type = response
.command
Expand All @@ -53,15 +56,15 @@ impl MoveServiceClassUser {

match status_type {
StatusType::Success => {
debug!("C-MOVE completed successfully");
info!("C-MOVE completed successfully");
break;
}
StatusType::Pending => {
trace!("C-MOVE is pending");
}
StatusType::Cancel => return Err(MoveError::Cancelled),
StatusType::Failure | StatusType::Warning => {
debug!("C-MOVE operation failed");
error!("C-MOVE sub-operation failed");
return Err(MoveError::OperationFailed);
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/backend/dimse/cstore/storescp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,24 @@ impl StoreServiceClassProvider {
}
}

#[instrument(skip_all, name = " STORE-SCP")]
pub async fn spawn(&self) -> anyhow::Result<()> {
let address = SocketAddr::from((self.inner.config.host, self.inner.config.port));
let listener = TcpListener::bind(&address).await?;
info!("Started Store Service Class Provider on {}", address);
loop {
match listener.accept().await {
Ok((stream, peer)) => {
let span = info_span!("STORE-SCP", peer = peer.to_string());
info!("Accepted incoming connection from {peer}");
let inner = Arc::clone(&self.inner);
tokio::spawn(Self::process(stream, inner));
tokio::spawn(Self::process(stream, inner).instrument(span));
}
Err(err) => error!("Failed to accept incoming connection: {err}"),
};
}
}

#[instrument(skip_all)]
async fn process(
stream: TcpStream,
inner: Arc<InnerStoreServiceClassProvider>,
Expand Down Expand Up @@ -108,7 +109,11 @@ impl StoreServiceClassProvider {
.and_then(Result::ok)
.context("Missing tag AFFECTED_SOP_INSTANCE_UID (0000,1000)")?;

debug!("Received instance {} ({})", sop_instance_uid, sop_class_uid);
info!(
sop_instance_uid = sop_instance_uid.as_ref(),
sop_class_uid = sop_class_uid.as_ref(),
"Received instance"
);
let response = CompositeStoreResponse {
sop_instance_uid: UI::from(sop_instance_uid.clone()),
sop_class_uid: UI::from(sop_class_uid.clone()),
Expand Down
4 changes: 4 additions & 0 deletions src/backend/dimse/cstore/storescu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use association::AssociationError;
use dicom::object::{FileDicomObject, InMemDicomObject};
use std::time::Duration;
use thiserror::Error;
use tracing::trace;

pub struct StoreServiceClassUser {
pool: AssociationPool,
Expand Down Expand Up @@ -40,8 +41,11 @@ impl StoreServiceClassUser {
};

association.write_message(request, self.timeout).await?;
trace!("Sent C-STORE-RQ");

association.read_message(self.timeout).await?;
trace!("Received C-STORE-RSP");

Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/dimse/qido.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use dicom::dictionary_std::tags;
use dicom::object::InMemDicomObject;
use futures::{StreamExt, TryStreamExt};
use std::time::Duration;
use tracing::warn;
use tracing::{info, warn};

pub struct DimseQidoService {
findscu: FindServiceClassUser,
Expand Down

0 comments on commit bc1fd69

Please sign in to comment.