Skip to content

Commit 9150e62

Browse files
chore: Reduce cpu-config API log verbosity
PUT /cpu-config API will include the request payload which should contain the CPU config template only for DEBUG log levels or higher. Signed-off-by: Matthew Schlebusch <[email protected]>
1 parent 83bde9c commit 9150e62

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/api_server/src/parsed_request.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use logger::{error, info};
4+
use logger::{error, info, log_enabled, Level};
55
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
66
use serde::ser::Serialize;
77
use serde_json::Value;
@@ -232,17 +232,34 @@ fn log_received_api_request(api_description: String) {
232232
fn describe(method: Method, path: &str, body: Option<&Body>) -> String {
233233
match (path, body) {
234234
("/mmds", Some(_)) | (_, None) => format!("{:?} request on {:?}", method, path),
235-
(_, Some(value)) => format!(
236-
"{:?} request on {:?} with body {:?}",
237-
method,
238-
path,
239-
std::str::from_utf8(value.body.as_slice())
240-
.unwrap_or("inconvertible to UTF-8")
241-
.to_string()
242-
),
235+
("/cpu-config", Some(payload_value)) => {
236+
// If the log level is at Debug or higher, include the CPU template in
237+
// the log line.
238+
if log_enabled!(Level::Debug) {
239+
describe_with_body(method, path, payload_value)
240+
} else {
241+
format!(
242+
"{:?} request on {:?}. To view the CPU template received by the API, \
243+
configure log-level to DEBUG",
244+
method, path
245+
)
246+
}
247+
}
248+
(_, Some(payload_value)) => describe_with_body(method, path, payload_value),
243249
}
244250
}
245251

252+
fn describe_with_body(method: Method, path: &str, payload_value: &Body) -> String {
253+
format!(
254+
"{:?} request on {:?} with body {:?}",
255+
method,
256+
path,
257+
std::str::from_utf8(payload_value.body.as_slice())
258+
.unwrap_or("inconvertible to UTF-8")
259+
.to_string()
260+
)
261+
}
262+
246263
/// Generates a `GenericError` for each request method.
247264
pub(crate) fn method_to_error(method: Method) -> Result<ParsedRequest, Error> {
248265
match method {

tests/integration_tests/build/test_coverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def is_on_skylake():
2525
# Checkout the cpuid crate. In the future other
2626
# differences may appear.
2727
if utils.is_io_uring_supported():
28-
COVERAGE_DICT = {"Intel": 83.76, "AMD": 83.34, "ARM": 83.12}
28+
COVERAGE_DICT = {"Intel": 83.76, "AMD": 83.34, "ARM": 83.18}
2929
else:
3030
COVERAGE_DICT = {"Intel": 81.02, "AMD": 80.55, "ARM": 80.19}
3131

0 commit comments

Comments
 (0)