Skip to content

Commit 4183e03

Browse files
Alexandra Iordacheacatangiu
authored andcommitted
log requests that generate err responses as errors
Fixes #741 Signed-off-by: Alexandra Iordache <[email protected]>
1 parent 28f44b3 commit 4183e03

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

api_server/src/http_service.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,27 @@ impl hyper::server::Service for ApiServerHttpService {
537537
// available.
538538
Either::B(
539539
outcome_receiver
540-
.map(move |x| {
541-
info!(
542-
"Received Success on {}",
543-
describe(&method_copy, &path_copy, &b_str)
544-
);
545-
x.generate_response()
540+
.map(move |result| {
541+
let description = describe(&method_copy, &path_copy, &b_str);
542+
// `generate_response` and `err` both consume the inner error.
543+
// Errors aren't `Clone`-able so we can't back it up either,
544+
// so we'll rely on the fact that the error was previously
545+
// logged at its point of origin and not log it again.
546+
let response = result.generate_response();
547+
let status_code = response.status();
548+
if result.is_ok() {
549+
info!(
550+
"Received Success {} on {}",
551+
status_code, description
552+
);
553+
} else {
554+
error!("Received Error {} on {}", status_code, description);
555+
}
556+
response
546557
})
547558
.map_err(move |_| {
548-
info!(
549-
"Received Error on {}",
559+
error!(
560+
"Timeout on {}",
550561
describe(&method_copy_err, &path_copy_err, &b_str_err)
551562
);
552563
METRICS.api_server.sync_outcome_fails.inc();
@@ -561,9 +572,14 @@ impl hyper::server::Service for ApiServerHttpService {
561572
}
562573
}
563574

564-
/// Helper function for metric-logging purposes on API requests
565-
/// `method` is whether PUT or GET
566-
/// `path` and `body` represent path of the API request and body, respectively
575+
/// Helper function for metric-logging purposes on API requests.
576+
///
577+
/// # Arguments
578+
///
579+
/// * `method` - one of `GET`, `PATCH`, `PUT`
580+
/// * `path` - path of the API request
581+
/// * `body` - body of the API request
582+
///
567583
fn describe(method: &Method, path: &String, body: &String) -> String {
568584
format!(
569585
"synchronous {:?} request {:?} with body {:?}",

0 commit comments

Comments
 (0)