Skip to content

Commit 8804768

Browse files
author
Jonathan Woollett-Light
committed
fix: tracing::instrument
Adds function instrumentation. Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
1 parent ddedc10 commit 8804768

File tree

221 files changed

+2302
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+2302
-5
lines changed

src/api_server/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl ApiServer {
6363
/// Constructor for `ApiServer`.
6464
///
6565
/// Returns the newly formed `ApiServer`.
66+
#[tracing::instrument(level = "trace", ret)]
6667
pub fn new(
6768
api_request_sender: mpsc::Sender<ApiRequest>,
6869
vmm_response_receiver: mpsc::Receiver<ApiResponse>,
@@ -147,6 +148,7 @@ impl ApiServer {
147148
/// let mut buf: [u8; 100] = [0; 100];
148149
/// assert!(sock.read(&mut buf[..]).unwrap() > 0);
149150
/// ```
151+
#[tracing::instrument(level = "trace", ret)]
150152
pub fn bind_and_run(
151153
&mut self,
152154
path: &PathBuf,
@@ -223,6 +225,7 @@ impl ApiServer {
223225
}
224226

225227
/// Handles an API request received through the associated socket.
228+
#[tracing::instrument(level = "trace", ret)]
226229
pub fn handle_request(
227230
&mut self,
228231
request: &Request,
@@ -252,6 +255,7 @@ impl ApiServer {
252255
}
253256
}
254257

258+
#[tracing::instrument(level = "trace", ret)]
255259
fn serve_vmm_action_request(
256260
&mut self,
257261
vmm_action: Box<VmmAction>,
@@ -294,12 +298,14 @@ impl ApiServer {
294298
}
295299

296300
/// An HTTP response which also includes a body.
301+
#[tracing::instrument(level = "trace", ret)]
297302
pub(crate) fn json_response<T: Into<String> + Debug>(status: StatusCode, body: T) -> Response {
298303
let mut response = Response::new(Version::Http11, status);
299304
response.set_body(Body::new(body.into()));
300305
response
301306
}
302307

308+
#[tracing::instrument(level = "trace", ret)]
303309
fn json_fault_message<T: AsRef<str> + serde::Serialize + Debug>(msg: T) -> String {
304310
json!({ "fault_message": msg }).to_string()
305311
}

src/api_server/src/parsed_request.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ pub(crate) struct ParsingInfo {
4141
}
4242

4343
impl ParsingInfo {
44+
#[tracing::instrument(level = "trace", ret)]
4445
pub fn append_deprecation_message(&mut self, message: &str) {
4546
match self.deprecation_message.as_mut() {
4647
None => self.deprecation_message = Some(message.to_owned()),
4748
Some(s) => (*s).push_str(message),
4849
}
4950
}
5051

52+
#[tracing::instrument(level = "trace", ret)]
5153
pub fn take_deprecation_message(&mut self) -> Option<String> {
5254
self.deprecation_message.take()
5355
}
@@ -121,21 +123,25 @@ impl TryFrom<&Request> for ParsedRequest {
121123
}
122124

123125
impl ParsedRequest {
126+
#[tracing::instrument(level = "trace", ret)]
124127
pub(crate) fn new(action: RequestAction) -> Self {
125128
Self {
126129
action,
127130
parsing_info: Default::default(),
128131
}
129132
}
130-
133+
134+
#[tracing::instrument(level = "trace", ret)]
131135
pub(crate) fn into_parts(self) -> (RequestAction, ParsingInfo) {
132136
(self.action, self.parsing_info)
133137
}
134138

139+
#[tracing::instrument(level = "trace")]
135140
pub(crate) fn parsing_info(&mut self) -> &mut ParsingInfo {
136141
&mut self.parsing_info
137142
}
138143

144+
#[tracing::instrument(level = "trace", ret)]
139145
pub(crate) fn success_response_with_data<T>(body_data: &T) -> Response
140146
where
141147
T: ?Sized + Serialize + Debug,
@@ -146,6 +152,7 @@ impl ParsedRequest {
146152
response
147153
}
148154

155+
#[tracing::instrument(level = "trace", ret)]
149156
pub(crate) fn success_response_with_mmds_value(body_data: &Value) -> Response {
150157
info!("The request was executed successfully. Status code: 200 OK.");
151158
let mut response = Response::new(Version::Http11, StatusCode::OK);
@@ -157,6 +164,7 @@ impl ParsedRequest {
157164
response
158165
}
159166

167+
#[tracing::instrument(level = "trace", ret)]
160168
pub(crate) fn convert_to_response(
161169
request_outcome: &std::result::Result<VmmData, VmmActionError>,
162170
) -> Response {
@@ -206,6 +214,7 @@ impl ParsedRequest {
206214
}
207215

208216
/// Helper function to avoid boiler-plate code.
217+
#[tracing::instrument(level = "trace", ret)]
209218
pub(crate) fn new_sync(vmm_action: VmmAction) -> ParsedRequest {
210219
ParsedRequest::new(RequestAction::Sync(Box::new(vmm_action)))
211220
}
@@ -215,6 +224,7 @@ impl ParsedRequest {
215224
///
216225
/// The `info` macro is used for logging.
217226
#[inline]
227+
#[tracing::instrument(level = "trace", ret)]
218228
fn log_received_api_request(api_description: String) {
219229
info!("The API server received a {}.", api_description);
220230
}
@@ -226,6 +236,7 @@ fn log_received_api_request(api_description: String) {
226236
/// * `method` - one of `GET`, `PATCH`, `PUT`
227237
/// * `path` - path of the API request
228238
/// * `body` - body of the API request
239+
#[tracing::instrument(level = "trace", ret)]
229240
fn describe(method: Method, path: &str, body: Option<&Body>) -> String {
230241
match (path, body) {
231242
("/mmds", Some(_)) | (_, None) => format!("{:?} request on {:?}", method, path),
@@ -241,6 +252,7 @@ fn describe(method: Method, path: &str, body: Option<&Body>) -> String {
241252
}
242253

243254
/// Generates a `GenericError` for each request method.
255+
#[tracing::instrument(level = "trace", ret)]
244256
pub(crate) fn method_to_error(method: Method) -> Result<ParsedRequest, Error> {
245257
match method {
246258
Method::Get => Err(Error::Generic(
@@ -279,6 +291,7 @@ pub(crate) enum Error {
279291

280292
// It's convenient to turn errors into HTTP responses directly.
281293
impl From<Error> for Response {
294+
#[tracing::instrument(level = "trace", ret)]
282295
fn from(err: Error) -> Self {
283296
let msg = ApiServer::json_fault_message(format!("{}", err));
284297
match err {
@@ -292,6 +305,7 @@ impl From<Error> for Response {
292305
}
293306

294307
// This function is supposed to do id validation for requests.
308+
#[tracing::instrument(level = "trace", ret)]
295309
pub(crate) fn checked_id(id: &str) -> Result<&str, Error> {
296310
// todo: are there any checks we want to do on id's?
297311
// not allow them to be empty strings maybe?
@@ -324,6 +338,7 @@ pub mod tests {
324338
use super::*;
325339

326340
impl PartialEq for ParsedRequest {
341+
#[tracing::instrument(level = "trace", ret)]
327342
fn eq(&self, other: &ParsedRequest) -> bool {
328343
if self.parsing_info.deprecation_message != other.parsing_info.deprecation_message {
329344
return false;
@@ -338,13 +353,15 @@ pub mod tests {
338353
}
339354
}
340355

356+
#[tracing::instrument(level = "trace", ret)]
341357
pub(crate) fn vmm_action_from_request(req: ParsedRequest) -> VmmAction {
342358
match req.action {
343359
RequestAction::Sync(vmm_action) => *vmm_action,
344360
_ => panic!("Invalid request"),
345361
}
346362
}
347363

364+
#[tracing::instrument(level = "trace", ret)]
348365
pub(crate) fn depr_action_from_req(req: ParsedRequest, msg: Option<String>) -> VmmAction {
349366
let (action_req, mut parsing_info) = req.into_parts();
350367
match action_req {
@@ -358,6 +375,7 @@ pub mod tests {
358375
}
359376
}
360377

378+
#[tracing::instrument(level = "trace", ret)]
361379
fn http_response(body: &str, status_code: i32) -> String {
362380
let header = format!(
363381
"HTTP/1.1 {} \r\nServer: Firecracker API\r\nConnection: keep-alive\r\n",
@@ -377,6 +395,7 @@ pub mod tests {
377395
}
378396
}
379397

398+
#[tracing::instrument(level = "trace", ret)]
380399
fn http_request(request_type: &str, endpoint: &str, body: Option<&str>) -> String {
381400
let req_no_body = format!(
382401
"{} {} HTTP/1.1\r\nContent-Type: application/json\r\n",

src/api_server/src/request/actions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct ActionBody {
2828
action_type: ActionType,
2929
}
3030

31+
#[tracing::instrument(level = "trace", ret)]
3132
pub(crate) fn parse_put_actions(body: &Body) -> Result<ParsedRequest, Error> {
3233
METRICS.put_api_requests.actions_count.inc();
3334
let action_body = serde_json::from_slice::<ActionBody>(body.raw()).map_err(|err| {

src/api_server/src/request/balloon.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::super::VmmAction;
1010
use crate::parsed_request::{Error, ParsedRequest};
1111
use crate::request::Body;
1212

13+
#[tracing::instrument(level = "trace", ret)]
1314
pub(crate) fn parse_get_balloon(path_second_token: Option<&str>) -> Result<ParsedRequest, Error> {
1415
match path_second_token {
1516
Some(stats_path) => match stats_path {
@@ -23,12 +24,14 @@ pub(crate) fn parse_get_balloon(path_second_token: Option<&str>) -> Result<Parse
2324
}
2425
}
2526

27+
#[tracing::instrument(level = "trace", ret)]
2628
pub(crate) fn parse_put_balloon(body: &Body) -> Result<ParsedRequest, Error> {
2729
Ok(ParsedRequest::new_sync(VmmAction::SetBalloonDevice(
2830
serde_json::from_slice::<BalloonDeviceConfig>(body.raw())?,
2931
)))
3032
}
3133

34+
#[tracing::instrument(level = "trace", ret)]
3235
pub(crate) fn parse_patch_balloon(
3336
body: &Body,
3437
path_second_token: Option<&str>,

src/api_server/src/request/boot_source.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::super::VmmAction;
88
use crate::parsed_request::{Error, ParsedRequest};
99
use crate::request::Body;
1010

11+
#[tracing::instrument(level = "trace", ret)]
1112
pub(crate) fn parse_put_boot_source(body: &Body) -> Result<ParsedRequest, Error> {
1213
METRICS.put_api_requests.boot_source_count.inc();
1314
Ok(ParsedRequest::new_sync(VmmAction::ConfigureBootSource(

src/api_server/src/request/cpu_configuration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::super::VmmAction;
88
use crate::parsed_request::{Error, ParsedRequest};
99
use crate::request::Body;
1010

11+
#[tracing::instrument(level = "trace", ret)]
1112
pub(crate) fn parse_put_cpu_config(body: &Body) -> Result<ParsedRequest, Error> {
1213
METRICS.put_api_requests.cpu_cfg_count.inc();
1314

src/api_server/src/request/drive.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::super::VmmAction;
88
use crate::parsed_request::{checked_id, Error, ParsedRequest};
99
use crate::request::{Body, StatusCode};
1010

11+
#[tracing::instrument(level = "trace", ret)]
1112
pub(crate) fn parse_put_drive(
1213
body: &Body,
1314
id_from_path: Option<&str>,
@@ -38,6 +39,7 @@ pub(crate) fn parse_put_drive(
3839
}
3940
}
4041

42+
#[tracing::instrument(level = "trace", ret)]
4143
pub(crate) fn parse_patch_drive(
4244
body: &Body,
4345
id_from_path: Option<&str>,

src/api_server/src/request/entropy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use vmm::vmm_config::entropy::EntropyDeviceConfig;
77
use crate::parsed_request::{Error, ParsedRequest};
88
use crate::request::Body;
99

10+
#[tracing::instrument(level = "trace", ret)]
1011
pub(crate) fn parse_put_entropy(body: &Body) -> Result<ParsedRequest, Error> {
1112
let cfg = serde_json::from_slice::<EntropyDeviceConfig>(body.raw())?;
1213
Ok(ParsedRequest::new_sync(VmmAction::SetEntropyDevice(cfg)))

src/api_server/src/request/instance_info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use vmm::rpc_interface::VmmAction;
66

77
use crate::parsed_request::{Error, ParsedRequest};
88

9+
#[tracing::instrument(level = "trace", ret)]
910
pub(crate) fn parse_get_instance_info() -> Result<ParsedRequest, Error> {
1011
METRICS.get_api_requests.instance_info_count.inc();
1112
Ok(ParsedRequest::new_sync(VmmAction::GetVmInstanceInfo))

src/api_server/src/request/logger.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::super::VmmAction;
88
use crate::parsed_request::{Error, ParsedRequest};
99
use crate::request::Body;
1010

11+
#[tracing::instrument(level = "trace", ret)]
1112
pub(crate) fn parse_put_logger(body: &Body) -> Result<ParsedRequest, Error> {
1213
METRICS.put_api_requests.logger_count.inc();
1314
let res = serde_json::from_slice::<LoggerConfig>(body.raw());

0 commit comments

Comments
 (0)