-
Notifications
You must be signed in to change notification settings - Fork 43
Conversation
Change the way the logger is constructed to allow for future improvements by making the logger concrete logrus.Entry rather than a FieldLogger interface type. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
@@ -625,7 +625,7 @@ func (c *Container) kill(signal syscall.Signal, all bool) error { | |||
} | |||
|
|||
if c.state.State != StateReady && c.state.State != StateRunning { | |||
return fmt.Errorf("Container not ready or running, impossible to signal the container") | |||
return Errorf("Container not ready or running, impossible to signal the container") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very good and returning better error messages will definitely help for faster debug. One question though, why is that only applied to this specific error ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I missed that it was only an example...
@jodh-intel PR looks good, and I agree this should be in a new subpackage of virtcontainers. This way, this could be reused accross repos. |
Create a new `Errorf()` function that returns an `error` object as `fmt.Errorf()` does but which also includes additional metadata: - the structured logging fields of the logger. - details of the call site of the error. Fixes containers#656. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
Make a call to the new internal error creation function. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
7aec6e9
to
e1cd97b
Compare
Hi @sboeuf - regarding the separate package, what about Kata? If we agree to adopt "enriched errors", we'd want them used everywhere so wouldn't it be simpler to create a completely separate package (https://github.com/kata-containers/errors or https://github.com/kata-containers/utils or something) that all components could vendor to avoid vendoring (a sub-package of) virtcontainers? |
Well given the fact that virtcontainers might very likely move under kata-containers/runtime, there is no need to move this to its own repo. |
A summary of current thinking... The errors package@markdryan pointed me at https://github.com/pkg/errors. This looks interesting, but although it improves the quality of the errors by adding a stack trace...
I'm after a solution that doesn't change the error interface and which generates "structured" errors. Original API IdeaI have an almost complete implementation whose API is:
This works in most scenarios but gets tripped up due to the flexible nature of
The ways to resolve this issue (atleast the ones I came up with) aren't particularly palatable:
A simpler API ideaI had a further think and came up with the following:
With this, we could then do magic like:
The advantages of this approach:
An example of that API:
which generates an error something like:
... or re-formatted with the log-parser:
|
Any thoughts on the above @sameo, @sboeuf, @grahamwhaley? |
Most of that sounds sane to me, I think.
mostly unrelated - query - is the
and if so, what does it mean, and why do they not also appear in the error time? |
Yes, Ignore those timestamps - you get the weird prefix when running |
@jodh-intel I am all for simplicity ! And your |
@jodh-intel Need to be closed and moved to https://github.com/kata-containers/runtime/virtcontainers |
Context
All components of both Clear Containers and Kata Containers now produce structured logs. This is extremely useful as the log fields provide a lot of context on key stages in the runtime flows.
Current virtcontainers error example
However, errors currently suffer as they are wholly "free-format".
For example, here's an example of a structured log message logged by
cc-runtime
:Or formatted with the log-parser on kata-containers/tests#98 for easier reading:
Notes:
msg
is the value passed tofmt.Errorf()
.source=runtime
is actually wrong - this error was generated by virtcontainers, but it was the runtime that caught the error and logged it (but how would a reader know this?)Error based on this PR
This PR is just an idea for how we could improve our error handling. It adds a new implementation of
Errorf()
so that rather than the above, with this PR you'd get the following:... and here's the log-parser reformatted version of that line:
Notes:
time
) and the other showing the time the error was generated (error-time
).source
now correctly showsvirtcontainers
.Caveats
This PR is just an example. To be generally useful, we'd need this
Errorf()
function (and an equivalent toerrors.New()
) to be available to all components of Clear Containers and Kata Containers. That implies we'd need a new package for this functionality in a separate repo that we'd "vendor in" to all the components.The other issue is how we handle the logger itself. Ideally, we'd find a way to register the logger with the new package and then have
Errorf()
use that logger object. But worst case, we'd need to change all thefmt.Errorf()
anderrors.New()
calls to pass in the logger as an extra arg./cc @sameo, @sboeuf, @grahamwhaley.