Add spans to CRI runtime service and related client methods

This adds otel spans to CRI service mainly targeting mutating apis which includes:
* Sandbox apis - RunPodSandbox, StopPodSandbox, RemovePodSandbox
* Container apis - CreateContainer, StartContainer, StopContainer, RemoveContainer
* Attach, Exec and Exec Sync
* Containerd client methods: container.go, client.go, process.go and task.go

Signed-off-by: Swagat Bora <sbora@amazon.com>
This commit is contained in:
Swagat Bora
2022-11-17 17:52:08 +00:00
parent 45d8917089
commit c0cdcb34f1
17 changed files with 287 additions and 13 deletions

View File

@@ -28,11 +28,16 @@ import (
"github.com/containerd/containerd/v2/pkg/filters"
"github.com/containerd/containerd/v2/pkg/identifiers"
"github.com/containerd/containerd/v2/pkg/namespaces"
"github.com/containerd/containerd/v2/pkg/tracing"
"github.com/containerd/errdefs"
"github.com/containerd/typeurl/v2"
"go.etcd.io/bbolt"
)
const (
spanSandboxPrefix = "metadata.sandbox"
)
type sandboxStore struct {
db *DB
}
@@ -46,6 +51,11 @@ func NewSandboxStore(db *DB) api.Store {
// Create a sandbox record in the store
func (s *sandboxStore) Create(ctx context.Context, sandbox api.Sandbox) (api.Sandbox, error) {
ctx, span := tracing.StartSpan(ctx,
tracing.Name(spanSandboxPrefix, "Create"),
tracing.WithAttribute("sandbox.id", sandbox.ID),
)
defer span.End()
ns, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return api.Sandbox{}, err
@@ -68,6 +78,9 @@ func (s *sandboxStore) Create(ctx context.Context, sandbox api.Sandbox) (api.San
return fmt.Errorf("write error: %w", err)
}
span.SetAttributes(
tracing.Attribute("sandbox.CreatedAt", sandbox.CreatedAt.Format(time.RFC3339)),
)
return nil
}); err != nil {
return api.Sandbox{}, err
@@ -78,6 +91,11 @@ func (s *sandboxStore) Create(ctx context.Context, sandbox api.Sandbox) (api.San
// Update the sandbox with the provided sandbox object and fields
func (s *sandboxStore) Update(ctx context.Context, sandbox api.Sandbox, fieldpaths ...string) (api.Sandbox, error) {
ctx, span := tracing.StartSpan(ctx,
tracing.Name(spanSandboxPrefix, "Update"),
tracing.WithAttribute("sandbox.id", sandbox.ID),
)
defer span.End()
ns, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return api.Sandbox{}, err
@@ -142,6 +160,10 @@ func (s *sandboxStore) Update(ctx context.Context, sandbox api.Sandbox, fieldpat
return err
}
span.SetAttributes(
tracing.Attribute("sandbox.CreatedAt", updated.CreatedAt.Format(time.RFC3339)),
tracing.Attribute("sandbox.UpdatedAt", updated.UpdatedAt.Format(time.RFC3339)),
)
ret = updated
return nil
}); err != nil {
@@ -227,6 +249,11 @@ func (s *sandboxStore) List(ctx context.Context, fields ...string) ([]api.Sandbo
// Delete a sandbox from metadata store using the id
func (s *sandboxStore) Delete(ctx context.Context, id string) error {
ctx, span := tracing.StartSpan(ctx,
tracing.Name(spanSandboxPrefix, "Delete"),
tracing.WithAttribute("sandbox.id", id),
)
defer span.End()
ns, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return err