mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-02 02:02:24 +00:00
tracing: Create trace function
Simplify code slightly be creating a `trace()` function. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
a193366b3d
commit
f0073bec2f
@ -18,7 +18,6 @@ import (
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
vf "github.com/kata-containers/runtime/virtcontainers/factory"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -96,7 +95,7 @@ func create(ctx context.Context, containerID, bundlePath, console, pidFilePath s
|
||||
runtimeConfig oci.RuntimeConfig) error {
|
||||
var err error
|
||||
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "create")
|
||||
span, ctx := trace(ctx, "create")
|
||||
defer span.Finish()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
@ -254,7 +253,7 @@ func setKernelParams(containerID string, runtimeConfig *oci.RuntimeConfig) error
|
||||
|
||||
func createSandbox(ctx context.Context, ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig,
|
||||
containerID, bundlePath, console string, disableOutput bool) (vc.Process, error) {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "createSandbox")
|
||||
span, ctx := trace(ctx, "createSandbox")
|
||||
defer span.Finish()
|
||||
|
||||
err := setKernelParams(containerID, &runtimeConfig)
|
||||
@ -306,7 +305,7 @@ func setEphemeralStorageType(ociSpec oci.CompatOCISpec) oci.CompatOCISpec {
|
||||
func createContainer(ctx context.Context, ociSpec oci.CompatOCISpec, containerID, bundlePath,
|
||||
console string, disableOutput bool) (vc.Process, error) {
|
||||
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "createContainer")
|
||||
span, ctx := trace(ctx, "createContainer")
|
||||
defer span.Finish()
|
||||
|
||||
ociSpec = setEphemeralStorageType(ociSpec)
|
||||
@ -338,7 +337,7 @@ func createContainer(ctx context.Context, ociSpec oci.CompatOCISpec, containerID
|
||||
}
|
||||
|
||||
func createCgroupsFiles(ctx context.Context, containerID string, cgroupsDirPath string, cgroupsPathList []string, pid int) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "createCgroupsFiles")
|
||||
span, _ := trace(ctx, "createCgroupsFiles")
|
||||
defer span.Finish()
|
||||
|
||||
if len(cgroupsPathList) == 0 {
|
||||
@ -384,7 +383,7 @@ func createCgroupsFiles(ctx context.Context, containerID string, cgroupsDirPath
|
||||
}
|
||||
|
||||
func createPIDFile(ctx context.Context, pidFilePath string, pid int) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "createPIDFile")
|
||||
span, _ := trace(ctx, "createPIDFile")
|
||||
defer span.Finish()
|
||||
|
||||
if pidFilePath == "" {
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -60,7 +59,7 @@ EXAMPLE:
|
||||
}
|
||||
|
||||
func delete(ctx context.Context, containerID string, force bool) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "delete")
|
||||
span, ctx := trace(ctx, "delete")
|
||||
defer span.Finish()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
@ -134,7 +133,7 @@ func delete(ctx context.Context, containerID string, force bool) error {
|
||||
}
|
||||
|
||||
func deleteSandbox(ctx context.Context, sandboxID string) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "deleteSandbox")
|
||||
span, _ := trace(ctx, "deleteSandbox")
|
||||
defer span.Finish()
|
||||
|
||||
status, err := vci.StatusSandbox(sandboxID)
|
||||
@ -156,7 +155,7 @@ func deleteSandbox(ctx context.Context, sandboxID string) error {
|
||||
}
|
||||
|
||||
func deleteContainer(ctx context.Context, sandboxID, containerID string, forceStop bool) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "deleteContainer")
|
||||
span, _ := trace(ctx, "deleteContainer")
|
||||
defer span.Finish()
|
||||
|
||||
if forceStop {
|
||||
@ -173,7 +172,7 @@ func deleteContainer(ctx context.Context, sandboxID, containerID string, forceSt
|
||||
}
|
||||
|
||||
func removeCgroupsPath(ctx context.Context, containerID string, cgroupsPathList []string) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "removeCgroupsPath")
|
||||
span, _ := trace(ctx, "removeCgroupsPath")
|
||||
defer span.Finish()
|
||||
|
||||
if len(cgroupsPathList) == 0 {
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"time"
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
@ -142,7 +141,7 @@ information is displayed once every 5 seconds.`,
|
||||
return err
|
||||
}
|
||||
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "events")
|
||||
span, _ := trace(ctx, "events")
|
||||
defer span.Finish()
|
||||
|
||||
containerID := context.Args().First()
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -189,7 +188,7 @@ func generateExecParams(context *cli.Context, specProcess *oci.CompatOCIProcess)
|
||||
}
|
||||
|
||||
func execute(ctx context.Context, context *cli.Context) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "execute")
|
||||
span, ctx := trace(ctx, "execute")
|
||||
defer span.Finish()
|
||||
|
||||
containerID := context.Args().First()
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"syscall"
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -288,7 +287,7 @@ var kataCheckCLICommand = cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "kata-check")
|
||||
span, _ := trace(ctx, "kata-check")
|
||||
defer span.Finish()
|
||||
|
||||
setCPUtype()
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
vcUtils "github.com/kata-containers/runtime/virtcontainers/utils"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -411,7 +410,7 @@ var kataEnvCLICommand = cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "kata-env")
|
||||
span, _ := trace(ctx, "kata-env")
|
||||
defer span.Finish()
|
||||
|
||||
return handleSettings(defaultOutputFile, context)
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -98,7 +97,7 @@ var signals = map[string]syscall.Signal{
|
||||
}
|
||||
|
||||
func kill(ctx context.Context, containerID, signal string, all bool) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "kill")
|
||||
span, _ := trace(ctx, "kill")
|
||||
defer span.Finish()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/urfave/cli"
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
@ -114,7 +113,7 @@ To list containers created using a non-default value for "--root":
|
||||
return err
|
||||
}
|
||||
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "list")
|
||||
span, _ := trace(ctx, "list")
|
||||
defer span.Finish()
|
||||
|
||||
s, err := getContainers(context)
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
"github.com/opencontainers/runc/libcontainer/utils"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -128,7 +127,7 @@ func validCreateParams(containerID, bundlePath string) (string, error) {
|
||||
// OCI runtime specification. It returns a list of complete paths
|
||||
// that should be created and used for every specified resource.
|
||||
func processCgroupsPath(ctx context.Context, ociSpec oci.CompatOCISpec, isSandbox bool) ([]string, error) {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "processCgroupsPath")
|
||||
span, _ := trace(ctx, "processCgroupsPath")
|
||||
defer span.Finish()
|
||||
|
||||
var cgroupsPathList []string
|
||||
@ -377,7 +376,7 @@ func fetchContainerIDMapping(containerID string) (string, error) {
|
||||
}
|
||||
|
||||
func addContainerIDMapping(ctx context.Context, containerID, sandboxID string) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "addContainerIDMapping")
|
||||
span, _ := trace(ctx, "addContainerIDMapping")
|
||||
defer span.Finish()
|
||||
|
||||
if containerID == "" {
|
||||
@ -404,7 +403,7 @@ func addContainerIDMapping(ctx context.Context, containerID, sandboxID string) e
|
||||
}
|
||||
|
||||
func delContainerIDMapping(ctx context.Context, containerID string) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "delContainerIDMapping")
|
||||
span, _ := trace(ctx, "delContainerIDMapping")
|
||||
defer span.Finish()
|
||||
|
||||
if containerID == "" {
|
||||
|
@ -9,7 +9,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -58,7 +57,7 @@ func toggle(c *cli.Context, pause bool) error {
|
||||
}
|
||||
|
||||
func toggleContainerPause(ctx context.Context, containerID string, pause bool) (err error) {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "pause")
|
||||
span, _ := trace(ctx, "pause")
|
||||
defer span.Finish()
|
||||
span.SetTag("pause", pause)
|
||||
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -51,7 +50,7 @@ var psCLICommand = cli.Command{
|
||||
}
|
||||
|
||||
func ps(ctx context.Context, containerID, format string, args []string) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "ps")
|
||||
span, _ := trace(ctx, "ps")
|
||||
defer span.Finish()
|
||||
|
||||
if containerID == "" {
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -82,7 +81,7 @@ var runCLICommand = cli.Command{
|
||||
|
||||
func run(ctx context.Context, containerID, bundle, console, consoleSocket, pidFile string, detach bool,
|
||||
runtimeConfig oci.RuntimeConfig) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "run")
|
||||
span, ctx := trace(ctx, "run")
|
||||
defer span.Finish()
|
||||
|
||||
consolePath, err := setupConsole(console, consoleSocket)
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/specconv"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -78,7 +77,7 @@ generate a proper rootless spec file.`,
|
||||
return err
|
||||
}
|
||||
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "spec")
|
||||
span, _ := trace(ctx, "spec")
|
||||
defer span.Finish()
|
||||
|
||||
spec := specconv.Example()
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -48,7 +47,7 @@ var startCLICommand = cli.Command{
|
||||
}
|
||||
|
||||
func start(ctx context.Context, containerID string) (vc.VCSandbox, error) {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "start")
|
||||
span, _ := trace(ctx, "start")
|
||||
defer span.Finish()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -41,7 +40,7 @@ instance of a container.`,
|
||||
}
|
||||
|
||||
func state(ctx context.Context, containerID string) error {
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "state")
|
||||
span, _ := trace(ctx, "state")
|
||||
defer span.Finish()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
|
@ -76,3 +76,14 @@ func stopTracing(ctx context.Context) {
|
||||
// report all possible spans to the collector
|
||||
tracerCloser.Close()
|
||||
}
|
||||
|
||||
// trace creates a new tracing span based on the specified name and parent
|
||||
// context.
|
||||
func trace(parent context.Context, name string) (opentracing.Span, context.Context) {
|
||||
span, ctx := opentracing.StartSpanFromContext(parent, name)
|
||||
|
||||
span.SetTag("source", "runtime")
|
||||
span.SetTag("component", "cli")
|
||||
|
||||
return span, ctx
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"github.com/docker/go-units"
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -133,7 +132,7 @@ other options are ignored.
|
||||
return err
|
||||
}
|
||||
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "update")
|
||||
span, _ := trace(ctx, "update")
|
||||
defer span.Finish()
|
||||
|
||||
if context.Args().Present() == false {
|
||||
|
@ -6,7 +6,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -19,7 +18,7 @@ var versionCLICommand = cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
span, _ := opentracing.StartSpanFromContext(ctx, "version")
|
||||
span, _ := trace(ctx, "version")
|
||||
defer span.Finish()
|
||||
|
||||
cli.VersionPrinter(context)
|
||||
|
Loading…
Reference in New Issue
Block a user