Skip to content

Commit

Permalink
CP-48195: Instrument forkhelpers with tracing
Browse files Browse the repository at this point in the history
Instrument `forkhelpers.ml` with tracing.

Signed-off-by: Gabriel Buica <[email protected]>
  • Loading branch information
GabrielBuica committed Apr 9, 2024
1 parent 5713b5f commit 97f0194
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions ocaml/forkexecd/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
xapi-log
xapi-stdext-pervasives
xapi-stdext-unix
xapi-tracing
)
(preprocess
(pps ppx_deriving_rpc)))
17 changes: 12 additions & 5 deletions ocaml/forkexecd/lib/forkhelpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ let test_path =

let runtime_path = Option.value ~default:"/var" test_path

let with_tracing ?traceparent ~name f =
let name = "forkhelpers" ^ "." ^ name in
Tracing.with_tracing ?parent:traceparent ~name f

let finally = Xapi_stdext_pervasives.Pervasiveext.finally

type pidty = Unix.file_descr * int
Expand Down Expand Up @@ -300,8 +304,9 @@ let safe_close_and_exec ?env stdin stdout stderr
)
close_fds

let execute_command_get_output_inner ?env ?stdin ?(syslog_stdout = NoSyslogging)
?(redirect_stderr_to_stdout = false) ?(timeout = -1.0) cmd args =
let execute_command_get_output_inner ?traceparent ?env ?stdin
?(syslog_stdout = NoSyslogging) ?(redirect_stderr_to_stdout = false)
?(timeout = -1.0) cmd args =
let to_close = ref [] in
let close fd =
if List.mem fd !to_close then (
Expand Down Expand Up @@ -357,10 +362,12 @@ let execute_command_get_output_inner ?env ?stdin ?(syslog_stdout = NoSyslogging)
)
(fun () -> List.iter Unix.close !to_close)

let execute_command_get_output ?env ?(syslog_stdout = NoSyslogging)
let execute_command_get_output ?traceparent ?env ?(syslog_stdout = NoSyslogging)
?(redirect_stderr_to_stdout = false) ?timeout cmd args =
execute_command_get_output_inner ?env ?stdin:None ?timeout ~syslog_stdout
~redirect_stderr_to_stdout cmd args
with_tracing ~traceparent ~name:"execute_command_get_output"
@@ fun traceparent ->
execute_command_get_output_inner ?traceparent ?env ?stdin:None ?timeout
~syslog_stdout ~redirect_stderr_to_stdout cmd args

let execute_command_get_output_send_stdin ?env ?(syslog_stdout = NoSyslogging)
?(redirect_stderr_to_stdout = false) ?timeout cmd args stdin =
Expand Down
3 changes: 2 additions & 1 deletion ocaml/forkexecd/lib/forkhelpers.mli
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ val default_path : string list
val default_path_env_pair : string array

val execute_command_get_output :
?env:string array
?traceparent:Tracing.Span.t
-> ?env:string array
-> ?syslog_stdout:syslog_stdout_t
-> ?redirect_stderr_to_stdout:bool
-> ?timeout:float
Expand Down
3 changes: 2 additions & 1 deletion ocaml/xapi/sm_exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ let exec_xmlrpc ~dbg ?context:_ ?(needs_session = true) (driver : string)
~component:Xapi_observer_components.SMApi ~traceparent
~exe ~args
in
Forkhelpers.execute_command_get_output ?env exe args
Forkhelpers.execute_command_get_output ?traceparent:di.tracing
?env exe args
in
try (Xml.parse_string output, stderr)
with e ->
Expand Down

0 comments on commit 97f0194

Please sign in to comment.