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 <chelsea.e.mafrica@intel.com>
This commit is contained in:
Chelsea Mafrica 2021-02-17 18:02:36 -08:00
parent 0a9cc357c6
commit a44b27291c
2 changed files with 16 additions and 27 deletions

View File

@ -19,6 +19,7 @@ import (
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
otelTrace "go.opentelemetry.io/otel/trace"
// only register the proto type // only register the proto type
_ "github.com/containerd/containerd/runtime/linux/runctypes" _ "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()) 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 { if err != nil {
return nil, err 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 { if rootFs.Mounted, err = checkAndMount(s, r); err != nil {
return nil, err return nil, err
} }
@ -90,6 +101,10 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest) (*con
go s.startManagementServer(ctx, ociSpec) go s.startManagementServer(ctx, ociSpec)
case vc.PodContainer: case vc.PodContainer:
var span otelTrace.Span
span, s.ctx = trace(s.ctx, "create")
defer span.End()
if s.sandbox == nil { if s.sandbox == nil {
return nil, fmt.Errorf("BUG: Cannot start the container, since the sandbox hasn't been created") return nil, fmt.Errorf("BUG: Cannot start the container, since the sandbox hasn't been created")
} }

View File

@ -81,21 +81,6 @@ func New(ctx context.Context, id string, publisher events.Publisher) (cdshim.Shi
vci.SetLogger(ctx, shimLog) vci.SetLogger(ctx, shimLog)
katautils.SetLogger(ctx, shimLog, shimLog.Logger.Level) 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) ctx, cancel := context.WithCancel(ctx)
s := &service{ s := &service{
@ -103,7 +88,6 @@ func New(ctx context.Context, id string, publisher events.Publisher) (cdshim.Shi
pid: uint32(os.Getpid()), pid: uint32(os.Getpid()),
ctx: ctx, ctx: ctx,
containers: make(map[string]*container), containers: make(map[string]*container),
config: &runtimeConfig,
events: make(chan interface{}, chSize), events: make(chan interface{}, chSize),
ec: make(chan exit, bufferSize), ec: make(chan exit, bufferSize),
cancel: cancel, 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 // StartShim willl start a kata shimv2 daemon which will implemented the
// ShimV2 APIs such as create/start/update etc containers. // ShimV2 APIs such as create/start/update etc containers.
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress string) (string, error) { 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() bundlePath, err := os.Getwd()
if err != nil { if err != nil {
return "", err 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 // 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) { 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() start := time.Now()
defer func() { defer func() {
err = toGRPC(err) err = toGRPC(err)