Skip to content

Commit 72b1805

Browse files
committed
Adds logs to RPC requests and improves the ones for the http interface
Also updates the severity from the http logs from info to debug
1 parent d386e56 commit 72b1805

File tree

2 files changed

+66
-23
lines changed

2 files changed

+66
-23
lines changed

teos/src/api/http.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ fn parse_grpc_response<T: serde::Serialize>(
9898
match result {
9999
Ok(r) => {
100100
let inner = r.into_inner();
101-
log::info!("Request succeeded");
101+
log::debug!("Request succeeded");
102102
log::debug!("Response: {}", serde_json::json!(inner));
103103
(reply::json(&inner), StatusCode::OK)
104104
}
105105
Err(s) => {
106106
let (status_code, error_code) = match_status(&s);
107-
log::info!("Request failed, error_code={}", error_code);
107+
log::debug!("Request failed, error_code={}", error_code);
108108
log::debug!("Response: {}", serde_json::json!(s.message()));
109109
(
110110
reply::json(&ApiError::new(s.message().into(), error_code)),
@@ -119,10 +119,10 @@ async fn register(
119119
addr: Option<std::net::SocketAddr>,
120120
mut grpc_conn: PublicTowerServicesClient<Channel>,
121121
) -> std::result::Result<impl Reply, Rejection> {
122-
match addr {
123-
Some(a) => log::info!("Received register request from {}", a),
124-
None => log::info!("Received register request from unknown address"),
125-
}
122+
log::debug!(
123+
"Received a register request from {}",
124+
addr.map_or("an unknown address".to_owned(), |a| a.to_string())
125+
);
126126

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

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

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

213213
if req.signature.is_empty() {
214214
return Err(ApiError::empty_field("signature"));

teos/src/api/internal.rs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,15 @@ impl PrivateTowerServices for Arc<InternalAPI> {
232232
/// Internally calls [Watcher::get_all_watcher_appointments] and [Watcher::get_all_responder_trackers].
233233
async fn get_all_appointments(
234234
&self,
235-
_: Request<()>,
235+
request: Request<()>,
236236
) -> Result<Response<msgs::GetAllAppointmentsResponse>, Status> {
237+
log::debug!(
238+
"Received a get_all_appointments request from {}",
239+
request
240+
.remote_addr()
241+
.map_or("an unknown address".to_owned(), |a| a.to_string())
242+
);
243+
237244
let mut all_appointments = Vec::new();
238245

239246
for (_, appointment) in self.watcher.get_all_watcher_appointments().into_iter() {
@@ -265,6 +272,13 @@ impl PrivateTowerServices for Arc<InternalAPI> {
265272
&self,
266273
request: tonic::Request<msgs::GetAppointmentsRequest>,
267274
) -> Result<tonic::Response<msgs::GetAppointmentsResponse>, Status> {
275+
log::debug!(
276+
"Received a get_appointments requests from {}",
277+
request
278+
.remote_addr()
279+
.map_or("an unknown address".to_owned(), |a| a.to_string())
280+
);
281+
268282
let mut matching_appointments = vec![];
269283
let locator = Locator::from_slice(&request.into_inner().locator).map_err(|_| {
270284
Status::new(
@@ -309,8 +323,15 @@ impl PrivateTowerServices for Arc<InternalAPI> {
309323
/// and [Watcher::get_trackers_count].
310324
async fn get_tower_info(
311325
&self,
312-
_: Request<()>,
326+
request: Request<()>,
313327
) -> Result<Response<msgs::GetTowerInfoResponse>, Status> {
328+
log::debug!(
329+
"Received a get_tower_info request from {}",
330+
request
331+
.remote_addr()
332+
.map_or("an unknown address".to_owned(), |a| a.to_string())
333+
);
334+
314335
Ok(Response::new(msgs::GetTowerInfoResponse {
315336
tower_id: self.watcher.tower_id.to_vec(),
316337
addresses: self.get_addresses().clone(),
@@ -323,7 +344,17 @@ impl PrivateTowerServices for Arc<InternalAPI> {
323344

324345
/// Get user endpoint. Gets all users in the tower. Part of the private API.
325346
/// Internally calls [Watcher::get_user_ids].
326-
async fn get_users(&self, _: Request<()>) -> Result<Response<msgs::GetUsersResponse>, Status> {
347+
async fn get_users(
348+
&self,
349+
request: Request<()>,
350+
) -> Result<Response<msgs::GetUsersResponse>, Status> {
351+
log::debug!(
352+
"Received a get_users requests from {}",
353+
request
354+
.remote_addr()
355+
.map_or("an unknown address".to_owned(), |a| a.to_string())
356+
);
357+
327358
let user_ids = self
328359
.watcher
329360
.get_user_ids()
@@ -340,6 +371,13 @@ impl PrivateTowerServices for Arc<InternalAPI> {
340371
&self,
341372
request: Request<msgs::GetUserRequest>,
342373
) -> Result<Response<msgs::GetUserResponse>, Status> {
374+
log::debug!(
375+
"Received a get_user request from {}",
376+
request
377+
.remote_addr()
378+
.map_or("an unknown address".to_owned(), |a| a.to_string())
379+
);
380+
343381
let user_id = UserId::from_slice(&request.into_inner().user_id).map_err(|_| {
344382
Status::new(
345383
Code::InvalidArgument,
@@ -358,10 +396,15 @@ impl PrivateTowerServices for Arc<InternalAPI> {
358396
}
359397

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

364-
log::debug!("Received shutting down signal, notifying components");
402+
log::debug!(
403+
"Received a shutting down request from {}, notifying components",
404+
request
405+
.remote_addr()
406+
.map_or("an unknown address".to_owned(), |a| a.to_string())
407+
);
365408
Ok(Response::new(()))
366409
}
367410
}

0 commit comments

Comments
 (0)