Skip to content

Commit 743565c

Browse files
authored
Don't pollute the logs with some errors (#6518)
It's an in-house joke that most of `xapi`'s errors are "expected" (either because they're handled by the caller after being logged or because they are frequent and benign) and knowing which ones are unusual and actually critical takes a lot of learning. Try to remove at least some of the most obvious ones from the toolstack startup/VM resume, either removing the logs completely or downgrading it to `debug` when appropriate. Manually tested in the appropriate scenarios.
2 parents e67f151 + 3f0e977 commit 743565c

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

ocaml/libs/xapi-stdext/lib/xapi-stdext-unix/unixext.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ exception Unix_error of int
1717

1818
let _exit = Unix._exit
1919

20+
let raise_with_preserved_backtrace exn f =
21+
let bt = Printexc.get_raw_backtrace () in
22+
f () ;
23+
Printexc.raise_with_backtrace exn bt
24+
2025
(** remove a file, but doesn't raise an exception if the file is already removed *)
2126
let unlink_safe file =
2227
try Unix.unlink file with (* Unix.Unix_error (Unix.ENOENT, _ , _)*) _ -> ()

ocaml/libs/xapi-stdext/lib/xapi-stdext-unix/unixext.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
val _exit : int -> unit
1717

18+
val raise_with_preserved_backtrace : exn -> (unit -> unit) -> 'b
19+
(** A wrapper that preserves the backtrace (otherwise erased by calling
20+
formatting functions, for example) *)
21+
1822
val unlink_safe : string -> unit
1923

2024
val mkdir_safe : string -> Unix.file_perm -> unit

ocaml/networkd/lib/network_utils.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ module Sysfs = struct
162162
with
163163
| End_of_file ->
164164
""
165-
| Unix.Unix_error (Unix.EINVAL, _, _) ->
165+
| Unix.Unix_error (Unix.EINVAL, _, _) | Unix.Unix_error (Unix.ENOENT, _, _)
166+
->
166167
(* The device is not yet up *)
167168
raise (Network_error (Read_error file))
168169
| exn ->

ocaml/xapi/xapi_vgpu_type.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,9 @@ module Nvidia_compat = struct
10331033
read_configs ac tl
10341034
)
10351035
in
1036-
let conf_files = Array.to_list (Sys.readdir conf_dir) in
1036+
let conf_files =
1037+
try Array.to_list (Sys.readdir conf_dir) with Sys_error _ -> []
1038+
in
10371039
debug "Reading NVIDIA vGPU config files %s/{%s}" conf_dir
10381040
(String.concat ", " conf_files) ;
10391041
read_configs []

ocaml/xenopsd/xc/xenguestHelper.ml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,14 @@ let rec non_debug_receive ?(debug_callback = fun s -> debug "%s" s) cnx =
200200
201201
(* Dump memory statistics on failure *)
202202
let non_debug_receive ?debug_callback cnx =
203-
let debug_memory () =
203+
let debug_memory log_type =
204204
Xenctrl.with_intf (fun xc ->
205205
let open Memory in
206206
let open Int64 in
207207
let open Xenctrl in
208208
let p = Xenctrl.physinfo xc in
209-
error "Memory F %Ld KiB S %Ld KiB T %Ld MiB"
209+
(match log_type with Syslog.Debug -> debug | _ -> error)
210+
"Memory F %Ld KiB S %Ld KiB T %Ld MiB"
210211
(p.free_pages |> of_nativeint |> kib_of_pages)
211212
(p.scrub_pages |> of_nativeint |> kib_of_pages)
212213
(p.total_pages |> of_nativeint |> mib_of_pages_free)
@@ -215,10 +216,18 @@ let non_debug_receive ?debug_callback cnx =
215216
try
216217
match non_debug_receive ?debug_callback cnx with
217218
| Error y as x ->
218-
error "Received: %s" y ; debug_memory () ; x
219+
error "Received: %s" y ; debug_memory Syslog.Err ; x
219220
| x ->
220221
x
221-
with e -> debug_memory () ; raise e
222+
with
223+
| End_of_file as e ->
224+
Unixext.raise_with_preserved_backtrace e (fun () ->
225+
debug_memory Syslog.Debug
226+
)
227+
| e ->
228+
Unixext.raise_with_preserved_backtrace e (fun () ->
229+
debug_memory Syslog.Err
230+
)
222231
223232
(** For the simple case where we just want the successful result, return it. If
224233
we get an error message (or suspend) then throw an exception. *)

0 commit comments

Comments
 (0)