mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-22 12:29:49 +00:00
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>
94 lines
2.1 KiB
Go
94 lines
2.1 KiB
Go
// Copyright (c) 2014,2015,2016 Docker, Inc.
|
|
// Copyright (c) 2017 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
opentracing "github.com/opentracing/opentracing-go"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var noteText = `Use "` + name + ` list" to identify container statuses.`
|
|
|
|
var pauseCLICommand = cli.Command{
|
|
Name: "pause",
|
|
Usage: "suspend all processes in a container",
|
|
ArgsUsage: `<container-id>
|
|
|
|
Where "<container-id>" is the container name to be paused.`,
|
|
Description: `The pause command suspends all processes in a container.
|
|
|
|
` + noteText,
|
|
Action: pause,
|
|
}
|
|
|
|
var resumeCLICommand = cli.Command{
|
|
Name: "resume",
|
|
Usage: "unpause all previously paused processes in a container",
|
|
ArgsUsage: `<container-id>
|
|
|
|
Where "<container-id>" is the container name to be resumed.`,
|
|
Description: `The resume command unpauses all processes in a container.
|
|
|
|
` + noteText,
|
|
Action: resume,
|
|
}
|
|
|
|
func pause(c *cli.Context) error {
|
|
return toggle(c, true)
|
|
}
|
|
|
|
func resume(c *cli.Context) error {
|
|
return toggle(c, false)
|
|
}
|
|
|
|
func toggle(c *cli.Context, pause bool) error {
|
|
ctx, err := cliContextToContext(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return toggleContainerPause(ctx, c.Args().First(), pause)
|
|
}
|
|
|
|
func toggleContainerPause(ctx context.Context, containerID string, pause bool) (err error) {
|
|
span, _ := opentracing.StartSpanFromContext(ctx, "pause")
|
|
defer span.Finish()
|
|
span.SetTag("pause", pause)
|
|
|
|
kataLog = kataLog.WithField("container", containerID)
|
|
setExternalLoggers(kataLog)
|
|
span.SetTag("container", containerID)
|
|
|
|
// Checks the MUST and MUST NOT from OCI runtime specification
|
|
status, sandboxID, err := getExistingContainerInfo(containerID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
containerID = status.ID
|
|
|
|
kataLog = kataLog.WithFields(logrus.Fields{
|
|
"container": containerID,
|
|
"sandbox": sandboxID,
|
|
})
|
|
|
|
setExternalLoggers(kataLog)
|
|
span.SetTag("container", containerID)
|
|
span.SetTag("sandbox", sandboxID)
|
|
|
|
if pause {
|
|
err = vci.PauseContainer(sandboxID, containerID)
|
|
} else {
|
|
err = vci.ResumeContainer(sandboxID, containerID)
|
|
}
|
|
|
|
return err
|
|
}
|