From d21254e7f74b49a84c3fbe1b13260cb23954cf92 Mon Sep 17 00:00:00 2001 From: Edgar Lee Date: Wed, 2 Mar 2022 12:05:35 -0800 Subject: [PATCH] Add events for exec op Signed-off-by: Edgar Lee --- executor/containerdexecutor/executor.go | 10 ++++++++++ executor/runcexecutor/executor.go | 14 ++++++++++++++ solver/llbsolver/ops/exec.go | 3 +++ 3 files changed, 27 insertions(+) diff --git a/executor/containerdexecutor/executor.go b/executor/containerdexecutor/executor.go index 7b45df78..43a05ccc 100644 --- a/executor/containerdexecutor/executor.go +++ b/executor/containerdexecutor/executor.go @@ -11,6 +11,8 @@ import ( "time" "github.com/moby/buildkit/util/bklog" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "github.com/containerd/containerd" "github.com/containerd/containerd/cio" @@ -207,8 +209,10 @@ func (w *containerdExecutor) Run(ctx context.Context, id string, root executor.M } }() + trace.SpanFromContext(ctx).AddEvent("Container created") err = w.runProcess(ctx, task, process.Resize, process.Signal, func() { startedOnce.Do(func() { + trace.SpanFromContext(ctx).AddEvent("Container started") if started != nil { close(started) } @@ -396,6 +400,12 @@ func (w *containerdExecutor) runProcess(ctx context.Context, p containerd.Proces if cancel != nil { cancel() } + trace.SpanFromContext(ctx).AddEvent( + "Container exited", + trace.WithAttributes( + attribute.Int("exit.code", int(status.ExitCode())), + ), + ) if status.ExitCode() != 0 { exitErr := &gatewayapi.ExitError{ ExitCode: status.ExitCode(), diff --git a/executor/runcexecutor/executor.go b/executor/runcexecutor/executor.go index e7f4b82d..702d5131 100644 --- a/executor/runcexecutor/executor.go +++ b/executor/runcexecutor/executor.go @@ -12,6 +12,8 @@ import ( "time" "github.com/moby/buildkit/util/bklog" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "github.com/containerd/containerd/mount" containerdoci "github.com/containerd/containerd/oci" @@ -316,8 +318,10 @@ func (w *runcExecutor) Run(ctx context.Context, id string, root executor.Mount, bklog.G(ctx).Debugf("> creating %s %v", id, meta.Args) + trace.SpanFromContext(ctx).AddEvent("Container created") err = w.run(runCtx, id, bundle, process, func() { startedOnce.Do(func() { + trace.SpanFromContext(ctx).AddEvent("Container started") if started != nil { close(started) } @@ -339,6 +343,12 @@ func exitError(ctx context.Context, err error) error { ExitCode: uint32(runcExitError.Status), } } + trace.SpanFromContext(ctx).AddEvent( + "Container exited", + trace.WithAttributes( + attribute.Int("exit.code", int(exitErr.ExitCode)), + ), + ) select { case <-ctx.Done(): exitErr.Err = errors.Wrapf(ctx.Err(), exitErr.Error()) @@ -348,6 +358,10 @@ func exitError(ctx context.Context, err error) error { } } + trace.SpanFromContext(ctx).AddEvent( + "Container exited", + trace.WithAttributes(attribute.Int("exit.code", 0)), + ) return nil } diff --git a/solver/llbsolver/ops/exec.go b/solver/llbsolver/ops/exec.go index d01a72c0..51df9ff3 100644 --- a/solver/llbsolver/ops/exec.go +++ b/solver/llbsolver/ops/exec.go @@ -27,6 +27,7 @@ import ( digest "github.com/opencontainers/go-digest" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" + "go.opentelemetry.io/otel/trace" "golang.org/x/sync/semaphore" ) @@ -234,6 +235,8 @@ func addDefaultEnvvar(env []string, k, v string) []string { } func (e *execOp) Exec(ctx context.Context, g session.Group, inputs []solver.Result) (results []solver.Result, err error) { + trace.SpanFromContext(ctx).AddEvent("ExecOp started") + refs := make([]*worker.WorkerRef, len(inputs)) for i, inp := range inputs { var ok bool