From a44b27291cf49d5a81abf5a3be27f73a089713c4 Mon Sep 17 00:00:00 2001 From: Chelsea Mafrica Date: Wed, 17 Feb 2021 18:02:36 -0800 Subject: [PATCH] runtime: Create tracer later in shimv2 Remove loading of configuration from New() because we do not know the correct configuration file for the runtime until Create() and so that it is not loaded more than once. Start tracer in create() so that it is created after the runtime config is loaded in its original location. Fixes #1411 Signed-off-by: Chelsea Mafrica --- src/runtime/containerd-shim-v2/create.go | 17 ++++++++++++++- src/runtime/containerd-shim-v2/service.go | 26 ----------------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/runtime/containerd-shim-v2/create.go b/src/runtime/containerd-shim-v2/create.go index 87fddcba7f..556e9e1b76 100644 --- a/src/runtime/containerd-shim-v2/create.go +++ b/src/runtime/containerd-shim-v2/create.go @@ -19,6 +19,7 @@ import ( "github.com/containerd/typeurl" "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" + otelTrace "go.opentelemetry.io/otel/trace" // only register the proto type _ "github.com/containerd/containerd/runtime/linux/runctypes" @@ -59,11 +60,21 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest) (*con return nil, fmt.Errorf("cannot create another sandbox in sandbox: %s", s.sandbox.ID()) } - _, err := loadRuntimeConfig(s, r, ociSpec.Annotations) + s.config, err = loadRuntimeConfig(s, r, ociSpec.Annotations) + + // create tracer + // This is the earliest location we can create the tracer because we must wait + // until the runtime config is loaded + _, err = katautils.CreateTracer("kata", s.config) if err != nil { return nil, err } + // create span + var span otelTrace.Span + span, s.ctx = trace(s.ctx, "create") + defer span.End() + if rootFs.Mounted, err = checkAndMount(s, r); err != nil { return nil, err } @@ -90,6 +101,10 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest) (*con go s.startManagementServer(ctx, ociSpec) case vc.PodContainer: + var span otelTrace.Span + span, s.ctx = trace(s.ctx, "create") + defer span.End() + if s.sandbox == nil { return nil, fmt.Errorf("BUG: Cannot start the container, since the sandbox hasn't been created") } diff --git a/src/runtime/containerd-shim-v2/service.go b/src/runtime/containerd-shim-v2/service.go index e7fc236b89..ae2aa2e907 100644 --- a/src/runtime/containerd-shim-v2/service.go +++ b/src/runtime/containerd-shim-v2/service.go @@ -81,21 +81,6 @@ func New(ctx context.Context, id string, publisher events.Publisher) (cdshim.Shi vci.SetLogger(ctx, shimLog) katautils.SetLogger(ctx, shimLog, shimLog.Logger.Level) - // load runtime config so that tracing can start if enabled - _, runtimeConfig, err := katautils.LoadConfiguration("", false, true) - if err != nil { - return nil, err - } - - // create tracer - _, err = katautils.CreateTracer("kata", &runtimeConfig) - if err != nil { - return nil, err - } - // create span - span, ctx := trace(ctx, "New") - defer span.End() - ctx, cancel := context.WithCancel(ctx) s := &service{ @@ -103,7 +88,6 @@ func New(ctx context.Context, id string, publisher events.Publisher) (cdshim.Shi pid: uint32(os.Getpid()), ctx: ctx, containers: make(map[string]*container), - config: &runtimeConfig, events: make(chan interface{}, chSize), ec: make(chan exit, bufferSize), cancel: cancel, @@ -186,13 +170,6 @@ func newCommand(ctx context.Context, containerdBinary, id, containerdAddress str // StartShim willl start a kata shimv2 daemon which will implemented the // ShimV2 APIs such as create/start/update etc containers. func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress string) (string, error) { - // Stop tracing here since a new tracer will be created the next time New() - // is called again after StartShim() - defer katautils.StopTracing(s.ctx) - - span, _ := trace(s.ctx, "StartShim") - defer span.End() - bundlePath, err := os.Getwd() if err != nil { return "", err @@ -375,9 +352,6 @@ func (s *service) Cleanup(ctx context.Context) (_ *taskAPI.DeleteResponse, err e // Create a new sandbox or container with the underlying OCI runtime func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *taskAPI.CreateTaskResponse, err error) { - span, _ := trace(s.ctx, "Create") - defer span.End() - start := time.Now() defer func() { err = toGRPC(err)