mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 04:04:45 +00:00
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:
parent
0a9cc357c6
commit
a44b27291c
@ -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")
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user