Skip to content

Conversation

@lindig
Copy link
Contributor

@lindig lindig commented Mar 5, 2018

This logs all errors flowing across the interface to squeezed.

Signed-off-by: Christian Lindig [email protected]

@lindig lindig requested review from edwintorok and jonludlam March 5, 2018 14:51
@edwintorok
Copy link
Contributor

The Travis failure is unrelated to this PR, something gone wrong with all the preprocessors we have: #206 (comment)

Copy link
Contributor

@edwintorok edwintorok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start, might need to log some more details on the location and arguments.

{ def = errors
; raiser = (fun e ->
let exn = MemoryError e in
error "%s (%s)" (Printexc.to_string exn) __LOC__;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miight want to add D.log_backtrace () too.

raise exn)
; matcher = (function
| MemoryError e as exn ->
error "%s (%s)" (Printexc.to_string exn) __LOC__;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to register a pretty printer for this to work:

#require "xcp.memory";;
let e = Memory_interface.MemoryError (Memory_interface.Cannot_free_this_much_memory (42L, 42L));;
val e : exn =
  Memory_interface.MemoryError
   (Memory_interface.Cannot_free_this_much_memory (42L, 42L))
Printexc.to_string e;;
- : string = "Memory_interface.MemoryError(_)"

let string_of_error e = Rpcmarshal.marshal Memory_interface.errors.Rpc.Types.ty e |> Rpc.to_string;;
val string_of_error : Memory_interface.errors -> string = <fun>

 let register_memory_error () =
   Printexc.register_printer (function
    | Memory_interface.MemoryError e -> Some (Printf.sprintf "Memory_interface.Memory_error(%s)" (string_of_error e)) | _ -> None);;
val register_memory_error : unit -> unit = <fun>
register_memory_error ();;
- : unit = ()

Printexc.to_string e;;
- : string =
"Memory_interface.Memory_error([S(Cannot_free_this_much_memory);[I(42);I(42)]])"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(very bare bones pretty printer, maybe using Jsonrpc.to_string would make it look nicer?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I always assumed that Printexc.to_string e would be able to inspect any exception.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't see why the compiler couldn't autogenerate these pretty printers, it seems it only has trouble when the argument of the exception is an exception with a variant (otherwise it is able to at least print the constructor as a number)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could autogenerate these in ppx_deriving_rpc though?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fairly annoying. We can investigate what to do, it may be worth opening an issue on ocaml-rpc (and maybe also in Jira)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please do the same also for the other ported modules, I think v6, networkd and maybe rrd.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to port this change to the Error functor in ocaml-rpc

@lindig
Copy link
Contributor Author

lindig commented Mar 6, 2018

I have added logging for the other interfaces as well.

Copy link
Collaborator

@mseri mseri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. There is a fixup commit that needs squashing

lindig added 4 commits March 6, 2018 10:45
This logs all errors flowing across the interface to squeezed.  It adds
code to install a custom printer for MemoryError exceptions such that we
actually will get meaningful log messages.

Signed-off-by: Christian Lindig <[email protected]>
This adds logging for all errors passing the network interface.

Signed-off-by: Christian Lindig <[email protected]>
All errors passed through the V6 interface are now logged.

Signed-off-by: Christian Lindig <[email protected]>
This adds logging for all errors passing through the Gpumon_interface.

Signed-off-by: Christian Lindig <[email protected]>
@mseri mseri merged commit 10a1175 into xapi-project:master Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants