Skip to content

Commit

Permalink
OpenTracing support added to start, stop, run, create, pull, and ps
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Jug <sejug@redhat.com>
  • Loading branch information
sjug committed Oct 23, 2018
1 parent d43fc85 commit ca8eb75
Show file tree
Hide file tree
Showing 146 changed files with 19,609 additions and 33 deletions.
11 changes: 6 additions & 5 deletions cmd/podman/build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/containers/buildah"
"github.com/containers/buildah/imagebuildah"
buildahcli "github.com/containers/buildah/pkg/cli"
Expand All @@ -10,10 +15,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

var (
Expand Down Expand Up @@ -241,5 +242,5 @@ func buildCmd(c *cli.Context) error {
options.Isolation = buildah.IsolationOCIRootless
}

return runtime.Build(getContext(), options, dockerfiles...)
return runtime.Build(getContext(c), options, dockerfiles...)
}
2 changes: 1 addition & 1 deletion cmd/podman/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func cleanupCmd(c *cli.Context) error {

args := c.Args()

ctx := getContext()
ctx := getContext(c)

var lastError error
var cleanupContainers []*libpod.Container
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func commitCmd(c *cli.Context) error {
Changes: c.StringSlice("change"),
Author: c.String("author"),
}
newImage, err := ctr.Commit(getContext(), reference, options)
newImage, err := ctr.Commit(getContext(c), reference, options)
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/podman/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ func validateFlags(c *cli.Context, flags []cli.Flag) error {
}

// getContext returns a non-nil, empty context
func getContext() context.Context {
func getContext(c *cli.Context) context.Context {
if c != nil && c.GlobalBool("trace") {
return c.Ctx
}
return context.TODO()
}

Expand Down
17 changes: 16 additions & 1 deletion cmd/podman/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/docker/go-units"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/selinux/go-selinux/label"
opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand Down Expand Up @@ -58,6 +59,11 @@ var createCommand = cli.Command{
}

func createCmd(c *cli.Context) error {
if c.GlobalBool("trace") {
span, _ := opentracing.StartSpanFromContext(c.Ctx, "createCmd")
defer span.Finish()
}

if err := createInit(c); err != nil {
return err
}
Expand All @@ -84,6 +90,10 @@ func createCmd(c *cli.Context) error {
func createInit(c *cli.Context) error {
// TODO should allow user to create based off a directory on the host not just image
// Need CLI support for this
if c.GlobalBool("trace") {
span, _ := opentracing.StartSpanFromContext(c.Ctx, "createInit")
defer span.Finish()
}

// Docker-compatibility: the "-h" flag for run/create is reserved for
// the hostname (see https://github.com/containers/libpod/issues/1367).
Expand Down Expand Up @@ -112,8 +122,13 @@ func createInit(c *cli.Context) error {
}

func createContainer(c *cli.Context, runtime *libpod.Runtime) (*libpod.Container, *cc.CreateConfig, error) {
if c.GlobalBool("trace") {
span, _ := opentracing.StartSpanFromContext(c.Ctx, "createContainer")
defer span.Finish()
}

rtc := runtime.GetConfig()
ctx := getContext()
ctx := getContext(c)
rootfs := ""
if c.Bool("rootfs") {
rootfs = c.Args()[0]
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func historyCmd(c *cli.Context) error {
format: format,
}

history, err := image.History(getContext())
history, err := image.History(getContext(c))
if err != nil {
return errors.Wrapf(err, "error getting history of image %q", image.InputName)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func imagesCmd(c *cli.Context) error {
return errors.New("'podman images' requires at most 1 argument")
}

ctx := getContext()
ctx := getContext(c)

if len(c.StringSlice("filter")) > 0 || newImage != nil {
filterFuncs, err = CreateFilterFuncs(ctx, runtime, c, newImage)
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func importCmd(c *cli.Context) error {
source = file
}

newImage, err := runtime.ImageRuntime().Import(getContext(), source, reference, writer, image.SigningOptions{}, config)
newImage, err := runtime.ImageRuntime().Import(getContext(c), source, reference, writer, image.SigningOptions{}, config)
if err == nil {
fmt.Println(newImage.ID())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func inspectCmd(c *cli.Context) error {
inspectType = inspectTypeContainer
}

inspectedObjects, iterateErr := iterateInput(getContext(), c, args, runtime, inspectType)
inspectedObjects, iterateErr := iterateInput(getContext(c), c, args, runtime, inspectType)

var out formats.Writer
if outputFormat != "" && outputFormat != formats.JSONString {
Expand Down
16 changes: 16 additions & 0 deletions cmd/podman/libpodruntime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import (
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/util"
"github.com/containers/storage"
opentracing "github.com/opentracing/opentracing-go"
"github.com/urfave/cli"
)

// GetRuntime generates a new libpod runtime configured by command line options
func GetRuntime(c *cli.Context) (*libpod.Runtime, error) {
if c.GlobalBool("trace") {
span, _ := opentracing.StartSpanFromContext(c.Ctx, "getRuntime")
defer span.Finish()
}

storageOpts, err := util.GetDefaultStoreOptions()
if err != nil {
return nil, err
Expand All @@ -19,6 +25,11 @@ func GetRuntime(c *cli.Context) (*libpod.Runtime, error) {

// GetContainerRuntime generates a new libpod runtime configured by command line options for containers
func GetContainerRuntime(c *cli.Context) (*libpod.Runtime, error) {
if c.GlobalBool("trace") {
span, _ := opentracing.StartSpanFromContext(c.Ctx, "getContainerRuntime")
defer span.Finish()
}

mappings, err := util.ParseIDMapping(c.StringSlice("uidmap"), c.StringSlice("gidmap"), c.String("subuidmap"), c.String("subgidmap"))
if err != nil {
return nil, err
Expand All @@ -34,6 +45,11 @@ func GetContainerRuntime(c *cli.Context) (*libpod.Runtime, error) {

// GetRuntime generates a new libpod runtime configured by command line options
func GetRuntimeWithStorageOpts(c *cli.Context, storageOpts *storage.StoreOptions) (*libpod.Runtime, error) {
if c.GlobalBool("trace") {
span, _ := opentracing.StartSpanFromContext(c.Ctx, "GetRuntimeWithStorageOpts")
defer span.Finish()
}

options := []libpod.RuntimeOption{}

if c.GlobalIsSet("root") {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func loadCmd(c *cli.Context) error {
writer = os.Stderr
}

ctx := getContext()
ctx := getContext(c)

var newImages []*image.Image
src, err := dockerarchive.ParseReference(input) // FIXME? We should add dockerarchive.NewReference()
Expand Down
31 changes: 28 additions & 3 deletions cmd/podman/main.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package main

import (
"context"
"fmt"
"io"
"os"
"os/exec"
"runtime/pprof"
"syscall"

"log/syslog"

"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/hooks"
_ "github.com/containers/libpod/pkg/hooks/0.1.0"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/tracing"
"github.com/containers/libpod/version"
"github.com/containers/storage/pkg/reexec"
opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
lsyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/urfave/cli"
"log/syslog"
)

// This is populated by the Makefile from the VERSION file
Expand Down Expand Up @@ -46,8 +51,9 @@ var cmdsNotRequiringRootless = map[string]bool{
}

func main() {
debug := false
cpuProfile := false
var debug, cpuProfile, trace bool
var span opentracing.Span
var closer io.Closer

if reexec.Init() {
return
Expand Down Expand Up @@ -133,6 +139,16 @@ func main() {
logrus.AddHook(hook)
}
}
if c.GlobalBool("trace") {
trace = true
var tracer opentracing.Tracer
tracer, closer = tracing.Init("podman")
opentracing.SetGlobalTracer(tracer)

span = tracer.StartSpan("before-context")

c.Ctx = opentracing.ContextWithSpan(context.Background(), span)
}
logLevel := c.GlobalString("log-level")
if logLevel != "" {
level, err := logrus.ParseLevel(logLevel)
Expand Down Expand Up @@ -176,6 +192,10 @@ func main() {
if cpuProfile {
pprof.StopCPUProfile()
}
if trace {
span.Finish()
closer.Close()
}
return nil
}
app.Flags = []cli.Flag{
Expand Down Expand Up @@ -249,6 +269,11 @@ func main() {
Name: "syslog",
Usage: "output logging information to syslog as well as the console",
},
cli.BoolFlag{
Name: "trace",
Usage: "enable opentracing output",
Hidden: true,
},
}
if _, err := os.Stat("/etc/containers/registries.conf"); err != nil {
if os.IsNotExist(err) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pod_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func podCreateCmd(c *cli.Context) error {
// User Opt out is not yet supported
options = append(options, libpod.WithPodCgroups())

ctx := getContext()
ctx := getContext(c)
pod, err := runtime.NewPod(ctx, options...)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pod_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func podRestartCmd(c *cli.Context) error {
// in which case the following loop will be skipped.
pods, lastError := getPodsFromContext(c, runtime)

ctx := getContext()
ctx := getContext(c)
for _, pod := range pods {
ctr_errs, err := pod.Restart(ctx)
if ctr_errs != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pod_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func podRmCmd(c *cli.Context) error {
}
defer runtime.Shutdown(false)

ctx := getContext()
ctx := getContext(c)
force := c.Bool("force")

// getPodsFromContext returns an error when a requested pod
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pod_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func podStartCmd(c *cli.Context) error {
// in which case the following loop will be skipped.
pods, lastError := getPodsFromContext(c, runtime)

ctx := getContext()
ctx := getContext(c)
for _, pod := range pods {
ctr_errs, err := pod.Start(ctx)
if ctr_errs != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pod_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func podStopCmd(c *cli.Context) error {
// in which case the following loop will be skipped.
pods, lastError := getPodsFromContext(c, runtime)

ctx := getContext()
ctx := getContext(c)

for _, pod := range pods {
// set cleanup to true to clean mounts and namespaces
Expand Down
6 changes: 6 additions & 0 deletions cmd/podman/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/containers/libpod/pkg/util"
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/docker/go-units"
opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand Down Expand Up @@ -201,6 +202,11 @@ var (
)

func psCmd(c *cli.Context) error {
if c.GlobalBool("trace") {
span, _ := opentracing.StartSpanFromContext(c.Ctx, "psCmd")
defer span.Finish()
}

if err := validateFlags(c, psFlags); err != nil {
return err
}
Expand Down
10 changes: 8 additions & 2 deletions cmd/podman/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/containers/libpod/cmd/podman/libpodruntime"
image2 "github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/util"
opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand Down Expand Up @@ -64,6 +65,11 @@ specified, the image with the 'latest' tag (if it exists) is pulled
// pullCmd gets the data from the command line and calls pullImage
// to copy an image from a registry to a local machine
func pullCmd(c *cli.Context) error {
if c.GlobalBool("trace") {
span, _ := opentracing.StartSpanFromContext(c.Ctx, "pullCmd")
defer span.Finish()
}

forceSecure := false
runtime, err := libpodruntime.GetRuntime(c)
if err != nil {
Expand Down Expand Up @@ -118,14 +124,14 @@ func pullCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "error parsing %q", image)
}
newImage, err := runtime.ImageRuntime().LoadFromArchiveReference(getContext(), srcRef, c.String("signature-policy"), writer)
newImage, err := runtime.ImageRuntime().LoadFromArchiveReference(getContext(c), srcRef, c.String("signature-policy"), writer)
if err != nil {
return errors.Wrapf(err, "error pulling image from %q", image)
}
imgID = newImage[0].ID()
} else {
authfile := getAuthFile(c.String("authfile"))
newImage, err := runtime.ImageRuntime().New(getContext(), image, c.String("signature-policy"), authfile, writer, &dockerRegistryOptions, image2.SigningOptions{}, true, forceSecure)
newImage, err := runtime.ImageRuntime().New(getContext(c), image, c.String("signature-policy"), authfile, writer, &dockerRegistryOptions, image2.SigningOptions{}, true, forceSecure)
if err != nil {
return errors.Wrapf(err, "error pulling image %q", image)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,5 @@ func pushCmd(c *cli.Context) error {

authfile := getAuthFile(c.String("authfile"))

return newImage.PushImageToHeuristicDestination(getContext(), destName, manifestType, authfile, c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions, forceSecure, nil)
return newImage.PushImageToHeuristicDestination(getContext(c), destName, manifestType, authfile, c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions, forceSecure, nil)
}
2 changes: 1 addition & 1 deletion cmd/podman/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func refreshCmd(c *cli.Context) error {
return err
}

ctx := getContext()
ctx := getContext(c)

var lastError error
for _, ctr := range allCtrs {
Expand Down
Loading

0 comments on commit ca8eb75

Please sign in to comment.