Skip to content

Commit

Permalink
Adds logs to RPC requests and improves the ones for the http interface
Browse files Browse the repository at this point in the history
Also updates the severity from the http logs from info to debug
  • Loading branch information
sr-gi committed Jan 23, 2023
1 parent d386e56 commit 72b1805
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 23 deletions.
36 changes: 18 additions & 18 deletions teos/src/api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ fn parse_grpc_response<T: serde::Serialize>(
match result {
Ok(r) => {
let inner = r.into_inner();
log::info!("Request succeeded");
log::debug!("Request succeeded");
log::debug!("Response: {}", serde_json::json!(inner));
(reply::json(&inner), StatusCode::OK)
}
Err(s) => {
let (status_code, error_code) = match_status(&s);
log::info!("Request failed, error_code={}", error_code);
log::debug!("Request failed, error_code={}", error_code);
log::debug!("Response: {}", serde_json::json!(s.message()));
(
reply::json(&ApiError::new(s.message().into(), error_code)),
Expand All @@ -119,10 +119,10 @@ async fn register(
addr: Option<std::net::SocketAddr>,
mut grpc_conn: PublicTowerServicesClient<Channel>,
) -> std::result::Result<impl Reply, Rejection> {
match addr {
Some(a) => log::info!("Received register request from {}", a),
None => log::info!("Received register request from unknown address"),
}
log::debug!(
"Received a register request from {}",
addr.map_or("an unknown address".to_owned(), |a| a.to_string())
);

let user_id = req.user_id.clone();
if user_id.is_empty() {
Expand All @@ -145,10 +145,10 @@ async fn add_appointment(
addr: Option<std::net::SocketAddr>,
mut grpc_conn: PublicTowerServicesClient<Channel>,
) -> std::result::Result<impl Reply, Rejection> {
match addr {
Some(a) => log::info!("Received add_appointment request from {}", a),
None => log::info!("Received add_appointment request from unknown address"),
}
log::debug!(
"Received an add_appointment request from {}",
addr.map_or("an unknown address".to_owned(), |a| a.to_string())
);

if let Some(a) = &req.appointment {
if a.locator.is_empty() {
Expand Down Expand Up @@ -177,10 +177,10 @@ async fn get_appointment(
addr: Option<std::net::SocketAddr>,
mut grpc_conn: PublicTowerServicesClient<Channel>,
) -> std::result::Result<impl Reply, Rejection> {
match addr {
Some(a) => log::info!("Received get_appointment request from {}", a),
None => log::info!("Received get_appointment request from unknown address"),
}
log::debug!(
"Received an get_appointment request from {}",
addr.map_or("an unknown address".to_owned(), |a| a.to_string())
);

if req.locator.is_empty() {
return Err(ApiError::empty_field("locator"));
Expand All @@ -205,10 +205,10 @@ async fn get_subscription_info(
addr: Option<std::net::SocketAddr>,
mut grpc_conn: PublicTowerServicesClient<Channel>,
) -> std::result::Result<impl Reply, Rejection> {
match addr {
Some(a) => log::info!("Received get_subscription_info request from {}", a),
None => log::info!("Received get_subscription_info request from unknown address"),
}
log::debug!(
"Received an get_subscription_info request from {}",
addr.map_or("an unknown address".to_owned(), |a| a.to_string())
);

if req.signature.is_empty() {
return Err(ApiError::empty_field("signature"));
Expand Down
53 changes: 48 additions & 5 deletions teos/src/api/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,15 @@ impl PrivateTowerServices for Arc<InternalAPI> {
/// Internally calls [Watcher::get_all_watcher_appointments] and [Watcher::get_all_responder_trackers].
async fn get_all_appointments(
&self,
_: Request<()>,
request: Request<()>,
) -> Result<Response<msgs::GetAllAppointmentsResponse>, Status> {
log::debug!(
"Received a get_all_appointments request from {}",
request
.remote_addr()
.map_or("an unknown address".to_owned(), |a| a.to_string())
);

let mut all_appointments = Vec::new();

for (_, appointment) in self.watcher.get_all_watcher_appointments().into_iter() {
Expand Down Expand Up @@ -265,6 +272,13 @@ impl PrivateTowerServices for Arc<InternalAPI> {
&self,
request: tonic::Request<msgs::GetAppointmentsRequest>,
) -> Result<tonic::Response<msgs::GetAppointmentsResponse>, Status> {
log::debug!(
"Received a get_appointments requests from {}",
request
.remote_addr()
.map_or("an unknown address".to_owned(), |a| a.to_string())
);

let mut matching_appointments = vec![];
let locator = Locator::from_slice(&request.into_inner().locator).map_err(|_| {
Status::new(
Expand Down Expand Up @@ -309,8 +323,15 @@ impl PrivateTowerServices for Arc<InternalAPI> {
/// and [Watcher::get_trackers_count].
async fn get_tower_info(
&self,
_: Request<()>,
request: Request<()>,
) -> Result<Response<msgs::GetTowerInfoResponse>, Status> {
log::debug!(
"Received a get_tower_info request from {}",
request
.remote_addr()
.map_or("an unknown address".to_owned(), |a| a.to_string())
);

Ok(Response::new(msgs::GetTowerInfoResponse {
tower_id: self.watcher.tower_id.to_vec(),
addresses: self.get_addresses().clone(),
Expand All @@ -323,7 +344,17 @@ impl PrivateTowerServices for Arc<InternalAPI> {

/// Get user endpoint. Gets all users in the tower. Part of the private API.
/// Internally calls [Watcher::get_user_ids].
async fn get_users(&self, _: Request<()>) -> Result<Response<msgs::GetUsersResponse>, Status> {
async fn get_users(
&self,
request: Request<()>,
) -> Result<Response<msgs::GetUsersResponse>, Status> {
log::debug!(
"Received a get_users requests from {}",
request
.remote_addr()
.map_or("an unknown address".to_owned(), |a| a.to_string())
);

let user_ids = self
.watcher
.get_user_ids()
Expand All @@ -340,6 +371,13 @@ impl PrivateTowerServices for Arc<InternalAPI> {
&self,
request: Request<msgs::GetUserRequest>,
) -> Result<Response<msgs::GetUserResponse>, Status> {
log::debug!(
"Received a get_user request from {}",
request
.remote_addr()
.map_or("an unknown address".to_owned(), |a| a.to_string())
);

let user_id = UserId::from_slice(&request.into_inner().user_id).map_err(|_| {
Status::new(
Code::InvalidArgument,
Expand All @@ -358,10 +396,15 @@ impl PrivateTowerServices for Arc<InternalAPI> {
}

/// Stop endpoint. Stops the tower daemon. Part of the private API.
async fn stop(&self, _: Request<()>) -> Result<Response<()>, Status> {
async fn stop(&self, request: Request<()>) -> Result<Response<()>, Status> {
self.shutdown_trigger.trigger();

log::debug!("Received shutting down signal, notifying components");
log::debug!(
"Received a shutting down request from {}, notifying components",
request
.remote_addr()
.map_or("an unknown address".to_owned(), |a| a.to_string())
);
Ok(Response::new(()))
}
}
Expand Down

0 comments on commit 72b1805

Please sign in to comment.