Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/snapshot/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import (

"github.com/containerd/accelerated-container-image/pkg/label"
"github.com/containerd/accelerated-container-image/pkg/snapshot/diskquota"
"github.com/containerd/accelerated-container-image/pkg/tracing"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"

mylog "github.com/containerd/accelerated-container-image/internal/log"
"github.com/containerd/accelerated-container-image/pkg/metrics"
Expand Down Expand Up @@ -448,7 +451,6 @@ func (o *snapshotter) isPrepareRootfs(info snapshots.Info) bool {
}

func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind, key string, parent string, opts ...snapshots.Opt) (_ []mount.Mount, retErr error) {

ctx, t, err := o.ms.TransactionContext(ctx, true)
if err != nil {
return nil, err
Expand Down Expand Up @@ -550,6 +552,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
if err != nil {
return nil, err
}
trace.SpanFromContext(ctx).AddEvent("identifyStorageType", trace.WithAttributes(attribute.Int("stype", int(stype))))

// Download blob
downloadBlob := info.Labels[label.DownloadRemoteBlob]
Expand Down Expand Up @@ -994,6 +997,12 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
}

func (o *snapshotter) commit(ctx context.Context, name, key string, opts ...snapshots.Opt) (string, snapshots.Info, error) {
ctx, span := tracing.GetDefaultTracer().Start(ctx, "snapshotter.commit", trace.WithAttributes(
attribute.String("snapshot_name", name),
attribute.String("key", key),
))
defer span.End()

id, _, _, err := storage.GetInfo(ctx, key)
if err != nil {
return "", snapshots.Info{}, err
Expand Down Expand Up @@ -1380,6 +1389,12 @@ func (o *snapshotter) getDiskQuotaSize(info *snapshots.Info) string {
}

func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string, opts []snapshots.Opt) (_ string, _ snapshots.Info, err error) {
ctx, span := tracing.GetDefaultTracer().Start(ctx, "snapshotter.createSnapshot", trace.WithAttributes(
attribute.String("kind", kind.String()),
attribute.String("parent", parent),
))
defer span.End()

var td, path string
defer func() {
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions pkg/snapshot/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"time"

sn "github.com/containerd/accelerated-container-image/pkg/types"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"

"github.com/containerd/accelerated-container-image/pkg/label"
"github.com/containerd/accelerated-container-image/pkg/utils"
Expand Down Expand Up @@ -503,9 +505,12 @@ func (o *snapshotter) constructOverlayBDSpec(ctx context.Context, key string, wr
return errors.Wrapf(err, "failed to identify storage of snapshot %s", key)
}

var carrier = propagation.MapCarrier{}
otel.GetTextMapPropagator().Inject(ctx, carrier)
configJSON := sn.OverlayBDBSConfig{
Lowers: []sn.OverlayBDBSConfigLower{},
ResultFile: o.overlaybdInitDebuglogPath(id),
Lowers: []sn.OverlayBDBSConfigLower{},
ResultFile: o.overlaybdInitDebuglogPath(id),
TraceContext: carrier,
}

// load the parent's config and reuse the lowerdir
Expand Down
41 changes: 8 additions & 33 deletions pkg/tracing/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ import (

snapshotsapi "github.com/containerd/containerd/api/services/snapshots/v1"
ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

const tracerName = "accelerated-container-image/snapshotter"

// TracingSnapshotter wraps a snapshotter service with OpenTelemetry tracing
type TracingSnapshotter struct {
server snapshotsapi.SnapshotsServer
Expand All @@ -45,7 +42,7 @@ func WithTracing(server snapshotsapi.SnapshotsServer) snapshotsapi.SnapshotsServ
}

func (s *TracingSnapshotter) Prepare(ctx context.Context, pr *snapshotsapi.PrepareSnapshotRequest) (*snapshotsapi.PrepareSnapshotResponse, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "snapshotter.Prepare", trace.WithAttributes(
ctx, span := GetDefaultTracer().Start(ctx, "snapshotter.Prepare", trace.WithAttributes(
attribute.String("key", pr.Key),
attribute.String("parent", pr.Parent),
))
Expand All @@ -59,7 +56,7 @@ func (s *TracingSnapshotter) Prepare(ctx context.Context, pr *snapshotsapi.Prepa
}

func (s *TracingSnapshotter) View(ctx context.Context, pr *snapshotsapi.ViewSnapshotRequest) (*snapshotsapi.ViewSnapshotResponse, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "snapshotter.View", trace.WithAttributes(
ctx, span := GetDefaultTracer().Start(ctx, "snapshotter.View", trace.WithAttributes(
attribute.String("key", pr.Key),
attribute.String("parent", pr.Parent),
))
Expand All @@ -73,7 +70,7 @@ func (s *TracingSnapshotter) View(ctx context.Context, pr *snapshotsapi.ViewSnap
}

func (s *TracingSnapshotter) Mounts(ctx context.Context, mr *snapshotsapi.MountsRequest) (*snapshotsapi.MountsResponse, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "snapshotter.Mounts", trace.WithAttributes(
ctx, span := GetDefaultTracer().Start(ctx, "snapshotter.Mounts", trace.WithAttributes(
attribute.String("key", mr.Key),
))
defer span.End()
Expand All @@ -86,7 +83,7 @@ func (s *TracingSnapshotter) Mounts(ctx context.Context, mr *snapshotsapi.Mounts
}

func (s *TracingSnapshotter) Commit(ctx context.Context, cr *snapshotsapi.CommitSnapshotRequest) (*ptypes.Empty, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "snapshotter.Commit", trace.WithAttributes(
ctx, span := GetDefaultTracer().Start(ctx, "snapshotter.Commit", trace.WithAttributes(
attribute.String("name", cr.Name),
attribute.String("key", cr.Key),
))
Expand All @@ -100,7 +97,7 @@ func (s *TracingSnapshotter) Commit(ctx context.Context, cr *snapshotsapi.Commit
}

func (s *TracingSnapshotter) Remove(ctx context.Context, rr *snapshotsapi.RemoveSnapshotRequest) (*ptypes.Empty, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "snapshotter.Remove", trace.WithAttributes(
ctx, span := GetDefaultTracer().Start(ctx, "snapshotter.Remove", trace.WithAttributes(
attribute.String("key", rr.Key),
))
defer span.End()
Expand All @@ -113,20 +110,12 @@ func (s *TracingSnapshotter) Remove(ctx context.Context, rr *snapshotsapi.Remove
}

func (s *TracingSnapshotter) Stat(ctx context.Context, sr *snapshotsapi.StatSnapshotRequest) (*snapshotsapi.StatSnapshotResponse, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "snapshotter.Stat", trace.WithAttributes(
attribute.String("key", sr.Key),
))
defer span.End()

resp, err := s.server.Stat(ctx, sr)
if err != nil {
span.RecordError(err)
}
return resp, err
}

func (s *TracingSnapshotter) Update(ctx context.Context, sr *snapshotsapi.UpdateSnapshotRequest) (*snapshotsapi.UpdateSnapshotResponse, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "snapshotter.Update", trace.WithAttributes(
ctx, span := GetDefaultTracer().Start(ctx, "snapshotter.Update", trace.WithAttributes(
attribute.String("name", sr.Info.Name),
))
defer span.End()
Expand All @@ -139,7 +128,7 @@ func (s *TracingSnapshotter) Update(ctx context.Context, sr *snapshotsapi.Update
}

func (s *TracingSnapshotter) List(sr *snapshotsapi.ListSnapshotsRequest, ss snapshotsapi.Snapshots_ListServer) error {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ss.Context(), "snapshotter.List")
ctx, span := GetDefaultTracer().Start(ss.Context(), "snapshotter.List")
defer span.End()

err := s.server.List(sr, &tracingListServer{
Expand All @@ -162,26 +151,12 @@ func (t *tracingListServer) Context() context.Context {
}

func (s *TracingSnapshotter) Usage(ctx context.Context, ur *snapshotsapi.UsageRequest) (*snapshotsapi.UsageResponse, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "snapshotter.Usage", trace.WithAttributes(
attribute.String("key", ur.Key),
))
defer span.End()

resp, err := s.server.Usage(ctx, ur)
if err != nil {
span.RecordError(err)
}
if resp != nil {
span.SetAttributes(
attribute.Int64("inodes", resp.Inodes),
attribute.Int64("size", resp.Size),
)
}
return resp, err
}

func (s *TracingSnapshotter) Cleanup(ctx context.Context, cr *snapshotsapi.CleanupRequest) (*ptypes.Empty, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "snapshotter.Cleanup")
ctx, span := GetDefaultTracer().Start(ctx, "snapshotter.Cleanup")
defer span.End()

resp, err := s.server.Cleanup(ctx, cr)
Expand Down
7 changes: 7 additions & 0 deletions pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
"go.opentelemetry.io/otel/trace"
)

const tracerName = "accelerated-container-image/snapshotter"

var (
serviceName = os.Getenv("OTEL_SERVICE_NAME")
)
Expand Down Expand Up @@ -62,3 +65,7 @@ func InitTracer(ctx context.Context) (func(context.Context) error, error) {
// Return shutdown function
return tp.Shutdown, nil
}

func GetDefaultTracer() trace.Tracer {
return otel.GetTracerProvider().Tracer(tracerName)
}
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type OverlayBDBSConfig struct {
ResultFile string `json:"resultFile"`
AccelerationLayer bool `json:"accelerationLayer,omitempty"`
RecordTracePath string `json:"recordTracePath,omitempty"`
TraceContext map[string]string `json:"traceContext,omitempty"`
}

// OverlayBDBSConfigLower
Expand Down
Loading
Loading