containerd / nri

Node Resource Interface
Apache License 2.0
257 stars 65 forks source link

Enhance reporting of stdout and stderr from plugin invocation #4

Closed ddebroy closed 3 years ago

ddebroy commented 3 years ago

Capture the stdout and stderr buffers from plugin invocation and report them with the error messages in containerd when the unmarshalling of JSON fails. Also, stop reporting the plugin name twice, adjacent to each other (where possible).

Sample error messages with the changes in the PR:

  1. Overall execution error when the plugin binary could not be executed - stdout/stderr of plugin is irrelevant and therefore skipped:
    containerd: time="2020-12-20T04:33:05.811689116Z" level=error msg="RunPodSandbox for &PodSandboxMetadata{Name:ddebroy-busybox,Uid:30078379-5ae5-4e9c-bc2e-87230e52d13f,Namespace:dev-ddebroy,Attempt:0,} failed, error" error="nri invoke: plugin: testplugin: exec: \"testplugin\": executable file not found in $PATH"
  2. Plugin error from execution of the plugin (non zero exit code) that could not be unmarshalled - stdout and stderr dumped:
    containerd: time="2020-12-20T01:00:02.562795524Z" level=error msg="RunPodSandbox for &PodSandboxMetadata{Name:ddebroy-busybox,Uid:1fdfd08b-abda-4644-9cd3-14917ca31a1d,Namespace:dev-ddebroy,Attempt:0,} failed, error" error="nri invoke: plugin: testplugin: failed to unmarshal plugin error: unexpected end of JSON input: plugin exec details: plugin output: <empty> plugin error: \"time=\"2020-12-20T01:00:02Z\" level=fatal msg=testplugin error=\"plugin init error injection\"\n\" plugin exit code: 1"
  3. Plugin error reported by execution of the plugin that was successfully unmarshalled - stdout and stderr skipped (no changes):
    containerd: time="2020-12-20T23:14:42.285426113Z" level=error msg="RunPodSandbox for &PodSandboxMetadata{Name:ddebroy-busybox,Uid:536080ab-ca0a-476f-a381-b8b457267be1,Namespace:dev-ddebroy,Attempt:0,} failed, error" error="nri invoke: plugin: testplugin: testplugin: error injection test"
  4. Plugin result from execution of the plugin (exit code: 0) that could not be unmarshalled - stdout and stderr dumped:
    containerd: time="2020-12-20T23:33:42.722353484Z" level=error msg="RunPodSandbox for &PodSandboxMetadata{Name:ddebroy-busybox,Uid:39046aa9-8274-4561-810f-55a05ad45edd,Namespace:dev-ddebroy,Attempt:0,} failed, error" error="nri invoke: plugin: testplugin: failed to unmarshal plugin result: invalid character 'i' looking for beginning of value: plugin exec details: plugin output: \"injected invalid output\" plugin error: <empty>"

Signed-off-by: Deep Debroy ddebroy@apple.com