Skip to content

Commit

Permalink
cli: delete tracing code for kata-runtime binary
Browse files Browse the repository at this point in the history
There are no pod/container operations in kata-runtime binary,
tracing in this package is meaningless.

Fixes: #1748

Signed-off-by: bin <bin@hyper.sh>
(cherry picked from commit 13c23fe)
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
  • Loading branch information
liubin authored and fidencio committed May 10, 2021
1 parent 68cad37 commit 3f1b7c9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 143 deletions.
13 changes: 2 additions & 11 deletions src/runtime/cli/kata-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,6 @@ EXAMPLES:
if verbose {
kataLog.Logger.SetLevel(logrus.InfoLevel)
}
ctx, err := cliContextToContext(context)
if err != nil {
return err
}

span, _ := katautils.Trace(ctx, "check")
defer span.End()

if !context.Bool("no-network-checks") && os.Getenv(noNetworkEnvVar) == "" {
cmd := RelCmdCheck
Expand All @@ -407,8 +400,7 @@ EXAMPLES:
if os.Geteuid() == 0 {
kataLog.Warn("Not running network checks as super user")
} else {

err = HandleReleaseVersions(cmd, version, context.Bool("include-all-releases"))
err := HandleReleaseVersions(cmd, version, context.Bool("include-all-releases"))
if err != nil {
return err
}
Expand All @@ -424,7 +416,7 @@ EXAMPLES:
return errors.New("check: cannot determine runtime config")
}

err = setCPUtype(runtimeConfig.HypervisorType)
err := setCPUtype(runtimeConfig.HypervisorType)
if err != nil {
return err
}
Expand All @@ -437,7 +429,6 @@ EXAMPLES:
}

err = hostIsVMContainerCapable(details)

if err != nil {
return err
}
Expand Down
9 changes: 0 additions & 9 deletions src/runtime/cli/kata-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"strings"

"github.com/BurntSushi/toml"
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
"github.com/kata-containers/kata-containers/src/runtime/pkg/utils"
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
exp "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/experimental"
Expand Down Expand Up @@ -448,14 +447,6 @@ var kataEnvCLICommand = cli.Command{
},
},
Action: func(context *cli.Context) error {
ctx, err := cliContextToContext(context)
if err != nil {
return err
}

span, _ := katautils.Trace(ctx, "kata-env")
defer span.End()

return handleSettings(defaultOutputFile, context)
},
}
12 changes: 0 additions & 12 deletions src/runtime/cli/kata-exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
clientUtils "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/client"
"github.com/pkg/errors"
"github.com/urfave/cli"
"go.opentelemetry.io/otel/label"
)

const (
Expand Down Expand Up @@ -67,33 +66,22 @@ var kataExecCLICommand = cli.Command{
},
},
Action: func(context *cli.Context) error {
ctx, err := cliContextToContext(context)
if err != nil {
return err
}
span, _ := katautils.Trace(ctx, subCommandName)
defer span.End()

namespace := context.String(paramRuntimeNamespace)
if namespace == "" {
namespace = defaultRuntimeNamespace
}
span.SetAttributes(label.Key("namespace").String(namespace))

port := context.Uint64(paramDebugConsolePort)
if port == 0 {
port = defaultKernelParamDebugConsoleVPortValue
}
span.SetAttributes(label.Key("port").Uint64(port))

sandboxID := context.Args().Get(0)

if err := katautils.VerifyContainerID(sandboxID); err != nil {
return err
}

span.SetAttributes(label.Key("sandbox").String(sandboxID))

conn, err := getConn(namespace, sandboxID, port)
if err != nil {
return err
Expand Down
108 changes: 6 additions & 102 deletions src/runtime/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label"
otelTrace "go.opentelemetry.io/otel/trace"
)

// specConfig is the name of the file holding the containers configuration
Expand Down Expand Up @@ -132,10 +129,6 @@ var runtimeCommands = []cli.Command{
// parsing occurs.
var runtimeBeforeSubcommands = beforeSubcommands

// runtimeAfterSubcommands is the function to run after the command-line
// has been parsed.
var runtimeAfterSubcommands = afterSubcommands

// runtimeCommandNotFound is the function to handle an invalid sub-command.
var runtimeCommandNotFound = commandNotFound

Expand Down Expand Up @@ -168,10 +161,6 @@ func init() {

// setupSignalHandler sets up signal handling, starting a go routine to deal
// with signals as they arrive.
//
// Note that the specified context is NOT used to create a trace span (since the
// first (root) span must be created in beforeSubcommands()): it is simply
// used to pass to the crash handling functions to finalise tracing.
func setupSignalHandler(ctx context.Context) {
signals.SetLogger(kataLog)

Expand All @@ -181,10 +170,6 @@ func setupSignalHandler(ctx context.Context) {
signal.Notify(sigCh, sig)
}

dieCb := func() {
katautils.StopTracing(ctx)
}

go func() {
for {
sig := <-sigCh
Expand All @@ -198,7 +183,6 @@ func setupSignalHandler(ctx context.Context) {

if signals.FatalSignal(nativeSignal) {
kataLog.WithField("signal", sig).Error("received fatal signal")
signals.Die(dieCb)
} else if debug && signals.NonFatalSignal(nativeSignal) {
kataLog.WithField("signal", sig).Debug("handling signal")
signals.Backtrace()
Expand All @@ -210,18 +194,6 @@ func setupSignalHandler(ctx context.Context) {
// setExternalLoggers registers the specified logger with the external
// packages which accept a logger to handle their own logging.
func setExternalLoggers(ctx context.Context, logger *logrus.Entry) {
var span otelTrace.Span

// Only create a new span if a root span already exists. This is
// required to ensure that this function will not disrupt the root
// span logic by creating a span before the proper root span has been
// created.

if otelTrace.SpanFromContext(ctx) != nil {
span, ctx = katautils.Trace(ctx, "setExternalLoggers")
defer span.End()
}

// Set virtcontainers logger.
vci.SetLogger(ctx, logger)

Expand All @@ -244,7 +216,6 @@ func beforeSubcommands(c *cli.Context) error {
var configFile string
var runtimeConfig oci.RuntimeConfig
var err error
var traceFlushFunc func()

katautils.SetConfigOptions(name, defaultRuntimeConfiguration, defaultSysConfRuntimeConfiguration)

Expand All @@ -270,7 +241,6 @@ func beforeSubcommands(c *cli.Context) error {
// Issue: https://github.com/kata-containers/runtime/issues/2428

ignoreConfigLogs := false
var traceRootSpan string

subCmdIsCheckCmd := (c.NArg() >= 1 && ((c.Args()[0] == "kata-check") || (c.Args()[0] == "check")))
if subCmdIsCheckCmd {
Expand Down Expand Up @@ -302,16 +272,13 @@ func beforeSubcommands(c *cli.Context) error {
cmdName := c.Args().First()
if c.App.Command(cmdName) != nil {
kataLog = kataLog.WithField("command", cmdName)

// Name for the root span (used for tracing) now the
// sub-command name is known.
traceRootSpan = name + " " + cmdName
}

// Since a context is required, pass a new (throw-away) one - we
// cannot use the main context as tracing hasn't been enabled yet
// (meaning any spans created at this point will be silently ignored).
setExternalLoggers(context.Background(), kataLog)
ctx, err := cliContextToContext(c)
if err != nil {
return err
}
setExternalLoggers(ctx, kataLog)

if c.NArg() == 1 && (c.Args()[0] == "kata-env" || c.Args()[0] == "env") {
// simply report the logging setup
Expand All @@ -325,20 +292,6 @@ func beforeSubcommands(c *cli.Context) error {
}
if !subCmdIsCheckCmd {
debug = runtimeConfig.Debug

if traceRootSpan != "" {
// Create the tracer.
//
// Note: no spans are created until the command-line has been parsed.
// This delays collection of trace data slightly but benefits the user by
// ensuring the first span is the name of the sub-command being
// invoked from the command-line.
traceFlushFunc, err = setupTracing(c, traceRootSpan, &runtimeConfig)
if err != nil {
return err
}
defer traceFlushFunc()
}
}

args := strings.Join(c.Args(), " ")
Expand Down Expand Up @@ -377,36 +330,6 @@ func handleShowConfig(context *cli.Context) {
}
}

func setupTracing(context *cli.Context, rootSpanName string, config *oci.RuntimeConfig) (func(), error) {
flush, err := katautils.CreateTracer(name, config)
if err != nil {
return nil, err
}

ctx, err := cliContextToContext(context)
if err != nil {
return nil, err
}

// Create the root span now that the sub-command name is
// known.
//
// Note that this "Before" function is called (and returns)
// before the subcommand handler is called. As such, we cannot
// "Finish()" the span here - that is handled in the .After
// function.
tracer := otel.Tracer("kata")
newCtx, span := tracer.Start(ctx, rootSpanName)

span.SetAttributes(label.Key("subsystem").String("runtime"))

// Add tracer to metadata and update the context
context.App.Metadata["tracer"] = tracer
context.App.Metadata["context"] = newCtx

return flush, nil
}

// add supported experimental features in context
func addExpFeatures(clictx *cli.Context, runtimeConfig oci.RuntimeConfig) error {
ctx, err := cliContextToContext(clictx)
Expand All @@ -420,22 +343,11 @@ func addExpFeatures(clictx *cli.Context, runtimeConfig oci.RuntimeConfig) error
}

ctx = exp.ContextWithExp(ctx, exps)
// Add tracer to metadata and update the context
// Add experimental features to metadata and update the context
clictx.App.Metadata["context"] = ctx
return nil
}

func afterSubcommands(c *cli.Context) error {
ctx, err := cliContextToContext(c)
if err != nil {
return err
}

katautils.StopTracing(ctx)

return nil
}

// function called when an invalid command is specified which causes the
// runtime to error.
func commandNotFound(c *cli.Context, command string) {
Expand Down Expand Up @@ -502,7 +414,6 @@ func createRuntimeApp(ctx context.Context, args []string) error {
app.Flags = runtimeFlags
app.Commands = runtimeCommands
app.Before = runtimeBeforeSubcommands
app.After = runtimeAfterSubcommands
app.EnableBashCompletion = true

// allow sub-commands to access context
Expand Down Expand Up @@ -578,12 +489,5 @@ func cliContextToContext(c *cli.Context) (context.Context, error) {
func main() {
// create a new empty context
ctx := context.Background()

dieCb := func() {
katautils.StopTracing(ctx)
}

defer signals.HandlePanic(dieCb)

createRuntime(ctx)
}
9 changes: 0 additions & 9 deletions src/runtime/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@
package main

import (
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
"github.com/urfave/cli"
)

var versionCLICommand = cli.Command{
Name: "version",
Usage: "display version details",
Action: func(context *cli.Context) error {
ctx, err := cliContextToContext(context)
if err != nil {
return err
}

span, _ := katautils.Trace(ctx, "version")
defer span.End()

cli.VersionPrinter(context)
return nil
},
Expand Down

0 comments on commit 3f1b7c9

Please sign in to comment.