Merge pull request #2695 from hinshun/exec-telemetry
Add events for exec op for container start / exitmaster
commit
e58afa464c
|
@ -11,6 +11,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/moby/buildkit/util/bklog"
|
"github.com/moby/buildkit/util/bklog"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cio"
|
"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() {
|
err = w.runProcess(ctx, task, process.Resize, process.Signal, func() {
|
||||||
startedOnce.Do(func() {
|
startedOnce.Do(func() {
|
||||||
|
trace.SpanFromContext(ctx).AddEvent("Container started")
|
||||||
if started != nil {
|
if started != nil {
|
||||||
close(started)
|
close(started)
|
||||||
}
|
}
|
||||||
|
@ -396,6 +400,12 @@ func (w *containerdExecutor) runProcess(ctx context.Context, p containerd.Proces
|
||||||
if cancel != nil {
|
if cancel != nil {
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
trace.SpanFromContext(ctx).AddEvent(
|
||||||
|
"Container exited",
|
||||||
|
trace.WithAttributes(
|
||||||
|
attribute.Int("exit.code", int(status.ExitCode())),
|
||||||
|
),
|
||||||
|
)
|
||||||
if status.ExitCode() != 0 {
|
if status.ExitCode() != 0 {
|
||||||
exitErr := &gatewayapi.ExitError{
|
exitErr := &gatewayapi.ExitError{
|
||||||
ExitCode: status.ExitCode(),
|
ExitCode: status.ExitCode(),
|
||||||
|
|
|
@ -12,6 +12,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/moby/buildkit/util/bklog"
|
"github.com/moby/buildkit/util/bklog"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
containerdoci "github.com/containerd/containerd/oci"
|
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)
|
bklog.G(ctx).Debugf("> creating %s %v", id, meta.Args)
|
||||||
|
|
||||||
|
trace.SpanFromContext(ctx).AddEvent("Container created")
|
||||||
err = w.run(runCtx, id, bundle, process, func() {
|
err = w.run(runCtx, id, bundle, process, func() {
|
||||||
startedOnce.Do(func() {
|
startedOnce.Do(func() {
|
||||||
|
trace.SpanFromContext(ctx).AddEvent("Container started")
|
||||||
if started != nil {
|
if started != nil {
|
||||||
close(started)
|
close(started)
|
||||||
}
|
}
|
||||||
|
@ -339,6 +343,12 @@ func exitError(ctx context.Context, err error) error {
|
||||||
ExitCode: uint32(runcExitError.Status),
|
ExitCode: uint32(runcExitError.Status),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
trace.SpanFromContext(ctx).AddEvent(
|
||||||
|
"Container exited",
|
||||||
|
trace.WithAttributes(
|
||||||
|
attribute.Int("exit.code", int(exitErr.ExitCode)),
|
||||||
|
),
|
||||||
|
)
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
exitErr.Err = errors.Wrapf(ctx.Err(), exitErr.Error())
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
digest "github.com/opencontainers/go-digest"
|
digest "github.com/opencontainers/go-digest"
|
||||||
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
"golang.org/x/sync/semaphore"
|
"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) {
|
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))
|
refs := make([]*worker.WorkerRef, len(inputs))
|
||||||
for i, inp := range inputs {
|
for i, inp := range inputs {
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
Loading…
Reference in New Issue