Skip to content

Commit 4a106a4

Browse files
committed
clean up debug printing
1 parent 440cf65 commit 4a106a4

1 file changed

Lines changed: 51 additions & 79 deletions

File tree

booster_sdk/src/dds/rpc.rs

Lines changed: 51 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,6 @@ fn normalize_service_topic(service_topic: &str) -> String {
123123
trimmed.to_owned()
124124
}
125125

126-
fn rpc_debug_enabled() -> bool {
127-
std::env::var("BOOSTER_RPC_DEBUG")
128-
.map(|value| {
129-
let value = value.trim();
130-
value == "1"
131-
|| value.eq_ignore_ascii_case("true")
132-
|| value.eq_ignore_ascii_case("yes")
133-
|| value.eq_ignore_ascii_case("on")
134-
})
135-
.unwrap_or(false)
136-
}
137-
138126
fn preview_for_log(value: &str, max_chars: usize) -> String {
139127
let mut preview = String::new();
140128
let mut chars = value.chars();
@@ -255,19 +243,15 @@ impl RpcClient {
255243
where
256244
R: DeserializeOwned + Send + 'static,
257245
{
258-
let debug_enabled = rpc_debug_enabled();
259-
260246
if self.startup_wait > Duration::from_millis(0)
261247
&& !self.startup_wait_done.swap(true, Ordering::SeqCst)
262248
{
263-
if debug_enabled {
264-
tracing::debug!(
265-
target: "booster_sdk::rpc",
266-
service_topic = %self.service_topic,
267-
startup_wait_ms = self.startup_wait.as_millis(),
268-
"initial startup wait before first rpc call"
269-
);
270-
}
249+
tracing::debug!(
250+
target: "booster_sdk::rpc",
251+
service_topic = %self.service_topic,
252+
startup_wait_ms = self.startup_wait.as_millis(),
253+
"initial startup wait before first rpc call"
254+
);
271255
tokio::time::sleep(self.startup_wait).await;
272256
}
273257

@@ -279,17 +263,15 @@ impl RpcClient {
279263
let header = serde_json::json!({ "api_id": api_id }).to_string();
280264
let service_topic = self.service_topic.clone();
281265

282-
if debug_enabled {
283-
tracing::debug!(
284-
target: "booster_sdk::rpc",
285-
service_topic = %service_topic,
286-
api_id,
287-
request_uuid = %request_id,
288-
header = %preview_for_log(&header, 200),
289-
body = %preview_for_log(&body, 300),
290-
"send rpc request"
291-
);
292-
}
266+
tracing::debug!(
267+
target: "booster_sdk::rpc",
268+
service_topic = %service_topic,
269+
api_id,
270+
request_uuid = %request_id,
271+
header = %preview_for_log(&header, 200),
272+
body = %preview_for_log(&body, 300),
273+
"send rpc request"
274+
);
293275

294276
let request = RpcReqMsg {
295277
uuid: request_id.clone(),
@@ -309,16 +291,14 @@ impl RpcClient {
309291
let response = match tokio::time::timeout(remaining, response_stream.next()).await {
310292
Ok(Some(Ok(sample))) => sample.into_value(),
311293
Ok(Some(Err(err))) => {
312-
if debug_enabled {
313-
tracing::warn!(
314-
target: "booster_sdk::rpc",
315-
service_topic = %service_topic,
316-
api_id,
317-
request_uuid = %request_id,
318-
error = %err,
319-
"rpc receive error"
320-
);
321-
}
294+
tracing::warn!(
295+
target: "booster_sdk::rpc",
296+
service_topic = %service_topic,
297+
api_id,
298+
request_uuid = %request_id,
299+
error = %err,
300+
"rpc receive error"
301+
);
322302
return Err(DdsError::ReceiveFailed(err.to_string()).into());
323303
}
324304
Ok(None) => {
@@ -327,59 +307,51 @@ impl RpcClient {
327307
);
328308
}
329309
Err(_) => {
330-
if debug_enabled {
331-
tracing::warn!(
332-
target: "booster_sdk::rpc",
333-
service_topic = %service_topic,
334-
api_id,
335-
request_uuid = %request_id,
336-
timeout_ms = timeout.as_millis(),
337-
"rpc timeout"
338-
);
339-
}
340-
return Err(RpcError::Timeout { timeout }.into());
341-
}
342-
};
343-
344-
if response.uuid != request_id {
345-
if debug_enabled {
346-
tracing::debug!(
310+
tracing::warn!(
347311
target: "booster_sdk::rpc",
348312
service_topic = %service_topic,
349313
api_id,
350314
request_uuid = %request_id,
351-
response_uuid = %response.uuid,
352-
"ignoring response for a different request uuid"
315+
timeout_ms = timeout.as_millis(),
316+
"rpc timeout"
353317
);
318+
return Err(RpcError::Timeout { timeout }.into());
354319
}
355-
continue;
356-
}
320+
};
357321

358-
let status_code = parse_status_from_header(&response.header).unwrap_or(0);
359-
if debug_enabled {
322+
if response.uuid != request_id {
360323
tracing::debug!(
361324
target: "booster_sdk::rpc",
362325
service_topic = %service_topic,
363326
api_id,
364327
request_uuid = %request_id,
365328
response_uuid = %response.uuid,
366-
status_code,
367-
header = %preview_for_log(&response.header, 200),
368-
body = %preview_for_log(&response.body, 300),
369-
"recv rpc response"
329+
"ignoring response for a different request uuid"
370330
);
331+
continue;
371332
}
372333

334+
let status_code = parse_status_from_header(&response.header).unwrap_or(0);
335+
tracing::debug!(
336+
target: "booster_sdk::rpc",
337+
service_topic = %service_topic,
338+
api_id,
339+
request_uuid = %request_id,
340+
response_uuid = %response.uuid,
341+
status_code,
342+
header = %preview_for_log(&response.header, 200),
343+
body = %preview_for_log(&response.body, 300),
344+
"recv rpc response"
345+
);
346+
373347
if status_code == -1 {
374-
if debug_enabled {
375-
tracing::debug!(
376-
target: "booster_sdk::rpc",
377-
service_topic = %service_topic,
378-
api_id,
379-
request_uuid = %request_id,
380-
"ignoring intermediate status=-1"
381-
);
382-
}
348+
tracing::debug!(
349+
target: "booster_sdk::rpc",
350+
service_topic = %service_topic,
351+
api_id,
352+
request_uuid = %request_id,
353+
"ignoring intermediate status=-1"
354+
);
383355
continue;
384356
}
385357

0 commit comments

Comments
 (0)