mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-22 12:29:49 +00:00
tracing: Add initial opentracing support
Add initial support for opentracing by using the `jaeger` package. Since opentracing uses the `context` package, add a `context.Context` as the first parameter to all the functions that we might want to trace. Trace "spans" (trace points) are then added by extracting the trace details from the specified context parameter. Notes: - Although the tracer is created in `main()`, the "root span" (aka the first trace point) is not added until `beforeSubcommands()`. This is by design and is a compromise: by delaying the creation of the root span, the spans become much more readable since using the web-based JaegerUI, you will see traces like this: ``` kata-runtime: kata-runtime create ------------ ------------------- ^ ^ | | Trace name First span name (which clearly shows the CLI command that was run) ``` Creating the span earlier means it is necessary to expand 'n' spans in the UI before you get to see the name of the CLI command that was run. In adding support, this became very tedious, hence my design decision to defer the creation of the root span until after signal handling has been setup and after CLI options have been parsed, but still very early in the code path. - At this stage, the tracing stops at the `virtcontainers` call boundary. - Tracing is "always on" as there doesn't appear to be a way to toggle it. However, its resolves to a "nop" unless the tracer can talk to a jaeger agent. Note that this commit required a bit of rework to `beforeSubcommands()` to reduce the cyclomatic complexity. Fixes #557. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
@@ -7,6 +7,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
@@ -26,6 +27,7 @@ import (
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
jaeger "github.com/uber/jaeger-client-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -474,6 +476,10 @@ func createCLIContextWithApp(flagSet *flag.FlagSet, app *cli.App) *cli.Context {
|
||||
ctx.App.Metadata = map[string]interface{}{}
|
||||
}
|
||||
|
||||
// add standard entries
|
||||
ctx.App.Metadata["context"] = context.Background()
|
||||
ctx.App.Metadata["tracer"] = &jaeger.Tracer{}
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
@@ -918,7 +924,7 @@ func TestMainCreateRuntimeApp(t *testing.T) {
|
||||
|
||||
args := []string{name}
|
||||
|
||||
err = createRuntimeApp(args)
|
||||
err = createRuntimeApp(context.Background(), args)
|
||||
assert.NoError(err, "%v", args)
|
||||
}
|
||||
|
||||
@@ -941,7 +947,7 @@ func TestMainCreateRuntimeAppInvalidSubCommand(t *testing.T) {
|
||||
}()
|
||||
|
||||
// calls fatal() so no return
|
||||
_ = createRuntimeApp([]string{name, "i-am-an-invalid-sub-command"})
|
||||
_ = createRuntimeApp(context.Background(), []string{name, "i-am-an-invalid-sub-command"})
|
||||
|
||||
assert.NotEqual(exitStatus, 0)
|
||||
}
|
||||
@@ -985,7 +991,7 @@ func TestMainCreateRuntime(t *testing.T) {
|
||||
}()
|
||||
|
||||
assert.Equal(exitStatus, 0)
|
||||
createRuntime()
|
||||
createRuntime(context.Background())
|
||||
assert.NotEqual(exitStatus, 0)
|
||||
}
|
||||
|
||||
@@ -1012,7 +1018,7 @@ func TestMainVersionPrinter(t *testing.T) {
|
||||
|
||||
setCLIGlobals()
|
||||
|
||||
err = createRuntimeApp([]string{name, "--version"})
|
||||
err = createRuntimeApp(context.Background(), []string{name, "--version"})
|
||||
assert.NoError(err)
|
||||
|
||||
err = grep(fmt.Sprintf(`%s\s*:\s*%s`, name, version), output)
|
||||
@@ -1060,7 +1066,7 @@ func TestMainFatalWriter(t *testing.T) {
|
||||
|
||||
setCLIGlobals()
|
||||
|
||||
err := createRuntimeApp([]string{name, cmd})
|
||||
err := createRuntimeApp(context.Background(), []string{name, cmd})
|
||||
assert.Error(err)
|
||||
|
||||
re := regexp.MustCompile(
|
||||
|
Reference in New Issue
Block a user