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:
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/containerd/containerd/api/services/tasks/v1"
|
||||
"github.com/containerd/containerd/v2/pkg/cio"
|
||||
"github.com/containerd/containerd/v2/pkg/protobuf"
|
||||
"github.com/containerd/containerd/v2/pkg/tracing"
|
||||
"github.com/containerd/errdefs"
|
||||
)
|
||||
|
||||
@@ -118,6 +119,11 @@ func (p *process) Pid() uint32 {
|
||||
|
||||
// Start starts the exec process
|
||||
func (p *process) Start(ctx context.Context) error {
|
||||
ctx, span := tracing.StartSpan(ctx, "process.Start",
|
||||
tracing.WithAttribute("process.id", p.ID()),
|
||||
tracing.WithAttribute("process.task.id", p.task.ID()),
|
||||
)
|
||||
defer span.End()
|
||||
r, err := p.task.client.TaskService().Start(ctx, &tasks.StartRequest{
|
||||
ContainerID: p.task.id,
|
||||
ExecID: p.id,
|
||||
@@ -130,11 +136,18 @@ func (p *process) Start(ctx context.Context) error {
|
||||
}
|
||||
return errdefs.FromGRPC(err)
|
||||
}
|
||||
span.SetAttributes(tracing.Attribute("process.pid", int(r.Pid)))
|
||||
p.pid = r.Pid
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *process) Kill(ctx context.Context, s syscall.Signal, opts ...KillOpts) error {
|
||||
ctx, span := tracing.StartSpan(ctx, "process.Kill",
|
||||
tracing.WithAttribute("process.id", p.ID()),
|
||||
tracing.WithAttribute("process.pid", int(p.Pid())),
|
||||
tracing.WithAttribute("process.task.id", p.task.ID()),
|
||||
)
|
||||
defer span.End()
|
||||
var i KillInfo
|
||||
for _, o := range opts {
|
||||
if err := o(ctx, &i); err != nil {
|
||||
@@ -154,6 +167,11 @@ func (p *process) Wait(ctx context.Context) (<-chan ExitStatus, error) {
|
||||
c := make(chan ExitStatus, 1)
|
||||
go func() {
|
||||
defer close(c)
|
||||
ctx, span := tracing.StartSpan(ctx, "process.Wait",
|
||||
tracing.WithAttribute("process.id", p.ID()),
|
||||
tracing.WithAttribute("process.task.id", p.task.ID()),
|
||||
)
|
||||
defer span.End()
|
||||
r, err := p.task.client.TaskService().Wait(ctx, &tasks.WaitRequest{
|
||||
ContainerID: p.task.id,
|
||||
ExecID: p.id,
|
||||
@@ -174,6 +192,10 @@ func (p *process) Wait(ctx context.Context) (<-chan ExitStatus, error) {
|
||||
}
|
||||
|
||||
func (p *process) CloseIO(ctx context.Context, opts ...IOCloserOpts) error {
|
||||
ctx, span := tracing.StartSpan(ctx, "process.CloseIO",
|
||||
tracing.WithAttribute("process.id", p.ID()),
|
||||
)
|
||||
defer span.End()
|
||||
r := &tasks.CloseIORequest{
|
||||
ContainerID: p.task.id,
|
||||
ExecID: p.id,
|
||||
@@ -192,6 +214,10 @@ func (p *process) IO() cio.IO {
|
||||
}
|
||||
|
||||
func (p *process) Resize(ctx context.Context, w, h uint32) error {
|
||||
ctx, span := tracing.StartSpan(ctx, "process.Resize",
|
||||
tracing.WithAttribute("process.id", p.ID()),
|
||||
)
|
||||
defer span.End()
|
||||
_, err := p.task.client.TaskService().ResizePty(ctx, &tasks.ResizePtyRequest{
|
||||
ContainerID: p.task.id,
|
||||
Width: w,
|
||||
@@ -202,6 +228,10 @@ func (p *process) Resize(ctx context.Context, w, h uint32) error {
|
||||
}
|
||||
|
||||
func (p *process) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitStatus, error) {
|
||||
ctx, span := tracing.StartSpan(ctx, "process.Delete",
|
||||
tracing.WithAttribute("process.id", p.ID()),
|
||||
)
|
||||
defer span.End()
|
||||
for _, o := range opts {
|
||||
if err := o(ctx, p); err != nil {
|
||||
return nil, err
|
||||
@@ -238,8 +268,11 @@ func (p *process) Status(ctx context.Context) (Status, error) {
|
||||
if err != nil {
|
||||
return Status{}, errdefs.FromGRPC(err)
|
||||
}
|
||||
status := ProcessStatus(strings.ToLower(r.Process.Status.String()))
|
||||
exitStatus := r.Process.ExitStatus
|
||||
|
||||
return Status{
|
||||
Status: ProcessStatus(strings.ToLower(r.Process.Status.String())),
|
||||
ExitStatus: r.Process.ExitStatus,
|
||||
Status: status,
|
||||
ExitStatus: exitStatus,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user