diff --git a/cmd/containerd-shim-runhcs-v1/delete.go b/cmd/containerd-shim-runhcs-v1/delete.go index 3fc4447c68..cb8d5075dd 100644 --- a/cmd/containerd-shim-runhcs-v1/delete.go +++ b/cmd/containerd-shim-runhcs-v1/delete.go @@ -18,7 +18,6 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli" - "go.opencensus.io/trace" ) // LimitedRead reads at max `readLimitBytes` bytes from the file at path `filePath`. If the file has @@ -56,7 +55,7 @@ The delete command will be executed in the container's bundle as its cwd. // task.DeleteResponse by protocol. We can write to stderr which will be // logged as a warning in containerd. - ctx, span := trace.StartSpan(gcontext.Background(), "delete") + ctx, span := oc.StartSpan(gcontext.Background(), "delete") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/cmd/containerd-shim-runhcs-v1/events.go b/cmd/containerd-shim-runhcs-v1/events.go index 71ec3efdc6..fd791e7adf 100644 --- a/cmd/containerd-shim-runhcs-v1/events.go +++ b/cmd/containerd-shim-runhcs-v1/events.go @@ -39,7 +39,7 @@ func (e *eventPublisher) close() error { } func (e *eventPublisher) publishEvent(ctx context.Context, topic string, event interface{}) (err error) { - ctx, span := trace.StartSpan(ctx, "publishEvent") + ctx, span := oc.StartSpan(ctx, "publishEvent") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/cmd/containerd-shim-runhcs-v1/exec_hcs.go b/cmd/containerd-shim-runhcs-v1/exec_hcs.go index ffad91cb5a..49a7d396e8 100644 --- a/cmd/containerd-shim-runhcs-v1/exec_hcs.go +++ b/cmd/containerd-shim-runhcs-v1/exec_hcs.go @@ -20,6 +20,7 @@ import ( "github.com/Microsoft/hcsshim/internal/cmd" "github.com/Microsoft/hcsshim/internal/cow" "github.com/Microsoft/hcsshim/internal/log" + "github.com/Microsoft/hcsshim/internal/oc" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" "github.com/Microsoft/hcsshim/internal/signals" "github.com/Microsoft/hcsshim/internal/uvm" @@ -416,13 +417,15 @@ func (he *hcsExec) exitFromCreatedL(ctx context.Context, status int) { // // 7. Finally, save the UVM and this container as a template if specified. func (he *hcsExec) waitForExit() { - ctx, span := trace.StartSpan(context.Background(), "hcsExec::waitForExit") + var err error // this will only save the last error, since we dont return early on error + ctx, span := oc.StartSpan(context.Background(), "hcsExec::waitForExit") defer span.End() + defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( trace.StringAttribute("tid", he.tid), trace.StringAttribute("eid", he.id)) - err := he.p.Process.Wait() + err = he.p.Process.Wait() if err != nil { log.G(ctx).WithError(err).Error("failed process Wait") } @@ -478,7 +481,7 @@ func (he *hcsExec) waitForExit() { // // This MUST be called via a goroutine at exec create. func (he *hcsExec) waitForContainerExit() { - ctx, span := trace.StartSpan(context.Background(), "hcsExec::waitForContainerExit") + ctx, span := oc.StartSpan(context.Background(), "hcsExec::waitForContainerExit") defer span.End() span.AddAttributes( trace.StringAttribute("tid", he.tid), diff --git a/cmd/containerd-shim-runhcs-v1/main.go b/cmd/containerd-shim-runhcs-v1/main.go index f64d93ec30..55e4c3a55e 100644 --- a/cmd/containerd-shim-runhcs-v1/main.go +++ b/cmd/containerd-shim-runhcs-v1/main.go @@ -13,6 +13,7 @@ import ( "github.com/Microsoft/go-winio/pkg/etw" "github.com/Microsoft/go-winio/pkg/etwlogrus" "github.com/Microsoft/go-winio/pkg/guid" + "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/oc" "github.com/Microsoft/hcsshim/internal/shimdiag" specs "github.com/opencontainers/runtime-spec/specs-go" @@ -64,6 +65,8 @@ func etwCallback(sourceID guid.GUID, state etw.ProviderState, level etw.Level, m } func main() { + logrus.AddHook(log.NewHook()) + // Provider ID: 0b52781f-b24d-5685-ddf6-69830ed40ec3 // Provider and hook aren't closed explicitly, as they will exist until process exit. provider, err := etw.NewProvider("Microsoft.Virtualization.RunHCS", etwCallback) @@ -86,7 +89,7 @@ func main() { ) // Register our OpenCensus logrus exporter - trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) + trace.ApplyConfig(trace.Config{DefaultSampler: oc.DefaultSampler}) trace.RegisterExporter(&oc.LogrusExporter{}) app := cli.NewApp() diff --git a/cmd/containerd-shim-runhcs-v1/service.go b/cmd/containerd-shim-runhcs-v1/service.go index 92abc70a5c..2d900ab41b 100644 --- a/cmd/containerd-shim-runhcs-v1/service.go +++ b/cmd/containerd-shim-runhcs-v1/service.go @@ -98,7 +98,7 @@ func NewService(o ...ServiceOption) (svc *service, err error) { } func (s *service) State(ctx context.Context, req *task.StateRequest) (resp *task.StateResponse, err error) { - ctx, span := trace.StartSpan(ctx, "State") + ctx, span := oc.StartSpan(ctx, "State") defer span.End() defer func() { if resp != nil { @@ -123,7 +123,7 @@ func (s *service) State(ctx context.Context, req *task.StateRequest) (resp *task } func (s *service) Create(ctx context.Context, req *task.CreateTaskRequest) (resp *task.CreateTaskResponse, err error) { - ctx, span := trace.StartSpan(ctx, "Create") + ctx, span := oc.StartSpan(ctx, "Create") defer span.End() defer func() { if resp != nil { @@ -153,7 +153,7 @@ func (s *service) Create(ctx context.Context, req *task.CreateTaskRequest) (resp } func (s *service) Start(ctx context.Context, req *task.StartRequest) (resp *task.StartResponse, err error) { - ctx, span := trace.StartSpan(ctx, "Start") + ctx, span := oc.StartSpan(ctx, "Start") defer span.End() defer func() { if resp != nil { @@ -175,7 +175,7 @@ func (s *service) Start(ctx context.Context, req *task.StartRequest) (resp *task } func (s *service) Delete(ctx context.Context, req *task.DeleteRequest) (resp *task.DeleteResponse, err error) { - ctx, span := trace.StartSpan(ctx, "Delete") + ctx, span := oc.StartSpan(ctx, "Delete") defer span.End() defer func() { if resp != nil { @@ -200,7 +200,7 @@ func (s *service) Delete(ctx context.Context, req *task.DeleteRequest) (resp *ta } func (s *service) Pids(ctx context.Context, req *task.PidsRequest) (_ *task.PidsResponse, err error) { - ctx, span := trace.StartSpan(ctx, "Pids") + ctx, span := oc.StartSpan(ctx, "Pids") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -215,7 +215,7 @@ func (s *service) Pids(ctx context.Context, req *task.PidsRequest) (_ *task.Pids } func (s *service) Pause(ctx context.Context, req *task.PauseRequest) (_ *google_protobuf1.Empty, err error) { - ctx, span := trace.StartSpan(ctx, "Pause") + ctx, span := oc.StartSpan(ctx, "Pause") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -230,7 +230,7 @@ func (s *service) Pause(ctx context.Context, req *task.PauseRequest) (_ *google_ } func (s *service) Resume(ctx context.Context, req *task.ResumeRequest) (_ *google_protobuf1.Empty, err error) { - ctx, span := trace.StartSpan(ctx, "Resume") + ctx, span := oc.StartSpan(ctx, "Resume") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -245,7 +245,7 @@ func (s *service) Resume(ctx context.Context, req *task.ResumeRequest) (_ *googl } func (s *service) Checkpoint(ctx context.Context, req *task.CheckpointTaskRequest) (_ *google_protobuf1.Empty, err error) { - ctx, span := trace.StartSpan(ctx, "Checkpoint") + ctx, span := oc.StartSpan(ctx, "Checkpoint") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -262,7 +262,7 @@ func (s *service) Checkpoint(ctx context.Context, req *task.CheckpointTaskReques } func (s *service) Kill(ctx context.Context, req *task.KillRequest) (_ *google_protobuf1.Empty, err error) { - ctx, span := trace.StartSpan(ctx, "Kill") + ctx, span := oc.StartSpan(ctx, "Kill") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -281,7 +281,7 @@ func (s *service) Kill(ctx context.Context, req *task.KillRequest) (_ *google_pr } func (s *service) Exec(ctx context.Context, req *task.ExecProcessRequest) (_ *google_protobuf1.Empty, err error) { - ctx, span := trace.StartSpan(ctx, "Exec") + ctx, span := oc.StartSpan(ctx, "Exec") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -302,7 +302,7 @@ func (s *service) Exec(ctx context.Context, req *task.ExecProcessRequest) (_ *go } func (s *service) DiagExecInHost(ctx context.Context, req *shimdiag.ExecProcessRequest) (_ *shimdiag.ExecProcessResponse, err error) { - ctx, span := trace.StartSpan(ctx, "DiagExecInHost") + ctx, span := oc.StartSpan(ctx, "DiagExecInHost") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -323,7 +323,7 @@ func (s *service) DiagExecInHost(ctx context.Context, req *shimdiag.ExecProcessR } func (s *service) DiagShare(ctx context.Context, req *shimdiag.ShareRequest) (_ *shimdiag.ShareResponse, err error) { - ctx, span := trace.StartSpan(ctx, "DiagShare") + ctx, span := oc.StartSpan(ctx, "DiagShare") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -341,7 +341,7 @@ func (s *service) DiagShare(ctx context.Context, req *shimdiag.ShareRequest) (_ } func (s *service) ResizePty(ctx context.Context, req *task.ResizePtyRequest) (_ *google_protobuf1.Empty, err error) { - ctx, span := trace.StartSpan(ctx, "ResizePty") + ctx, span := oc.StartSpan(ctx, "ResizePty") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -360,7 +360,7 @@ func (s *service) ResizePty(ctx context.Context, req *task.ResizePtyRequest) (_ } func (s *service) CloseIO(ctx context.Context, req *task.CloseIORequest) (_ *google_protobuf1.Empty, err error) { - ctx, span := trace.StartSpan(ctx, "CloseIO") + ctx, span := oc.StartSpan(ctx, "CloseIO") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -378,7 +378,7 @@ func (s *service) CloseIO(ctx context.Context, req *task.CloseIORequest) (_ *goo } func (s *service) Update(ctx context.Context, req *task.UpdateTaskRequest) (_ *google_protobuf1.Empty, err error) { - ctx, span := trace.StartSpan(ctx, "Update") + ctx, span := oc.StartSpan(ctx, "Update") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -393,7 +393,7 @@ func (s *service) Update(ctx context.Context, req *task.UpdateTaskRequest) (_ *g } func (s *service) Wait(ctx context.Context, req *task.WaitRequest) (resp *task.WaitResponse, err error) { - ctx, span := trace.StartSpan(ctx, "Wait") + ctx, span := oc.StartSpan(ctx, "Wait") defer span.End() defer func() { if resp != nil { @@ -417,7 +417,7 @@ func (s *service) Wait(ctx context.Context, req *task.WaitRequest) (resp *task.W } func (s *service) Stats(ctx context.Context, req *task.StatsRequest) (_ *task.StatsResponse, err error) { - ctx, span := trace.StartSpan(ctx, "Stats") + ctx, span := oc.StartSpan(ctx, "Stats") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -432,7 +432,7 @@ func (s *service) Stats(ctx context.Context, req *task.StatsRequest) (_ *task.St } func (s *service) Connect(ctx context.Context, req *task.ConnectRequest) (resp *task.ConnectResponse, err error) { - ctx, span := trace.StartSpan(ctx, "Connect") + ctx, span := oc.StartSpan(ctx, "Connect") defer span.End() defer func() { if resp != nil { @@ -455,7 +455,7 @@ func (s *service) Connect(ctx context.Context, req *task.ConnectRequest) (resp * } func (s *service) Shutdown(ctx context.Context, req *task.ShutdownRequest) (_ *google_protobuf1.Empty, err error) { - ctx, span := trace.StartSpan(ctx, "Shutdown") + ctx, span := oc.StartSpan(ctx, "Shutdown") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -473,7 +473,7 @@ func (s *service) DiagStacks(ctx context.Context, req *shimdiag.StacksRequest) ( if s == nil { return nil, nil } - ctx, span := trace.StartSpan(ctx, "DiagStacks") + ctx, span := oc.StartSpan(ctx, "DiagStacks") defer span.End() span.AddAttributes(trace.StringAttribute("tid", s.tid)) @@ -505,7 +505,7 @@ func (s *service) DiagPid(ctx context.Context, req *shimdiag.PidRequest) (*shimd if s == nil { return nil, nil } - ctx, span := trace.StartSpan(ctx, "DiagPid") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "DiagPid") //nolint:ineffassign,staticcheck defer span.End() span.AddAttributes(trace.StringAttribute("tid", s.tid)) @@ -516,7 +516,7 @@ func (s *service) DiagPid(ctx context.Context, req *shimdiag.PidRequest) (*shimd } func (s *service) ComputeProcessorInfo(ctx context.Context, req *extendedtask.ComputeProcessorInfoRequest) (*extendedtask.ComputeProcessorInfoResponse, error) { - ctx, span := trace.StartSpan(ctx, "ComputeProcessorInfo") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "ComputeProcessorInfo") //nolint:ineffassign,staticcheck defer span.End() span.AddAttributes(trace.StringAttribute("tid", s.tid)) diff --git a/cmd/containerd-shim-runhcs-v1/task_hcs.go b/cmd/containerd-shim-runhcs-v1/task_hcs.go index 32f6a2055f..b2aaa5b6b5 100644 --- a/cmd/containerd-shim-runhcs-v1/task_hcs.go +++ b/cmd/containerd-shim-runhcs-v1/task_hcs.go @@ -32,6 +32,7 @@ import ( "github.com/Microsoft/hcsshim/internal/jobcontainers" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/memory" + "github.com/Microsoft/hcsshim/internal/oc" "github.com/Microsoft/hcsshim/internal/oci" "github.com/Microsoft/hcsshim/internal/processorinfo" "github.com/Microsoft/hcsshim/internal/protocol/guestrequest" @@ -692,7 +693,7 @@ func (ht *hcsTask) Wait() *task.StateResponse { } func (ht *hcsTask) waitInitExit(destroyContainer bool) { - ctx, span := trace.StartSpan(context.Background(), "hcsTask::waitInitExit") + ctx, span := oc.StartSpan(context.Background(), "hcsTask::waitInitExit") defer span.End() span.AddAttributes(trace.StringAttribute("tid", ht.id)) @@ -723,7 +724,7 @@ func (ht *hcsTask) waitInitExit(destroyContainer bool) { // Note: For Windows process isolated containers there is no host virtual // machine so this should not be called. func (ht *hcsTask) waitForHostExit() { - ctx, span := trace.StartSpan(context.Background(), "hcsTask::waitForHostExit") + ctx, span := oc.StartSpan(context.Background(), "hcsTask::waitForHostExit") defer span.End() span.AddAttributes(trace.StringAttribute("tid", ht.id)) diff --git a/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go b/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go index c99dea3483..3e254edaa6 100644 --- a/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go +++ b/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go @@ -12,6 +12,7 @@ import ( "github.com/Microsoft/hcsshim/internal/clone" "github.com/Microsoft/hcsshim/internal/cmd" "github.com/Microsoft/hcsshim/internal/log" + "github.com/Microsoft/hcsshim/internal/oc" "github.com/Microsoft/hcsshim/internal/shimdiag" "github.com/Microsoft/hcsshim/internal/uvm" eventstypes "github.com/containerd/containerd/api/events" @@ -212,7 +213,7 @@ func (wpst *wcowPodSandboxTask) close(ctx context.Context) { } func (wpst *wcowPodSandboxTask) waitInitExit() { - ctx, span := trace.StartSpan(context.Background(), "wcowPodSandboxTask::waitInitExit") + ctx, span := oc.StartSpan(context.Background(), "wcowPodSandboxTask::waitInitExit") defer span.End() span.AddAttributes(trace.StringAttribute("tid", wpst.id)) @@ -224,7 +225,7 @@ func (wpst *wcowPodSandboxTask) waitInitExit() { } func (wpst *wcowPodSandboxTask) waitParentExit() { - ctx, span := trace.StartSpan(context.Background(), "wcowPodSandboxTask::waitParentExit") + ctx, span := oc.StartSpan(context.Background(), "wcowPodSandboxTask::waitParentExit") defer span.End() span.AddAttributes(trace.StringAttribute("tid", wpst.id)) diff --git a/cmd/gcs/main.go b/cmd/gcs/main.go index 13f3201fe7..443240ed6b 100644 --- a/cmd/gcs/main.go +++ b/cmd/gcs/main.go @@ -197,6 +197,8 @@ func main() { trace.RegisterExporter(&oc.LogrusExporter{}) } + logrus.AddHook(log.NewHook()) + // Use a file instead of stdout if *logFile != "" { logFileHandle, err := os.OpenFile(*logFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) diff --git a/cmd/ncproxy/ncproxy.go b/cmd/ncproxy/ncproxy.go index f5de74c66f..cce0d3aeac 100644 --- a/cmd/ncproxy/ncproxy.go +++ b/cmd/ncproxy/ncproxy.go @@ -63,7 +63,7 @@ func newGRPCService(agentCache *computeAgentCache, ncproxyNetworking *ncproxysto var _ ncproxygrpc.NetworkConfigProxyServer = &grpcService{} func (s *grpcService) AddNIC(ctx context.Context, req *ncproxygrpc.AddNICRequest) (_ *ncproxygrpc.AddNICResponse, err error) { - ctx, span := trace.StartSpan(ctx, "AddNIC") + ctx, span := oc.StartSpan(ctx, "AddNIC") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -158,7 +158,7 @@ func (s *grpcService) AddNIC(ctx context.Context, req *ncproxygrpc.AddNICRequest } func (s *grpcService) ModifyNIC(ctx context.Context, req *ncproxygrpc.ModifyNICRequest) (_ *ncproxygrpc.ModifyNICResponse, err error) { - ctx, span := trace.StartSpan(ctx, "ModifyNIC") + ctx, span := oc.StartSpan(ctx, "ModifyNIC") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -252,7 +252,7 @@ func (s *grpcService) ModifyNIC(ctx context.Context, req *ncproxygrpc.ModifyNICR } func (s *grpcService) DeleteNIC(ctx context.Context, req *ncproxygrpc.DeleteNICRequest) (_ *ncproxygrpc.DeleteNICResponse, err error) { - ctx, span := trace.StartSpan(ctx, "DeleteNIC") + ctx, span := oc.StartSpan(ctx, "DeleteNIC") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -307,7 +307,7 @@ func (s *grpcService) DeleteNIC(ctx context.Context, req *ncproxygrpc.DeleteNICR } func (s *grpcService) CreateNetwork(ctx context.Context, req *ncproxygrpc.CreateNetworkRequest) (_ *ncproxygrpc.CreateNetworkResponse, err error) { - ctx, span := trace.StartSpan(ctx, "CreateNetwork") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "CreateNetwork") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -357,7 +357,7 @@ func (s *grpcService) CreateNetwork(ctx context.Context, req *ncproxygrpc.Create } func (s *grpcService) CreateEndpoint(ctx context.Context, req *ncproxygrpc.CreateEndpointRequest) (_ *ncproxygrpc.CreateEndpointResponse, err error) { - ctx, span := trace.StartSpan(ctx, "CreateEndpoint") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "CreateEndpoint") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -434,7 +434,7 @@ func (s *grpcService) CreateEndpoint(ctx context.Context, req *ncproxygrpc.Creat } func (s *grpcService) AddEndpoint(ctx context.Context, req *ncproxygrpc.AddEndpointRequest) (_ *ncproxygrpc.AddEndpointResponse, err error) { - ctx, span := trace.StartSpan(ctx, "AddEndpoint") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "AddEndpoint") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -472,7 +472,7 @@ func (s *grpcService) AddEndpoint(ctx context.Context, req *ncproxygrpc.AddEndpo } func (s *grpcService) DeleteEndpoint(ctx context.Context, req *ncproxygrpc.DeleteEndpointRequest) (_ *ncproxygrpc.DeleteEndpointResponse, err error) { - ctx, span := trace.StartSpan(ctx, "DeleteEndpoint") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "DeleteEndpoint") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -508,7 +508,7 @@ func (s *grpcService) DeleteEndpoint(ctx context.Context, req *ncproxygrpc.Delet } func (s *grpcService) DeleteNetwork(ctx context.Context, req *ncproxygrpc.DeleteNetworkRequest) (_ *ncproxygrpc.DeleteNetworkResponse, err error) { - ctx, span := trace.StartSpan(ctx, "DeleteNetwork") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "DeleteNetwork") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -577,7 +577,7 @@ func ncpNetworkingEndpointToEndpointResponse(ep *ncproxynetworking.Endpoint) (_ } func (s *grpcService) GetEndpoint(ctx context.Context, req *ncproxygrpc.GetEndpointRequest) (_ *ncproxygrpc.GetEndpointResponse, err error) { - ctx, span := trace.StartSpan(ctx, "GetEndpoint") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "GetEndpoint") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -605,7 +605,7 @@ func (s *grpcService) GetEndpoint(ctx context.Context, req *ncproxygrpc.GetEndpo } func (s *grpcService) GetEndpoints(ctx context.Context, req *ncproxygrpc.GetEndpointsRequest) (_ *ncproxygrpc.GetEndpointsResponse, err error) { - ctx, span := trace.StartSpan(ctx, "GetEndpoints") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "GetEndpoints") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -656,7 +656,7 @@ func ncpNetworkingNetworkToNetworkResponse(network *ncproxynetworking.Network) ( } func (s *grpcService) GetNetwork(ctx context.Context, req *ncproxygrpc.GetNetworkRequest) (_ *ncproxygrpc.GetNetworkResponse, err error) { - ctx, span := trace.StartSpan(ctx, "GetNetwork") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "GetNetwork") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -685,7 +685,7 @@ func (s *grpcService) GetNetwork(ctx context.Context, req *ncproxygrpc.GetNetwor } func (s *grpcService) GetNetworks(ctx context.Context, req *ncproxygrpc.GetNetworksRequest) (_ *ncproxygrpc.GetNetworksResponse, err error) { - ctx, span := trace.StartSpan(ctx, "GetNetworks") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "GetNetworks") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -755,7 +755,7 @@ func getComputeAgentClient(agentAddr string) (*computeAgentClient, error) { } func (s *ttrpcService) RegisterComputeAgent(ctx context.Context, req *ncproxyttrpc.RegisterComputeAgentRequest) (_ *ncproxyttrpc.RegisterComputeAgentResponse, err error) { - ctx, span := trace.StartSpan(ctx, "RegisterComputeAgent") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "RegisterComputeAgent") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -782,7 +782,7 @@ func (s *ttrpcService) RegisterComputeAgent(ctx context.Context, req *ncproxyttr } func (s *ttrpcService) UnregisterComputeAgent(ctx context.Context, req *ncproxyttrpc.UnregisterComputeAgentRequest) (_ *ncproxyttrpc.UnregisterComputeAgentResponse, err error) { - ctx, span := trace.StartSpan(ctx, "UnregisterComputeAgent") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "UnregisterComputeAgent") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -809,7 +809,7 @@ func (s *ttrpcService) UnregisterComputeAgent(ctx context.Context, req *ncproxyt } func (s *ttrpcService) ConfigureNetworking(ctx context.Context, req *ncproxyttrpc.ConfigureNetworkingInternalRequest) (_ *ncproxyttrpc.ConfigureNetworkingInternalResponse, err error) { - ctx, span := trace.StartSpan(ctx, "ConfigureNetworking") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "ConfigureNetworking") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/cmd/runhcs/create-scratch.go b/cmd/runhcs/create-scratch.go index 9f63df4a69..752155f63c 100644 --- a/cmd/runhcs/create-scratch.go +++ b/cmd/runhcs/create-scratch.go @@ -12,7 +12,6 @@ import ( "github.com/Microsoft/hcsshim/osversion" "github.com/pkg/errors" "github.com/urfave/cli" - "go.opencensus.io/trace" ) var createScratchCommand = cli.Command{ @@ -36,7 +35,7 @@ var createScratchCommand = cli.Command{ }, Before: appargs.Validate(), Action: func(context *cli.Context) (err error) { - ctx, span := trace.StartSpan(gcontext.Background(), "create-scratch") + ctx, span := oc.StartSpan(gcontext.Background(), "create-scratch") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/cmd/runhcs/prepare-disk.go b/cmd/runhcs/prepare-disk.go index bebd641c20..897d10ca5d 100644 --- a/cmd/runhcs/prepare-disk.go +++ b/cmd/runhcs/prepare-disk.go @@ -12,7 +12,6 @@ import ( "github.com/Microsoft/hcsshim/osversion" "github.com/pkg/errors" "github.com/urfave/cli" - "go.opencensus.io/trace" ) const ( @@ -32,7 +31,7 @@ var prepareDiskCommand = cli.Command{ }, Before: appargs.Validate(), Action: func(context *cli.Context) (err error) { - ctx, span := trace.StartSpan(gcontext.Background(), prepareDiskStr) + ctx, span := oc.StartSpan(gcontext.Background(), prepareDiskStr) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/computestorage/attach.go b/computestorage/attach.go index 05b6ea7bd4..54c4b3bc4a 100644 --- a/computestorage/attach.go +++ b/computestorage/attach.go @@ -19,8 +19,8 @@ import ( // // `layerData` is the parent read-only layer data. func AttachLayerStorageFilter(ctx context.Context, layerPath string, layerData LayerData) (err error) { - title := "hcsshim.AttachLayerStorageFilter" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::AttachLayerStorageFilter" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/computestorage/destroy.go b/computestorage/destroy.go index 8dd942bab9..5058d3b55e 100644 --- a/computestorage/destroy.go +++ b/computestorage/destroy.go @@ -14,8 +14,8 @@ import ( // // `layerPath` is a path to a directory containing the layer to export. func DestroyLayer(ctx context.Context, layerPath string) (err error) { - title := "hcsshim.DestroyLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::DestroyLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("layerPath", layerPath)) diff --git a/computestorage/detach.go b/computestorage/detach.go index 934ee5b1a6..daf1bfff20 100644 --- a/computestorage/detach.go +++ b/computestorage/detach.go @@ -14,8 +14,8 @@ import ( // // `layerPath` is a path to a directory containing the layer to export. func DetachLayerStorageFilter(ctx context.Context, layerPath string) (err error) { - title := "hcsshim.DetachLayerStorageFilter" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::DetachLayerStorageFilter" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("layerPath", layerPath)) diff --git a/computestorage/export.go b/computestorage/export.go index cf90d9b6c9..c6370a5c9a 100644 --- a/computestorage/export.go +++ b/computestorage/export.go @@ -21,8 +21,8 @@ import ( // // `options` are the export options applied to the exported layer. func ExportLayer(ctx context.Context, layerPath, exportFolderPath string, layerData LayerData, options ExportLayerOptions) (err error) { - title := "hcsshim.ExportLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::ExportLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/computestorage/format.go b/computestorage/format.go index 05e0729f50..4a5735e989 100644 --- a/computestorage/format.go +++ b/computestorage/format.go @@ -11,7 +11,6 @@ import ( "github.com/Microsoft/hcsshim/internal/oc" "github.com/Microsoft/hcsshim/osversion" "github.com/pkg/errors" - "go.opencensus.io/trace" "golang.org/x/sys/windows" ) @@ -43,8 +42,8 @@ func openDisk(path string) (windows.Handle, error) { // // If the VHD is not mounted it will be temporarily mounted. func FormatWritableLayerVhd(ctx context.Context, vhdHandle windows.Handle) (err error) { - title := "hcsshim.FormatWritableLayerVhd" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::FormatWritableLayerVhd" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/computestorage/import.go b/computestorage/import.go index a40b4037cc..e1c87416a3 100644 --- a/computestorage/import.go +++ b/computestorage/import.go @@ -21,8 +21,8 @@ import ( // // `layerData` is the parent layer data. func ImportLayer(ctx context.Context, layerPath, sourceFolderPath string, layerData LayerData) (err error) { - title := "hcsshim.ImportLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::ImportLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/computestorage/initialize.go b/computestorage/initialize.go index ddd8f318da..d0c6216056 100644 --- a/computestorage/initialize.go +++ b/computestorage/initialize.go @@ -18,8 +18,8 @@ import ( // // `layerData` is the parent read-only layer data. func InitializeWritableLayer(ctx context.Context, layerPath string, layerData LayerData) (err error) { - title := "hcsshim.InitializeWritableLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::InitializeWritableLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/computestorage/mount.go b/computestorage/mount.go index 6e445e766b..4f4d8ebf2f 100644 --- a/computestorage/mount.go +++ b/computestorage/mount.go @@ -8,14 +8,13 @@ import ( "github.com/Microsoft/hcsshim/internal/interop" "github.com/Microsoft/hcsshim/internal/oc" "github.com/pkg/errors" - "go.opencensus.io/trace" "golang.org/x/sys/windows" ) // GetLayerVhdMountPath returns the volume path for a virtual disk of a writable container layer. func GetLayerVhdMountPath(ctx context.Context, vhdHandle windows.Handle) (path string, err error) { - title := "hcsshim.GetLayerVhdMountPath" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::GetLayerVhdMountPath" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/computestorage/setup.go b/computestorage/setup.go index 4b27b895ad..faec837ca1 100644 --- a/computestorage/setup.go +++ b/computestorage/setup.go @@ -23,8 +23,8 @@ import ( // // `options` are the options applied while processing the layer. func SetupBaseOSLayer(ctx context.Context, layerPath string, vhdHandle windows.Handle, options OsLayerOptions) (err error) { - title := "hcsshim.SetupBaseOSLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::SetupBaseOSLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -54,8 +54,8 @@ func SetupBaseOSVolume(ctx context.Context, layerPath, volumePath string, option if osversion.Build() < 19645 { return errors.New("SetupBaseOSVolume is not present on builds older than 19645") } - title := "hcsshim.SetupBaseOSVolume" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::SetupBaseOSVolume" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/hcn/hcnsupport.go b/hcn/hcnsupport.go index 00af20be31..1b4c240205 100644 --- a/hcn/hcnsupport.go +++ b/hcn/hcnsupport.go @@ -3,11 +3,12 @@ package hcn import ( - "fmt" "sync" "github.com/pkg/errors" "github.com/sirupsen/logrus" + + "github.com/Microsoft/hcsshim/internal/log" ) var ( @@ -114,9 +115,9 @@ func getSupportedFeatures() (SupportedFeatures, error) { features.NetworkACL = isFeatureSupported(globals.Version, NetworkACLPolicyVersion) features.NestedIpSet = isFeatureSupported(globals.Version, NestedIpSetVersion) - logrus.WithFields(logrus.Fields{ - "version": fmt.Sprintf("%+v", globals.Version), - "supportedFeatures": fmt.Sprintf("%+v", features), + log.L.WithFields(logrus.Fields{ + "version": globals.Version, + "supportedFeatures": features, }).Info("HCN feature check") return features, nil diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 758eb78880..d7228619eb 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -13,6 +13,7 @@ import ( "github.com/Microsoft/hcsshim/internal/cow" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" + "github.com/Microsoft/hcsshim/internal/log" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" @@ -111,7 +112,7 @@ func Command(host cow.ProcessHost, name string, arg ...string) *Cmd { Spec: &specs.Process{ Args: append([]string{name}, arg...), }, - Log: logrus.NewEntry(logrus.StandardLogger()), + Log: log.L.Dup(), ExitState: &ExitState{}, } if host.OS() == "windows" { @@ -128,6 +129,7 @@ func Command(host cow.ProcessHost, name string, arg ...string) *Cmd { func CommandContext(ctx context.Context, host cow.ProcessHost, name string, arg ...string) *Cmd { cmd := Command(host, name, arg...) cmd.Context = ctx + cmd.Log = log.G(ctx) return cmd } @@ -239,7 +241,14 @@ func (c *Cmd) Start() error { go func() { select { case <-c.Context.Done(): - _, _ = c.Process.Kill(context.TODO()) + // Process.Kill (via Process.Signal) will not send an RPC if the + // provided context in is cancelled (bridge.AsyncRPC will end early) + ctx := c.Context + if ctx == nil { + ctx = context.Background() + } + kctx := log.Copy(context.Background(), ctx) + _, _ = c.Process.Kill(kctx) case <-c.allDoneCh: } }() diff --git a/internal/copyfile/copyfile.go b/internal/copyfile/copyfile.go index 61aa2dc405..ea3e65b543 100644 --- a/internal/copyfile/copyfile.go +++ b/internal/copyfile/copyfile.go @@ -20,7 +20,7 @@ var ( // CopyFile is a utility for copying a file using CopyFileW win32 API for // performance. func CopyFile(ctx context.Context, srcFile, destFile string, overwrite bool) (err error) { - ctx, span := trace.StartSpan(ctx, "copyfile::CopyFile") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "copyfile::CopyFile") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/internal/gcs/bridge.go b/internal/gcs/bridge.go index 1e3e7c201d..18d293adf5 100644 --- a/internal/gcs/bridge.go +++ b/internal/gcs/bridge.go @@ -311,7 +311,7 @@ func (brdg *bridge) recvLoop() error { } brdg.log.WithFields(logrus.Fields{ "payload": string(b), - "type": typ, + "type": typ.String(), "message-id": id}).Debug("bridge receive") switch typ & msgTypeMask { case msgTypeResponse: @@ -412,7 +412,7 @@ func (brdg *bridge) writeMessage(buf *bytes.Buffer, enc *json.Encoder, typ msgTy } brdg.log.WithFields(logrus.Fields{ "payload": string(b), - "type": typ, + "type": typ.String(), "message-id": id}).Debug("bridge send") } diff --git a/internal/gcs/container.go b/internal/gcs/container.go index bf704fb548..84889a8608 100644 --- a/internal/gcs/container.go +++ b/internal/gcs/container.go @@ -33,7 +33,7 @@ var _ cow.Container = &Container{} // CreateContainer creates a container using ID `cid` and `cfg`. The request // will likely not be cancellable even if `ctx` becomes done. func (gc *GuestConnection) CreateContainer(ctx context.Context, cid string, config interface{}) (_ *Container, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::CreateContainer") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::CreateContainer", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", cid)) @@ -92,7 +92,7 @@ func (c *Container) IsOCI() bool { // Close releases associated with the container. func (c *Container) Close() error { c.closeOnce.Do(func() { - _, span := trace.StartSpan(context.Background(), "gcs::Container::Close") + _, span := oc.StartSpan(context.Background(), "gcs::Container::Close") defer span.End() span.AddAttributes(trace.StringAttribute("cid", c.id)) }) @@ -101,7 +101,7 @@ func (c *Container) Close() error { // CreateProcess creates a process in the container. func (c *Container) CreateProcess(ctx context.Context, config interface{}) (_ cow.Process, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::CreateProcess") + ctx, span := oc.StartSpan(ctx, "gcs::Container::CreateProcess", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -116,7 +116,7 @@ func (c *Container) ID() string { // Modify sends a modify request to the container. func (c *Container) Modify(ctx context.Context, config interface{}) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Modify") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Modify", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -131,7 +131,7 @@ func (c *Container) Modify(ctx context.Context, config interface{}) (err error) // Properties returns the requested container properties targeting a V1 schema container. func (c *Container) Properties(ctx context.Context, types ...schema1.PropertyType) (_ *schema1.ContainerProperties, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Properties") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Properties", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -150,7 +150,7 @@ func (c *Container) Properties(ctx context.Context, types ...schema1.PropertyTyp // PropertiesV2 returns the requested container properties targeting a V2 schema container. func (c *Container) PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (_ *hcsschema.Properties, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::PropertiesV2") + ctx, span := oc.StartSpan(ctx, "gcs::Container::PropertiesV2", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -169,7 +169,7 @@ func (c *Container) PropertiesV2(ctx context.Context, types ...hcsschema.Propert // Start starts the container. func (c *Container) Start(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Start") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Start", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -200,7 +200,7 @@ func (c *Container) shutdown(ctx context.Context, proc rpcProc) error { // might not be terminated by the time the request completes (and might never // terminate). func (c *Container) Shutdown(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Shutdown") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Shutdown", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -214,7 +214,7 @@ func (c *Container) Shutdown(ctx context.Context) (err error) { // might not be terminated by the time the request completes (and might never // terminate). func (c *Container) Terminate(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Terminate") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Terminate", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -236,7 +236,7 @@ func (c *Container) Wait() error { } func (c *Container) waitBackground() { - ctx, span := trace.StartSpan(context.Background(), "gcs::Container::waitBackground") + ctx, span := oc.StartSpan(context.Background(), "gcs::Container::waitBackground") defer span.End() span.AddAttributes(trace.StringAttribute("cid", c.id)) diff --git a/internal/gcs/guestconnection.go b/internal/gcs/guestconnection.go index bb28d890ff..a90fba15e9 100644 --- a/internal/gcs/guestconnection.go +++ b/internal/gcs/guestconnection.go @@ -68,7 +68,7 @@ type GuestConnectionConfig struct { // Connect establishes a GCS connection. `gcc.Conn` will be closed by this function. func (gcc *GuestConnectionConfig) Connect(ctx context.Context, isColdStart bool) (_ *GuestConnection, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnectionConfig::Connect") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnectionConfig::Connect", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -167,7 +167,7 @@ func (gc *GuestConnection) connect(ctx context.Context, isColdStart bool, initGu // Modify sends a modify settings request to the null container. This is // generally used to prepare virtual hardware that has been added to the guest. func (gc *GuestConnection) Modify(ctx context.Context, settings interface{}) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::Modify") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::Modify", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -180,7 +180,7 @@ func (gc *GuestConnection) Modify(ctx context.Context, settings interface{}) (er } func (gc *GuestConnection) DumpStacks(ctx context.Context) (response string, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::DumpStacks") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::DumpStacks", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -193,7 +193,7 @@ func (gc *GuestConnection) DumpStacks(ctx context.Context) (response string, err } func (gc *GuestConnection) DeleteContainerState(ctx context.Context, cid string) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::DeleteContainerState") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::DeleteContainerState", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", cid)) @@ -216,7 +216,7 @@ func (gc *GuestConnection) Close() error { // CreateProcess creates a process in the container host. func (gc *GuestConnection) CreateProcess(ctx context.Context, settings interface{}) (_ cow.Process, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::CreateProcess") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::CreateProcess", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/gcs/guestconnection_test.go b/internal/gcs/guestconnection_test.go index f43a30d0bf..6ad9f4d697 100644 --- a/internal/gcs/guestconnection_test.go +++ b/internal/gcs/guestconnection_test.go @@ -20,6 +20,8 @@ import ( "github.com/sirupsen/logrus" "go.opencensus.io/trace" "go.opencensus.io/trace/tracestate" + + "github.com/Microsoft/hcsshim/internal/oc" ) const pipePortFmt = `\\.\pipe\gctest-port-%d` @@ -273,7 +275,7 @@ func Test_makeRequestNoSpan(t *testing.T) { } func Test_makeRequestWithSpan(t *testing.T) { - ctx, span := trace.StartSpan(context.Background(), t.Name()) + ctx, span := oc.StartSpan(context.Background(), t.Name()) defer span.End() r := makeRequest(ctx, t.Name()) diff --git a/internal/gcs/process.go b/internal/gcs/process.go index 60141e9f70..fab6af75c7 100644 --- a/internal/gcs/process.go +++ b/internal/gcs/process.go @@ -124,7 +124,7 @@ func (gc *GuestConnection) exec(ctx context.Context, cid string, params interfac // Close releases resources associated with the process and closes the // associated standard IO streams. func (p *Process) Close() error { - ctx, span := trace.StartSpan(context.Background(), "gcs::Process::Close") + ctx, span := oc.StartSpan(context.Background(), "gcs::Process::Close") defer span.End() span.AddAttributes( trace.StringAttribute("cid", p.cid), @@ -144,7 +144,7 @@ func (p *Process) Close() error { // CloseStdin causes the process to read EOF on its stdin stream. func (p *Process) CloseStdin(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::CloseStdin") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "gcs::Process::CloseStdin") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -158,7 +158,7 @@ func (p *Process) CloseStdin(ctx context.Context) (err error) { } func (p *Process) CloseStdout(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::CloseStdout") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "gcs::Process::CloseStdout") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -169,7 +169,7 @@ func (p *Process) CloseStdout(ctx context.Context) (err error) { } func (p *Process) CloseStderr(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::CloseStderr") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "gcs::Process::CloseStderr") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -195,7 +195,7 @@ func (p *Process) ExitCode() (_ int, err error) { // signal was delivered. The process might not be terminated by the time this // returns. func (p *Process) Kill(ctx context.Context) (_ bool, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::Kill") + ctx, span := oc.StartSpan(ctx, "gcs::Process::Kill") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -213,7 +213,7 @@ func (p *Process) Pid() int { // ResizeConsole requests that the pty associated with the process resize its // window. func (p *Process) ResizeConsole(ctx context.Context, width, height uint16) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::ResizeConsole") + ctx, span := oc.StartSpan(ctx, "gcs::Process::ResizeConsole", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -232,7 +232,7 @@ func (p *Process) ResizeConsole(ctx context.Context, width, height uint16) (err // Signal sends a signal to the process, returning whether it was delivered. func (p *Process) Signal(ctx context.Context, options interface{}) (_ bool, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::Signal") + ctx, span := oc.StartSpan(ctx, "gcs::Process::Signal", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -277,7 +277,7 @@ func (p *Process) Wait() error { } func (p *Process) waitBackground() { - ctx, span := trace.StartSpan(context.Background(), "gcs::Process::waitBackground") + ctx, span := oc.StartSpan(context.Background(), "gcs::Process::waitBackground") defer span.End() span.AddAttributes( trace.StringAttribute("cid", p.cid), diff --git a/internal/guest/bridge/bridge.go b/internal/guest/bridge/bridge.go index 402034f479..5b3f1e2bf4 100644 --- a/internal/guest/bridge/bridge.go +++ b/internal/guest/bridge/bridge.go @@ -17,15 +17,16 @@ import ( "sync/atomic" "time" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "go.opencensus.io/trace" + "go.opencensus.io/trace/tracestate" + "github.com/Microsoft/hcsshim/internal/guest/gcserr" "github.com/Microsoft/hcsshim/internal/guest/prot" "github.com/Microsoft/hcsshim/internal/guest/runtime/hcsv2" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/oc" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "go.opencensus.io/trace" - "go.opencensus.io/trace/tracestate" ) // UnknownMessage represents the default handler logic for an unmatched request @@ -131,7 +132,7 @@ func (mux *Mux) ServeMsg(r *Request) (RequestResponse, error) { type Request struct { // Context is the request context received from the bridge. Context context.Context - // Header is the wire format message header that preceeded the message for + // Header is the wire format message header that preceded the message for // this request. Header *prot.MessageHeader // ContainerID is the id of the container that this message corresponds to. @@ -164,7 +165,7 @@ type bridgeResponse struct { // It has two fundamentally different dispatch options: // // 1. Request/Response where using the `Handler` a request -// of a given type will be dispatched to the apprpriate handler +// of a given type will be dispatched to the appropriate handler // and an appropriate response will respond to exactly that request that // caused the dispatch. // @@ -288,9 +289,18 @@ func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser } } } - ctx, span = trace.StartSpanWithRemoteParent(context.Background(), "opengcs::bridge::request", sc) + ctx, span = oc.StartSpanWithRemoteParent( + context.Background(), + "opengcs::bridge::request", + sc, + oc.WithServerSpanKind, + ) } else { - ctx, span = trace.StartSpan(context.Background(), "opengcs::bridge::request") + ctx, span = oc.StartSpan( + context.Background(), + "opengcs::bridge::request", + oc.WithServerSpanKind, + ) } span.AddAttributes( @@ -410,7 +420,9 @@ func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser // PublishNotification writes a specific notification to the bridge. func (b *Bridge) PublishNotification(n *prot.ContainerNotification) { - ctx, span := trace.StartSpan(context.Background(), "opengcs::bridge::PublishNotification") + ctx, span := oc.StartSpan(context.Background(), + "opengcs::bridge::PublishNotification", + oc.WithClientSpanKind) span.AddAttributes(trace.StringAttribute("notification", fmt.Sprintf("%+v", n))) // DONT defer span.End() here. Publish is odd because bridgeResponse calls // `End` on the `ctx` after the response is sent. diff --git a/internal/guest/bridge/bridge_v2.go b/internal/guest/bridge/bridge_v2.go index 99777ca84a..a81045bb11 100644 --- a/internal/guest/bridge/bridge_v2.go +++ b/internal/guest/bridge/bridge_v2.go @@ -47,7 +47,7 @@ var capabilities = prot.GcsCapabilities{ // negotiateProtocolV2 was introduced in v4 so will not be called with a minimum // lower than that. func (b *Bridge) negotiateProtocolV2(r *Request) (_ RequestResponse, err error) { - _, span := trace.StartSpan(r.Context, "opengcs::bridge::negotiateProtocolV2") + _, span := oc.StartSpan(r.Context, "opengcs::bridge::negotiateProtocolV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -83,7 +83,7 @@ func (b *Bridge) negotiateProtocolV2(r *Request) (_ RequestResponse, err error) // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) createContainerV2(r *Request) (_ RequestResponse, err error) { - ctx, span := trace.StartSpan(r.Context, "opengcs::bridge::createContainerV2") + ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::createContainerV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -136,7 +136,7 @@ func (b *Bridge) createContainerV2(r *Request) (_ RequestResponse, err error) { // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) startContainerV2(r *Request) (_ RequestResponse, err error) { - _, span := trace.StartSpan(r.Context, "opengcs::bridge::startContainerV2") + _, span := oc.StartSpan(r.Context, "opengcs::bridge::startContainerV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -167,7 +167,7 @@ func (b *Bridge) startContainerV2(r *Request) (_ RequestResponse, err error) { // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) execProcessV2(r *Request) (_ RequestResponse, err error) { - ctx, span := trace.StartSpan(r.Context, "opengcs::bridge::execProcessV2") + ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::execProcessV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -223,7 +223,7 @@ func (b *Bridge) execProcessV2(r *Request) (_ RequestResponse, err error) { // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) killContainerV2(r *Request) (RequestResponse, error) { - ctx, span := trace.StartSpan(r.Context, "opengcs::bridge::killContainerV2") + ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::killContainerV2") defer span.End() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -236,7 +236,7 @@ func (b *Bridge) killContainerV2(r *Request) (RequestResponse, error) { // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) shutdownContainerV2(r *Request) (RequestResponse, error) { - ctx, span := trace.StartSpan(r.Context, "opengcs::bridge::shutdownContainerV2") + ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::shutdownContainerV2") defer span.End() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -282,7 +282,7 @@ func (b *Bridge) signalContainerV2(ctx context.Context, span *trace.Span, r *Req } func (b *Bridge) signalProcessV2(r *Request) (_ RequestResponse, err error) { - ctx, span := trace.StartSpan(r.Context, "opengcs::bridge::signalProcessV2") + ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::signalProcessV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -320,7 +320,7 @@ func (b *Bridge) signalProcessV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) getPropertiesV2(r *Request) (_ RequestResponse, err error) { - ctx, span := trace.StartSpan(r.Context, "opengcs::bridge::getPropertiesV2") + ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::getPropertiesV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -383,7 +383,7 @@ func (b *Bridge) getPropertiesV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) waitOnProcessV2(r *Request) (_ RequestResponse, err error) { - _, span := trace.StartSpan(r.Context, "opengcs::bridge::waitOnProcessV2") + _, span := oc.StartSpan(r.Context, "opengcs::bridge::waitOnProcessV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -438,7 +438,7 @@ func (b *Bridge) waitOnProcessV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) resizeConsoleV2(r *Request) (_ RequestResponse, err error) { - ctx, span := trace.StartSpan(r.Context, "opengcs::bridge::resizeConsoleV2") + ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::resizeConsoleV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -472,7 +472,7 @@ func (b *Bridge) resizeConsoleV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) modifySettingsV2(r *Request) (_ RequestResponse, err error) { - ctx, span := trace.StartSpan(r.Context, "opengcs::bridge::modifySettingsV2") + ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::modifySettingsV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) @@ -491,7 +491,7 @@ func (b *Bridge) modifySettingsV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) dumpStacksV2(r *Request) (_ RequestResponse, err error) { - _, span := trace.StartSpan(r.Context, "opengcs::bridge::dumpStacksV2") + _, span := oc.StartSpan(r.Context, "opengcs::bridge::dumpStacksV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -503,7 +503,7 @@ func (b *Bridge) dumpStacksV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) deleteContainerStateV2(r *Request) (_ RequestResponse, err error) { - ctx, span := trace.StartSpan(r.Context, "opengcs::bridge::deleteContainerStateV2") + ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::deleteContainerStateV2") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/guest/network/network.go b/internal/guest/network/network.go index d286952271..318671b99b 100644 --- a/internal/guest/network/network.go +++ b/internal/guest/network/network.go @@ -35,7 +35,7 @@ const maxDNSSearches = 6 // GenerateEtcHostsContent generates a /etc/hosts file based on `hostname`. func GenerateEtcHostsContent(ctx context.Context, hostname string) string { - _, span := trace.StartSpan(ctx, "network::GenerateEtcHostsContent") + _, span := oc.StartSpan(ctx, "network::GenerateEtcHostsContent") defer span.End() span.AddAttributes(trace.StringAttribute("hostname", hostname)) @@ -60,7 +60,7 @@ func GenerateEtcHostsContent(ctx context.Context, hostname string) string { // GenerateResolvConfContent generates the resolv.conf file content based on // `searches`, `servers`, and `options`. func GenerateResolvConfContent(ctx context.Context, searches, servers, options []string) (_ string, err error) { - _, span := trace.StartSpan(ctx, "network::GenerateResolvConfContent") + _, span := oc.StartSpan(ctx, "network::GenerateResolvConfContent") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -116,7 +116,7 @@ func MergeValues(first, second []string) []string { // // Will retry the operation until `ctx` is exceeded or canceled. func InstanceIDToName(ctx context.Context, id string, vpciAssigned bool) (_ string, err error) { - ctx, span := trace.StartSpan(ctx, "network::InstanceIDToName") + ctx, span := oc.StartSpan(ctx, "network::InstanceIDToName") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/guest/runtime/hcsv2/container.go b/internal/guest/runtime/hcsv2/container.go index 415dc613e1..5a921a8fd0 100644 --- a/internal/guest/runtime/hcsv2/container.go +++ b/internal/guest/runtime/hcsv2/container.go @@ -25,6 +25,7 @@ import ( "github.com/Microsoft/hcsshim/internal/guest/transport" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" + "github.com/Microsoft/hcsshim/internal/oc" "github.com/Microsoft/hcsshim/internal/protocol/guestrequest" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" ) @@ -200,7 +201,7 @@ func (c *Container) Update(ctx context.Context, resources interface{}) error { // Wait waits for the container's init process to exit. func (c *Container) Wait() prot.NotificationType { - _, span := trace.StartSpan(context.Background(), "opengcs::Container::Wait") + _, span := oc.StartSpan(context.Background(), "opengcs::Container::Wait") defer span.End() span.AddAttributes(trace.StringAttribute(logfields.ContainerID, c.id)) @@ -225,7 +226,7 @@ func (c *Container) setExitType(signal syscall.Signal) { // GetStats returns the cgroup metrics for the container. func (c *Container) GetStats(ctx context.Context) (*v1.Metrics, error) { - _, span := trace.StartSpan(ctx, "opengcs::Container::GetStats") + _, span := oc.StartSpan(ctx, "opengcs::Container::GetStats") defer span.End() span.AddAttributes(trace.StringAttribute("cid", c.id)) diff --git a/internal/guest/runtime/hcsv2/network.go b/internal/guest/runtime/hcsv2/network.go index 5edc7ff7a1..c639670dec 100644 --- a/internal/guest/runtime/hcsv2/network.go +++ b/internal/guest/runtime/hcsv2/network.go @@ -71,7 +71,7 @@ func GetOrAddNetworkNamespace(id string) *namespace { // RemoveNetworkNamespace removes the in-memory `namespace` found by `id`. func RemoveNetworkNamespace(ctx context.Context, id string) (err error) { - _, span := trace.StartSpan(ctx, "hcsv2::removeNetworkNamespace") + _, span := oc.StartSpan(ctx, "hcsv2::RemoveNetworkNamespace") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -112,7 +112,7 @@ func (n *namespace) ID() string { // assigned adapters into this namespace. The caller MUST call `Sync()` to // complete this operation. func (n *namespace) AssignContainerPid(ctx context.Context, pid int) (err error) { - _, span := trace.StartSpan(ctx, "namespace::AssignContainerPid") + _, span := oc.StartSpan(ctx, "namespace::AssignContainerPid") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -147,7 +147,7 @@ func (n *namespace) Adapters() []*guestresource.LCOWNetworkAdapter { // namespace assigned to `n`. A user must call `Sync()` to complete this // operation. func (n *namespace) AddAdapter(ctx context.Context, adp *guestresource.LCOWNetworkAdapter) (err error) { - ctx, span := trace.StartSpan(ctx, "namespace::AddAdapter") + ctx, span := oc.StartSpan(ctx, "namespace::AddAdapter") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -179,7 +179,7 @@ func (n *namespace) AddAdapter(ctx context.Context, adp *guestresource.LCOWNetwo // RemoveAdapter removes the adapter matching `id` from `n`. If `id` is not // found returns no error. func (n *namespace) RemoveAdapter(ctx context.Context, id string) (err error) { - _, span := trace.StartSpan(ctx, "namespace::RemoveAdapter") + _, span := oc.StartSpan(ctx, "namespace::RemoveAdapter") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -206,7 +206,7 @@ func (n *namespace) RemoveAdapter(ctx context.Context, id string) (err error) { // Sync moves all adapters to the network namespace of `n` if assigned. func (n *namespace) Sync(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "namespace::Sync") + ctx, span := oc.StartSpan(ctx, "namespace::Sync") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("namespace", n.id)) @@ -244,7 +244,7 @@ type nicInNamespace struct { // assignToPid assigns `nin.adapter`, represented by `nin.ifname` to `pid`. func (nin *nicInNamespace) assignToPid(ctx context.Context, pid int) (err error) { - ctx, span := trace.StartSpan(ctx, "nicInNamespace::assignToPid") + ctx, span := oc.StartSpan(ctx, "nicInNamespace::assignToPid") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/internal/guest/runtime/hcsv2/process.go b/internal/guest/runtime/hcsv2/process.go index f39a177ae5..00156a870f 100644 --- a/internal/guest/runtime/hcsv2/process.go +++ b/internal/guest/runtime/hcsv2/process.go @@ -14,6 +14,8 @@ import ( "github.com/Microsoft/hcsshim/internal/guest/runtime" "github.com/Microsoft/hcsshim/internal/guest/stdio" "github.com/Microsoft/hcsshim/internal/log" + "github.com/Microsoft/hcsshim/internal/logfields" + "github.com/Microsoft/hcsshim/internal/oc" oci "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -85,11 +87,11 @@ func newProcess(c *Container, spec *oci.Process, process runtime.Process, pid ui p.exitWg.Add(1) p.writersWg.Add(1) go func() { - ctx, span := trace.StartSpan(context.Background(), "newProcess::waitBackground") + ctx, span := oc.StartSpan(context.Background(), "newProcess::waitBackground") defer span.End() span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.pid))) + trace.StringAttribute(logfields.ContainerID, p.cid), + trace.Int64Attribute(logfields.ProcessID, int64(p.pid))) // Wait for the process to exit exitCode, err := p.process.Wait() @@ -115,7 +117,7 @@ func newProcess(c *Container, spec *oci.Process, process runtime.Process, pid ui } c.processesMutex.Lock() - _, span := trace.StartSpan(context.Background(), "newProcess::waitBackground::waitAllWaiters") + _, span := oc.StartSpan(context.Background(), "newProcess::waitBackground::waitAllWaiters") defer span.End() span.AddAttributes( trace.StringAttribute("cid", p.cid), @@ -163,7 +165,7 @@ func (p *containerProcess) ResizeConsole(ctx context.Context, height, width uint // gather the exit code. The second channel must be signaled from the caller // when the caller has completed its use of this call to Wait. func (p *containerProcess) Wait() (<-chan int, chan<- bool) { - ctx, span := trace.StartSpan(context.Background(), "opengcs::containerProcess::Wait") + ctx, span := oc.StartSpan(context.Background(), "opengcs::containerProcess::Wait") span.AddAttributes( trace.StringAttribute("cid", p.cid), trace.Int64Attribute("pid", int64(p.pid))) @@ -288,7 +290,7 @@ func (ep *externalProcess) ResizeConsole(ctx context.Context, height, width uint } func (ep *externalProcess) Wait() (<-chan int, chan<- bool) { - _, span := trace.StartSpan(context.Background(), "opengcs::externalProcess::Wait") + _, span := oc.StartSpan(context.Background(), "opengcs::externalProcess::Wait") span.AddAttributes(trace.Int64Attribute("pid", int64(ep.cmd.Process.Pid))) exitCodeChan := make(chan int, 1) diff --git a/internal/guest/runtime/hcsv2/sandbox_container.go b/internal/guest/runtime/hcsv2/sandbox_container.go index 45ad286016..4280eeb329 100644 --- a/internal/guest/runtime/hcsv2/sandbox_container.go +++ b/internal/guest/runtime/hcsv2/sandbox_container.go @@ -33,7 +33,7 @@ func getSandboxResolvPath(id string) string { } func setupSandboxContainerSpec(ctx context.Context, id string, spec *oci.Spec) (err error) { - ctx, span := trace.StartSpan(ctx, "hcsv2::setupSandboxContainerSpec") + ctx, span := oc.StartSpan(ctx, "hcsv2::setupSandboxContainerSpec") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", id)) diff --git a/internal/guest/runtime/hcsv2/standalone_container.go b/internal/guest/runtime/hcsv2/standalone_container.go index a3d2bc1ba9..de57b67893 100644 --- a/internal/guest/runtime/hcsv2/standalone_container.go +++ b/internal/guest/runtime/hcsv2/standalone_container.go @@ -37,7 +37,7 @@ func getStandaloneResolvPath(id string) string { } func setupStandaloneContainerSpec(ctx context.Context, id string, spec *oci.Spec) (err error) { - ctx, span := trace.StartSpan(ctx, "hcsv2::setupStandaloneContainerSpec") + ctx, span := oc.StartSpan(ctx, "hcsv2::setupStandaloneContainerSpec") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", id)) diff --git a/internal/guest/runtime/hcsv2/workload_container.go b/internal/guest/runtime/hcsv2/workload_container.go index 45249305a0..35ba49744b 100644 --- a/internal/guest/runtime/hcsv2/workload_container.go +++ b/internal/guest/runtime/hcsv2/workload_container.go @@ -98,7 +98,7 @@ func specHasGPUDevice(spec *oci.Spec) bool { } func setupWorkloadContainerSpec(ctx context.Context, sbid, id string, spec *oci.Spec) (err error) { - ctx, span := trace.StartSpan(ctx, "hcsv2::setupWorkloadContainerSpec") + ctx, span := oc.StartSpan(ctx, "hcsv2::setupWorkloadContainerSpec") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/internal/guest/storage/devicemapper/targets.go b/internal/guest/storage/devicemapper/targets.go index 82650e7562..2235f76c74 100644 --- a/internal/guest/storage/devicemapper/targets.go +++ b/internal/guest/storage/devicemapper/targets.go @@ -18,7 +18,7 @@ import ( // CreateZeroSectorLinearTarget creates dm-linear target for a device at `devPath` and `mappingInfo`, returns // virtual block device path. func CreateZeroSectorLinearTarget(ctx context.Context, devPath, devName string, mappingInfo *guestresource.LCOWVPMemMappingInfo) (_ string, err error) { - _, span := trace.StartSpan(ctx, "devicemapper::CreateZeroSectorLinearTarget") + _, span := oc.StartSpan(ctx, "devicemapper::CreateZeroSectorLinearTarget") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -49,7 +49,7 @@ func CreateZeroSectorLinearTarget(ctx context.Context, devPath, devName string, // size | version hash_dev | hash_offset // target hash_block func CreateVerityTarget(ctx context.Context, devPath, devName string, verityInfo *guestresource.DeviceVerityInfo) (_ string, err error) { - _, span := trace.StartSpan(ctx, "devicemapper::CreateVerityTarget") + _, span := oc.StartSpan(ctx, "devicemapper::CreateVerityTarget") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/guest/storage/mount.go b/internal/guest/storage/mount.go index 4d6d9ec0ba..d81f98a139 100644 --- a/internal/guest/storage/mount.go +++ b/internal/guest/storage/mount.go @@ -11,10 +11,11 @@ import ( "strings" "syscall" - "github.com/Microsoft/hcsshim/internal/oc" "github.com/pkg/errors" "go.opencensus.io/trace" "golang.org/x/sys/unix" + + "github.com/Microsoft/hcsshim/internal/oc" ) const procMountFile = "/proc/mounts" @@ -114,7 +115,7 @@ func MountRShared(path string) error { // UnmountPath unmounts the target path if it exists and is a mount path. If // removeTarget this will remove the previously mounted folder. func UnmountPath(ctx context.Context, target string, removeTarget bool) (err error) { - _, span := trace.StartSpan(ctx, "storage::UnmountPath") + _, span := oc.StartSpan(ctx, "storage::UnmountPath") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/guest/storage/overlay/overlay.go b/internal/guest/storage/overlay/overlay.go index f108dba3b0..329940d89f 100644 --- a/internal/guest/storage/overlay/overlay.go +++ b/internal/guest/storage/overlay/overlay.go @@ -60,7 +60,7 @@ func processErrNoSpace(ctx context.Context, path string, err error) { // MountLayer first enforces the security policy for the container's layer paths // and then calls Mount to mount the layer paths as an overlayfs func MountLayer(ctx context.Context, layerPaths []string, upperdirPath, workdirPath, rootfsPath string, readonly bool, containerId string, securityPolicy securitypolicy.SecurityPolicyEnforcer) (err error) { - _, span := trace.StartSpan(ctx, "overlay::MountLayer") + _, span := oc.StartSpan(ctx, "overlay::MountLayer") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -81,7 +81,7 @@ func MountLayer(ctx context.Context, layerPaths []string, upperdirPath, workdirP // Always creates `target`. On mount failure the created `target` will // be automatically cleaned up. func Mount(ctx context.Context, basePaths []string, upperdirPath, workdirPath, target string, readonly bool) (err error) { - _, span := trace.StartSpan(ctx, "overlay::Mount") + _, span := oc.StartSpan(ctx, "overlay::Mount") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/guest/storage/plan9/plan9.go b/internal/guest/storage/plan9/plan9.go index 28aa080207..2d98a762a6 100644 --- a/internal/guest/storage/plan9/plan9.go +++ b/internal/guest/storage/plan9/plan9.go @@ -30,7 +30,7 @@ var ( // `target` will be created. On mount failure the created `target` will be // automatically cleaned up. func Mount(ctx context.Context, vsock transport.Transport, target, share string, port uint32, readonly bool) (err error) { - _, span := trace.StartSpan(ctx, "plan9::Mount") + _, span := oc.StartSpan(ctx, "plan9::Mount") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/guest/storage/pmem/pmem.go b/internal/guest/storage/pmem/pmem.go index 9063d4b3da..f6ec60d157 100644 --- a/internal/guest/storage/pmem/pmem.go +++ b/internal/guest/storage/pmem/pmem.go @@ -78,7 +78,7 @@ func Mount( verityInfo *guestresource.DeviceVerityInfo, securityPolicy securitypolicy.SecurityPolicyEnforcer, ) (err error) { - mCtx, span := trace.StartSpan(ctx, "pmem::Mount") + mCtx, span := oc.StartSpan(ctx, "pmem::Mount") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -139,7 +139,7 @@ func Unmount( verityInfo *guestresource.DeviceVerityInfo, securityPolicy securitypolicy.SecurityPolicyEnforcer, ) (err error) { - _, span := trace.StartSpan(ctx, "pmem::Unmount") + _, span := oc.StartSpan(ctx, "pmem::Unmount") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/guest/storage/scsi/scsi.go b/internal/guest/storage/scsi/scsi.go index 8484f79ddb..71bdbcc0c4 100644 --- a/internal/guest/storage/scsi/scsi.go +++ b/internal/guest/storage/scsi/scsi.go @@ -100,7 +100,7 @@ func mount( verityInfo *guestresource.DeviceVerityInfo, securityPolicy securitypolicy.SecurityPolicyEnforcer, ) (err error) { - spnCtx, span := trace.StartSpan(ctx, "scsi::Mount") + spnCtx, span := oc.StartSpan(ctx, "scsi::Mount") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -229,7 +229,7 @@ func unmount( verityInfo *guestresource.DeviceVerityInfo, securityPolicy securitypolicy.SecurityPolicyEnforcer, ) (err error) { - ctx, span := trace.StartSpan(ctx, "scsi::Unmount") + ctx, span := oc.StartSpan(ctx, "scsi::Unmount") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -285,7 +285,7 @@ func Unmount( // ControllerLunToName finds the `/dev/sd*` path to the SCSI device on // `controller` index `lun`. func ControllerLunToName(ctx context.Context, controller, lun uint8) (_ string, err error) { - ctx, span := trace.StartSpan(ctx, "scsi::ControllerLunToName") + ctx, span := oc.StartSpan(ctx, "scsi::ControllerLunToName") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -329,7 +329,7 @@ func ControllerLunToName(ctx context.Context, controller, lun uint8) (_ string, // // If the device is not attached returns no error. func unplugDevice(ctx context.Context, controller, lun uint8) (err error) { - _, span := trace.StartSpan(ctx, "scsi::UnplugDevice") + _, span := oc.StartSpan(ctx, "scsi::UnplugDevice") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/hcs/process.go b/internal/hcs/process.go index 4bf3a167a5..c056636e8b 100644 --- a/internal/hcs/process.go +++ b/internal/hcs/process.go @@ -203,7 +203,7 @@ func (process *Process) Kill(ctx context.Context) (bool, error) { // call multiple times. func (process *Process) waitBackground() { operation := "hcs::Process::waitBackground" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() span.AddAttributes( trace.StringAttribute("cid", process.SystemID()), @@ -314,7 +314,7 @@ func (process *Process) ExitCode() (int, error) { // are the responsibility of the caller to close. func (process *Process) StdioLegacy() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadCloser, err error) { operation := "hcs::Process::StdioLegacy" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -400,7 +400,7 @@ func (process *Process) CloseStdin(ctx context.Context) error { } func (process *Process) CloseStdout(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "hcs::Process::CloseStdout") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "hcs::Process::CloseStdout") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -424,7 +424,7 @@ func (process *Process) CloseStdout(ctx context.Context) (err error) { } func (process *Process) CloseStderr(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "hcs::Process::CloseStderr") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "hcs::Process::CloseStderr") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -451,7 +451,7 @@ func (process *Process) CloseStderr(ctx context.Context) (err error) { // or wait on it. func (process *Process) Close() (err error) { operation := "hcs::Process::Close" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/internal/hcs/system.go b/internal/hcs/system.go index ffe2acca97..65f7204c0f 100644 --- a/internal/hcs/system.go +++ b/internal/hcs/system.go @@ -46,7 +46,7 @@ func CreateComputeSystem(ctx context.Context, id string, hcsDocumentInterface in // hcsCreateComputeSystemContext is an async operation. Start the outer span // here to measure the full create time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", id)) @@ -180,7 +180,7 @@ func (computeSystem *System) Start(ctx context.Context) (err error) { // hcsStartComputeSystemContext is an async operation. Start the outer span // here to measure the full start time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -255,7 +255,7 @@ func (computeSystem *System) Terminate(ctx context.Context) error { // safe to call multiple times. func (computeSystem *System) waitBackground() { operation := "hcs::System::waitBackground" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -361,7 +361,7 @@ func (computeSystem *System) Pause(ctx context.Context) (err error) { // hcsPauseComputeSystemContext is an async peration. Start the outer span // here to measure the full pause time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -388,7 +388,7 @@ func (computeSystem *System) Resume(ctx context.Context) (err error) { // hcsResumeComputeSystemContext is an async operation. Start the outer span // here to measure the full restore time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -413,9 +413,9 @@ func (computeSystem *System) Resume(ctx context.Context) (err error) { func (computeSystem *System) Save(ctx context.Context, options interface{}) (err error) { operation := "hcs::System::Save" - // hcsSaveComputeSystemContext is an async peration. Start the outer span + // hcsSaveComputeSystemContext is an async operation. Start the outer span // here to measure the full save time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -529,7 +529,7 @@ func (computeSystem *System) OpenProcess(ctx context.Context, pid int) (*Process // Close cleans up any state associated with the compute system but does not terminate or wait for it. func (computeSystem *System) Close() (err error) { operation := "hcs::System::Close" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) diff --git a/internal/log/context.go b/internal/log/context.go new file mode 100644 index 0000000000..ae4faf4234 --- /dev/null +++ b/internal/log/context.go @@ -0,0 +1,116 @@ +package log + +import ( + "context" + + "github.com/sirupsen/logrus" + "go.opencensus.io/trace" +) + +type entryContextKeyType int + +const _entryContextKey entryContextKeyType = iota + +var ( + // L is the default, blank logging entry. WithField and co. all return a copy + // of the original entry, so this will not leak fields between calls. + // + // Do NOT modify fields directly, as that will corrupt state for all users and + // is not thread safe. + // Instead, use `L.With*` or `L.Dup()`. Or `G(context.Background())`. + L = logrus.NewEntry(logrus.StandardLogger()) + + // G is an alias for GetEntry + G = GetEntry + + // S is an alias for SetEntry + S = SetEntry + + // U is an alias for UpdateContext + U = UpdateContext +) + +// GetEntry returns a `logrus.Entry` stored in the context, if one exists. +// Otherwise, it returns a default entry that points to the current context. +// +// Note: if the a new entry is returned, it will reference the passed in context. +// However, existing contexts may be stored in parent contexts and additionally reference +// earlier contexts. +// Use `UpdateContext` to update the entry and context. +func GetEntry(ctx context.Context) *logrus.Entry { + entry := fromContext(ctx) + + if entry == nil { + entry = L.WithContext(ctx) + } + + return entry +} + +// SetEntry updates the log entry in the context with the provided fields, and +// returns both. It is equivlent to: +// entry := GetEntry(ctx).WithFields(fields) +// ctx = WithContext(ctx, entry) +// +// See WithContext for more information. +func SetEntry(ctx context.Context, fields logrus.Fields) (context.Context, *logrus.Entry) { + e := GetEntry(ctx) + if len(fields) > 0 { + e = e.WithFields(fields) + } + return WithContext(ctx, e) +} + +// UpdateContext extracts the log entry from the context, and, if the entry's +// context points to a parent's of the current context, ands the entry +// to the most recent context. It is equivlent to: +// entry :=GetEntry(ctx) +// ctx = WithContext(ctx, entry) +// +// This allows the entry to reference the most recent context and any new +// values (such as span contexts) added to it. +// +// See WithContext for more information. +func UpdateContext(ctx context.Context) context.Context { + // there is no way to check its ctx (and not one of its parents) that contains `e` + // so, at a slight cost, force add `e` to the context + ctx, _ = WithContext(ctx, GetEntry(ctx)) + return ctx +} + +// WithContext returns a context that contains the provided log entry. +// The entry can be extracted with `GetEntry` (`G`) +// +// The entry in the context is a copy of `entry` (generated by `entry.WithContext`) +func WithContext(ctx context.Context, entry *logrus.Entry) (context.Context, *logrus.Entry) { + // regardless of the order, entry.Context != GetEntry(ctx) + // here, the returned entry will reference the supplied context + entry = entry.WithContext(ctx) + ctx = context.WithValue(ctx, _entryContextKey, entry) + + return ctx, entry +} + +// Copy extracts the tracing Span and logging entry from the src Context, if they +// exist, and adds them to the dst Context. +// +// This is useful to share tracing and logging between contexts, but not the +// cancellation. For example, if the src Context has been cancelled but cleanup +// operations triggered by the cancellation require a non-cancelled context to +// execute. +func Copy(dst context.Context, src context.Context) context.Context { + if s := trace.FromContext(src); s != nil { + dst = trace.NewContext(dst, s) + } + + if e := fromContext(src); e != nil { + dst, _ = WithContext(dst, e) + } + + return dst +} + +func fromContext(ctx context.Context) *logrus.Entry { + e, _ := ctx.Value(_entryContextKey).(*logrus.Entry) + return e +} diff --git a/internal/log/g.go b/internal/log/g.go deleted file mode 100644 index ba6b1a4a53..0000000000 --- a/internal/log/g.go +++ /dev/null @@ -1,23 +0,0 @@ -package log - -import ( - "context" - - "github.com/sirupsen/logrus" - "go.opencensus.io/trace" -) - -// G returns a `logrus.Entry` with the `TraceID, SpanID` from `ctx` if `ctx` -// contains an OpenCensus `trace.Span`. -func G(ctx context.Context) *logrus.Entry { - span := trace.FromContext(ctx) - if span != nil { - sctx := span.SpanContext() - return logrus.WithFields(logrus.Fields{ - "traceID": sctx.TraceID.String(), - "spanID": sctx.SpanID.String(), - // "parentSpanID": TODO: JTERRY75 - Try to convince OC to export this? - }) - } - return logrus.NewEntry(logrus.StandardLogger()) -} diff --git a/internal/log/hook.go b/internal/log/hook.go new file mode 100644 index 0000000000..8f89405923 --- /dev/null +++ b/internal/log/hook.go @@ -0,0 +1,45 @@ +package log + +import ( + "github.com/Microsoft/hcsshim/internal/logfields" + "github.com/sirupsen/logrus" + "go.opencensus.io/trace" +) + +// Hook serves to intercept and format `logrus.Entry`s before they are passed +// to the ETW hook. +// +// The containerd shim discards the (formatted) logrus output, and outputs only via ETW. +// The Linux GCS outputs logrus entries over stdout, which is consumed by the shim and +// then re-output via the ETW hook. +type Hook struct{} + +var _ logrus.Hook = &Hook{} + +func NewHook() *Hook { + return &Hook{} +} + +func (h *Hook) Levels() []logrus.Level { + return logrus.AllLevels +} + +func (h *Hook) Fire(e *logrus.Entry) (err error) { + h.addSpanContext(e) + + return nil +} + +func (h *Hook) addSpanContext(e *logrus.Entry) { + ctx := e.Context + if ctx == nil { + return + } + span := trace.FromContext(ctx) + if span == nil { + return + } + sctx := span.SpanContext() + e.Data[logfields.TraceID] = sctx.TraceID.String() + e.Data[logfields.SpanID] = sctx.SpanID.String() +} diff --git a/internal/oc/span.go b/internal/oc/span.go index fee4765cbc..0e2b7e9bf6 100644 --- a/internal/oc/span.go +++ b/internal/oc/span.go @@ -1,9 +1,14 @@ package oc import ( + "context" + + "github.com/Microsoft/hcsshim/internal/log" "go.opencensus.io/trace" ) +var DefaultSampler = trace.AlwaysSample() + // SetSpanStatus sets `span.SetStatus` to the proper status depending on `err`. If // `err` is `nil` assumes `trace.StatusCodeOk`. func SetSpanStatus(span *trace.Span, err error) { @@ -15,3 +20,29 @@ func SetSpanStatus(span *trace.Span, err error) { } span.SetStatus(status) } + +// StartSpan wraps "go.opencensus.io/trace".StartSpan, but, if the span is sampling, +// adds a log entry to the context that points to the newly created span. +func StartSpan(ctx context.Context, name string, o ...trace.StartOption) (context.Context, *trace.Span) { + ctx, s := trace.StartSpan(ctx, name, o...) + return update(ctx, s) +} + +// StartSpanWithRemoteParent wraps "go.opencensus.io/trace".StartSpanWithRemoteParent. +// +// See StartSpan for more information. +func StartSpanWithRemoteParent(ctx context.Context, name string, parent trace.SpanContext, o ...trace.StartOption) (context.Context, *trace.Span) { + ctx, s := trace.StartSpanWithRemoteParent(ctx, name, parent, o...) + return update(ctx, s) +} + +func update(ctx context.Context, s *trace.Span) (context.Context, *trace.Span) { + if s.IsRecordingEvents() { + ctx = log.UpdateContext(ctx) + } + + return ctx, s +} + +var WithServerSpanKind = trace.WithSpanKind(trace.SpanKindServer) +var WithClientSpanKind = trace.WithSpanKind(trace.SpanKindClient) diff --git a/internal/tools/uvmboot/lcow.go b/internal/tools/uvmboot/lcow.go index 4d029a9d04..48dad03089 100644 --- a/internal/tools/uvmboot/lcow.go +++ b/internal/tools/uvmboot/lcow.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/Microsoft/hcsshim/internal/cmd" + "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/memory" "github.com/Microsoft/hcsshim/internal/uvm" "github.com/containerd/console" @@ -273,7 +274,7 @@ func runLCOW(ctx context.Context, options *uvm.OptionsLCOW, c *cli.Context) erro func execViaGcs(vm *uvm.UtilityVM, c *cli.Context) error { cmd := cmd.Command(vm, "/bin/sh", "-c", c.String(execCommandLineArgName)) - cmd.Log = logrus.NewEntry(logrus.StandardLogger()) + cmd.Log = log.L.Dup() if lcowUseTerminal { cmd.Spec.Terminal = true cmd.Stdin = os.Stdin diff --git a/internal/tools/uvmboot/wcow.go b/internal/tools/uvmboot/wcow.go index 1ed1e4eaf4..b3d73340a8 100644 --- a/internal/tools/uvmboot/wcow.go +++ b/internal/tools/uvmboot/wcow.go @@ -13,9 +13,9 @@ import ( "strings" "github.com/Microsoft/hcsshim/internal/cmd" + "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/uvm" "github.com/containerd/console" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -89,7 +89,7 @@ var wcowCommand = cli.Command{ if wcowCommandLine != "" { cmd := cmd.Command(vm, "cmd.exe", "/c", wcowCommandLine) cmd.Spec.User.Username = `NT AUTHORITY\SYSTEM` - cmd.Log = logrus.NewEntry(logrus.StandardLogger()) + cmd.Log = log.L.Dup() if wcowUseTerminal { cmd.Spec.Terminal = true cmd.Stdin = os.Stdin diff --git a/internal/uvm/create.go b/internal/uvm/create.go index b07a78bdd3..9b36372ef0 100644 --- a/internal/uvm/create.go +++ b/internal/uvm/create.go @@ -243,7 +243,7 @@ func (uvm *UtilityVM) create(ctx context.Context, doc interface{}) error { // Close terminates and releases resources associated with the utility VM. func (uvm *UtilityVM) Close() (err error) { - ctx, span := trace.StartSpan(context.Background(), "uvm::Close") + ctx, span := oc.StartSpan(context.Background(), "uvm::Close") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute(logfields.UVMID, uvm.id)) diff --git a/internal/uvm/create_lcow.go b/internal/uvm/create_lcow.go index 596964a308..3792307ab5 100644 --- a/internal/uvm/create_lcow.go +++ b/internal/uvm/create_lcow.go @@ -707,7 +707,7 @@ func makeLCOWDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_ *hcs // consumes a set of options derived from various defaults and options // expressed as annotations. func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error) { - ctx, span := trace.StartSpan(ctx, "uvm::CreateLCOW") + ctx, span := oc.StartSpan(ctx, "uvm::CreateLCOW") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/uvm/create_wcow.go b/internal/uvm/create_wcow.go index ba11257b56..662fe69149 100644 --- a/internal/uvm/create_wcow.go +++ b/internal/uvm/create_wcow.go @@ -8,11 +8,11 @@ import ( "os" "path/filepath" + "github.com/Microsoft/go-winio" + "github.com/Microsoft/go-winio/pkg/guid" "github.com/pkg/errors" "go.opencensus.io/trace" - "github.com/Microsoft/go-winio" - "github.com/Microsoft/go-winio/pkg/guid" "github.com/Microsoft/hcsshim/internal/gcs" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" "github.com/Microsoft/hcsshim/internal/log" @@ -233,7 +233,7 @@ func prepareConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWCOW, uv // - The scratch is always attached to SCSI 0:0 // func CreateWCOW(ctx context.Context, opts *OptionsWCOW) (_ *UtilityVM, err error) { - ctx, span := trace.StartSpan(ctx, "uvm::CreateWCOW") + ctx, span := oc.StartSpan(ctx, "uvm::CreateWCOW") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/uvm/start.go b/internal/uvm/start.go index 412717aca6..f59259543a 100644 --- a/internal/uvm/start.go +++ b/internal/uvm/start.go @@ -87,7 +87,7 @@ func isDisconnectError(err error) bool { func parseLogrus(vmid string) func(r io.Reader) { return func(r io.Reader) { j := json.NewDecoder(r) - e := logrus.NewEntry(logrus.StandardLogger()) + e := log.L.Dup() fields := e.Data for { for k := range fields { diff --git a/internal/vmcompute/vmcompute.go b/internal/vmcompute/vmcompute.go index ef2e3708b8..3622f3bbee 100644 --- a/internal/vmcompute/vmcompute.go +++ b/internal/vmcompute/vmcompute.go @@ -98,7 +98,7 @@ func execute(ctx gcontext.Context, timeout time.Duration, f func() error) error } func HcsEnumerateComputeSystems(ctx gcontext.Context, query string) (computeSystems, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsEnumerateComputeSystems") + ctx, span := oc.StartSpan(ctx, "HcsEnumerateComputeSystems") defer span.End() defer func() { if result != "" { @@ -125,7 +125,7 @@ func HcsEnumerateComputeSystems(ctx gcontext.Context, query string) (computeSyst } func HcsCreateComputeSystem(ctx gcontext.Context, id string, configuration string, identity syscall.Handle) (computeSystem HcsSystem, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsCreateComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsCreateComputeSystem") defer span.End() defer func() { if result != "" { @@ -150,7 +150,7 @@ func HcsCreateComputeSystem(ctx gcontext.Context, id string, configuration strin } func HcsOpenComputeSystem(ctx gcontext.Context, id string) (computeSystem HcsSystem, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsOpenComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsOpenComputeSystem") defer span.End() defer func() { if result != "" { @@ -170,7 +170,7 @@ func HcsOpenComputeSystem(ctx gcontext.Context, id string) (computeSystem HcsSys } func HcsCloseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem) (hr error) { - ctx, span := trace.StartSpan(ctx, "HcsCloseComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsCloseComputeSystem") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -180,7 +180,7 @@ func HcsCloseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem) (hr er } func HcsStartComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsStartComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsStartComputeSystem") defer span.End() defer func() { if result != "" { @@ -203,7 +203,7 @@ func HcsStartComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, option } func HcsShutdownComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsShutdownComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsShutdownComputeSystem") defer span.End() defer func() { if result != "" { @@ -226,7 +226,7 @@ func HcsShutdownComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, opt } func HcsTerminateComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsTerminateComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsTerminateComputeSystem") defer span.End() defer func() { if result != "" { @@ -249,7 +249,7 @@ func HcsTerminateComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, op } func HcsPauseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsPauseComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsPauseComputeSystem") defer span.End() defer func() { if result != "" { @@ -272,7 +272,7 @@ func HcsPauseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, option } func HcsResumeComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsResumeComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsResumeComputeSystem") defer span.End() defer func() { if result != "" { @@ -295,7 +295,7 @@ func HcsResumeComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, optio } func HcsGetComputeSystemProperties(ctx gcontext.Context, computeSystem HcsSystem, propertyQuery string) (properties, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsGetComputeSystemProperties") + ctx, span := oc.StartSpan(ctx, "HcsGetComputeSystemProperties") defer span.End() defer func() { if result != "" { @@ -322,7 +322,7 @@ func HcsGetComputeSystemProperties(ctx gcontext.Context, computeSystem HcsSystem } func HcsModifyComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, configuration string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsModifyComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsModifyComputeSystem") defer span.End() defer func() { if result != "" { @@ -343,7 +343,7 @@ func HcsModifyComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, confi } func HcsModifyServiceSettings(ctx gcontext.Context, settings string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsModifyServiceSettings") + ctx, span := oc.StartSpan(ctx, "HcsModifyServiceSettings") defer span.End() defer func() { if result != "" { @@ -364,7 +364,7 @@ func HcsModifyServiceSettings(ctx gcontext.Context, settings string) (result str } func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSystem, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsRegisterComputeSystemCallback") + ctx, span := oc.StartSpan(ctx, "HcsRegisterComputeSystemCallback") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -374,7 +374,7 @@ func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSys } func HcsUnregisterComputeSystemCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) { - ctx, span := trace.StartSpan(ctx, "HcsUnregisterComputeSystemCallback") + ctx, span := oc.StartSpan(ctx, "HcsUnregisterComputeSystemCallback") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -384,7 +384,7 @@ func HcsUnregisterComputeSystemCallback(ctx gcontext.Context, callbackHandle Hcs } func HcsCreateProcess(ctx gcontext.Context, computeSystem HcsSystem, processParameters string) (processInformation HcsProcessInformation, process HcsProcess, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsCreateProcess") + ctx, span := oc.StartSpan(ctx, "HcsCreateProcess") defer span.End() defer func() { if result != "" { @@ -410,7 +410,7 @@ func HcsCreateProcess(ctx gcontext.Context, computeSystem HcsSystem, processPara } func HcsOpenProcess(ctx gcontext.Context, computeSystem HcsSystem, pid uint32) (process HcsProcess, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsOpenProcess") + ctx, span := oc.StartSpan(ctx, "HcsOpenProcess") defer span.End() defer func() { if result != "" { @@ -431,7 +431,7 @@ func HcsOpenProcess(ctx gcontext.Context, computeSystem HcsSystem, pid uint32) ( } func HcsCloseProcess(ctx gcontext.Context, process HcsProcess) (hr error) { - ctx, span := trace.StartSpan(ctx, "HcsCloseProcess") + ctx, span := oc.StartSpan(ctx, "HcsCloseProcess") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -441,7 +441,7 @@ func HcsCloseProcess(ctx gcontext.Context, process HcsProcess) (hr error) { } func HcsTerminateProcess(ctx gcontext.Context, process HcsProcess) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsTerminateProcess") + ctx, span := oc.StartSpan(ctx, "HcsTerminateProcess") defer span.End() defer func() { if result != "" { @@ -461,7 +461,7 @@ func HcsTerminateProcess(ctx gcontext.Context, process HcsProcess) (result strin } func HcsSignalProcess(ctx gcontext.Context, process HcsProcess, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsSignalProcess") + ctx, span := oc.StartSpan(ctx, "HcsSignalProcess") defer span.End() defer func() { if result != "" { @@ -482,7 +482,7 @@ func HcsSignalProcess(ctx gcontext.Context, process HcsProcess, options string) } func HcsGetProcessInfo(ctx gcontext.Context, process HcsProcess) (processInformation HcsProcessInformation, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsGetProcessInfo") + ctx, span := oc.StartSpan(ctx, "HcsGetProcessInfo") defer span.End() defer func() { if result != "" { @@ -502,7 +502,7 @@ func HcsGetProcessInfo(ctx gcontext.Context, process HcsProcess) (processInforma } func HcsGetProcessProperties(ctx gcontext.Context, process HcsProcess) (processProperties, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsGetProcessProperties") + ctx, span := oc.StartSpan(ctx, "HcsGetProcessProperties") defer span.End() defer func() { if result != "" { @@ -528,7 +528,7 @@ func HcsGetProcessProperties(ctx gcontext.Context, process HcsProcess) (processP } func HcsModifyProcess(ctx gcontext.Context, process HcsProcess, settings string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsModifyProcess") + ctx, span := oc.StartSpan(ctx, "HcsModifyProcess") defer span.End() defer func() { if result != "" { @@ -549,7 +549,7 @@ func HcsModifyProcess(ctx gcontext.Context, process HcsProcess, settings string) } func HcsGetServiceProperties(ctx gcontext.Context, propertyQuery string) (properties, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsGetServiceProperties") + ctx, span := oc.StartSpan(ctx, "HcsGetServiceProperties") defer span.End() defer func() { if result != "" { @@ -576,7 +576,7 @@ func HcsGetServiceProperties(ctx gcontext.Context, propertyQuery string) (proper } func HcsRegisterProcessCallback(ctx gcontext.Context, process HcsProcess, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsRegisterProcessCallback") + ctx, span := oc.StartSpan(ctx, "HcsRegisterProcessCallback") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -586,7 +586,7 @@ func HcsRegisterProcessCallback(ctx gcontext.Context, process HcsProcess, callba } func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) { - ctx, span := trace.StartSpan(ctx, "HcsUnregisterProcessCallback") + ctx, span := oc.StartSpan(ctx, "HcsUnregisterProcessCallback") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -596,7 +596,7 @@ func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallba } func HcsSaveComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsSaveComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsSaveComputeSystem") defer span.End() defer func() { if result != "" { diff --git a/internal/wclayer/activatelayer.go b/internal/wclayer/activatelayer.go index 98a79ef4c5..e12253c947 100644 --- a/internal/wclayer/activatelayer.go +++ b/internal/wclayer/activatelayer.go @@ -16,7 +16,7 @@ import ( // An activated layer must later be deactivated via DeactivateLayer. func ActivateLayer(ctx context.Context, path string) (err error) { title := "hcsshim::ActivateLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/internal/wclayer/createlayer.go b/internal/wclayer/createlayer.go index 4e81298514..932475723a 100644 --- a/internal/wclayer/createlayer.go +++ b/internal/wclayer/createlayer.go @@ -14,7 +14,7 @@ import ( // the parent layer provided. func CreateLayer(ctx context.Context, path, parent string) (err error) { title := "hcsshim::CreateLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/internal/wclayer/createscratchlayer.go b/internal/wclayer/createscratchlayer.go index 5750d53e91..5c9d5d2507 100644 --- a/internal/wclayer/createscratchlayer.go +++ b/internal/wclayer/createscratchlayer.go @@ -15,7 +15,7 @@ import ( // This requires the full list of paths to all parent layers up to the base func CreateScratchLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) { title := "hcsshim::CreateScratchLayer" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/internal/wclayer/deactivatelayer.go b/internal/wclayer/deactivatelayer.go index 724af6223d..e3bc77cbc8 100644 --- a/internal/wclayer/deactivatelayer.go +++ b/internal/wclayer/deactivatelayer.go @@ -13,7 +13,7 @@ import ( // DeactivateLayer will dismount a layer that was mounted via ActivateLayer. func DeactivateLayer(ctx context.Context, path string) (err error) { title := "hcsshim::DeactivateLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/internal/wclayer/destroylayer.go b/internal/wclayer/destroylayer.go index 20c5afea7f..d0a59efe12 100644 --- a/internal/wclayer/destroylayer.go +++ b/internal/wclayer/destroylayer.go @@ -14,7 +14,7 @@ import ( // path, including that layer's containing folder, if any. func DestroyLayer(ctx context.Context, path string) (err error) { title := "hcsshim::DestroyLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/internal/wclayer/expandscratchsize.go b/internal/wclayer/expandscratchsize.go index 38071322b7..e2ec27ad08 100644 --- a/internal/wclayer/expandscratchsize.go +++ b/internal/wclayer/expandscratchsize.go @@ -18,7 +18,7 @@ import ( // ExpandScratchSize expands the size of a layer to at least size bytes. func ExpandScratchSize(ctx context.Context, path string, size uint64) (err error) { title := "hcsshim::ExpandScratchSize" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/internal/wclayer/exportlayer.go b/internal/wclayer/exportlayer.go index f3b188e69e..08d6afd3b1 100644 --- a/internal/wclayer/exportlayer.go +++ b/internal/wclayer/exportlayer.go @@ -21,7 +21,7 @@ import ( // perform the export. func ExportLayer(ctx context.Context, path string, exportFolderPath string, parentLayerPaths []string) (err error) { title := "hcsshim::ExportLayer" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -57,7 +57,7 @@ type LayerReader interface { // The caller must have taken the SeBackupPrivilege privilege // to call this and any methods on the resulting LayerReader. func NewLayerReader(ctx context.Context, path string, parentLayerPaths []string) (_ LayerReader, err error) { - ctx, span := trace.StartSpan(ctx, "hcsshim::NewLayerReader") + ctx, span := oc.StartSpan(ctx, "hcsshim::NewLayerReader") defer func() { if err != nil { oc.SetSpanStatus(span, err) diff --git a/internal/wclayer/getlayermountpath.go b/internal/wclayer/getlayermountpath.go index 761b5bbd1d..715e06e379 100644 --- a/internal/wclayer/getlayermountpath.go +++ b/internal/wclayer/getlayermountpath.go @@ -18,7 +18,7 @@ import ( // folder path at which the layer is stored. func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) { title := "hcsshim::GetLayerMountPath" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/internal/wclayer/getsharedbaseimages.go b/internal/wclayer/getsharedbaseimages.go index 1da329c7a4..5e400fb209 100644 --- a/internal/wclayer/getsharedbaseimages.go +++ b/internal/wclayer/getsharedbaseimages.go @@ -16,7 +16,7 @@ import ( // of registering them with the graphdriver, graph, and tagstore. func GetSharedBaseImages(ctx context.Context) (_ string, err error) { title := "hcsshim::GetSharedBaseImages" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/internal/wclayer/grantvmaccess.go b/internal/wclayer/grantvmaccess.go index b0da3e71df..20217ed81b 100644 --- a/internal/wclayer/grantvmaccess.go +++ b/internal/wclayer/grantvmaccess.go @@ -13,7 +13,7 @@ import ( // GrantVmAccess adds access to a file for a given VM func GrantVmAccess(ctx context.Context, vmid string, filepath string) (err error) { title := "hcsshim::GrantVmAccess" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/internal/wclayer/importlayer.go b/internal/wclayer/importlayer.go index cd4e470837..b9946c5f4a 100644 --- a/internal/wclayer/importlayer.go +++ b/internal/wclayer/importlayer.go @@ -22,7 +22,7 @@ import ( // be present on the system at the paths provided in parentLayerPaths. func ImportLayer(ctx context.Context, path string, importFolderPath string, parentLayerPaths []string) (err error) { title := "hcsshim::ImportLayer" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -126,7 +126,7 @@ func (r *legacyLayerWriterWrapper) Close() (err error) { // The caller must have taken the SeBackupPrivilege and SeRestorePrivilege privileges // to call this and any methods on the resulting LayerWriter. func NewLayerWriter(ctx context.Context, path string, parentLayerPaths []string) (_ LayerWriter, err error) { - ctx, span := trace.StartSpan(ctx, "hcsshim::NewLayerWriter") + ctx, span := oc.StartSpan(ctx, "hcsshim::NewLayerWriter") defer func() { if err != nil { oc.SetSpanStatus(span, err) diff --git a/internal/wclayer/layerexists.go b/internal/wclayer/layerexists.go index 5ee3379cfb..4d82977ea1 100644 --- a/internal/wclayer/layerexists.go +++ b/internal/wclayer/layerexists.go @@ -14,7 +14,7 @@ import ( // to the system. func LayerExists(ctx context.Context, path string) (_ bool, err error) { title := "hcsshim::LayerExists" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/internal/wclayer/layerid.go b/internal/wclayer/layerid.go index ea459d2d42..d4805f1444 100644 --- a/internal/wclayer/layerid.go +++ b/internal/wclayer/layerid.go @@ -14,7 +14,7 @@ import ( // LayerID returns the layer ID of a layer on disk. func LayerID(ctx context.Context, path string) (_ guid.GUID, err error) { title := "hcsshim::LayerID" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/internal/wclayer/nametoguid.go b/internal/wclayer/nametoguid.go index 30938e3d66..c45fa2750c 100644 --- a/internal/wclayer/nametoguid.go +++ b/internal/wclayer/nametoguid.go @@ -16,7 +16,7 @@ import ( // across all clients. func NameToGuid(ctx context.Context, name string) (_ guid.GUID, err error) { title := "hcsshim::NameToGuid" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("objectName", name)) diff --git a/internal/wclayer/preparelayer.go b/internal/wclayer/preparelayer.go index 2f128ab153..b66e071245 100644 --- a/internal/wclayer/preparelayer.go +++ b/internal/wclayer/preparelayer.go @@ -21,7 +21,7 @@ var prepareLayerLock sync.Mutex // Disabling the filter must be done via UnprepareLayer. func PrepareLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) { title := "hcsshim::PrepareLayer" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/internal/wclayer/processimage.go b/internal/wclayer/processimage.go index aaf55d887b..7c49cbda45 100644 --- a/internal/wclayer/processimage.go +++ b/internal/wclayer/processimage.go @@ -14,7 +14,7 @@ import ( // The files should have been extracted to \Files. func ProcessBaseLayer(ctx context.Context, path string) (err error) { title := "hcsshim::ProcessBaseLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) @@ -30,7 +30,7 @@ func ProcessBaseLayer(ctx context.Context, path string) (err error) { // The files should have been extracted to \Files. func ProcessUtilityVMImage(ctx context.Context, path string) (err error) { title := "hcsshim::ProcessUtilityVMImage" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/internal/wclayer/unpreparelayer.go b/internal/wclayer/unpreparelayer.go index c53a06ea2c..fe20702c18 100644 --- a/internal/wclayer/unpreparelayer.go +++ b/internal/wclayer/unpreparelayer.go @@ -14,7 +14,7 @@ import ( // the given id. func UnprepareLayer(ctx context.Context, path string) (err error) { title := "hcsshim::UnprepareLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/pkg/octtrpc/interceptor.go b/pkg/octtrpc/interceptor.go index 4bbf9484c3..673b29b5a6 100644 --- a/pkg/octtrpc/interceptor.go +++ b/pkg/octtrpc/interceptor.go @@ -10,6 +10,8 @@ import ( "go.opencensus.io/trace/propagation" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + "github.com/Microsoft/hcsshim/internal/oc" ) type options struct { @@ -62,16 +64,18 @@ func setSpanStatus(span *trace.Span, err error) { // creates a new span for outgoing TTRPC calls, and passes the span context as // metadata on the call. func ClientInterceptor(opts ...Option) ttrpc.UnaryClientInterceptor { - o := options{} + o := options{ + sampler: oc.DefaultSampler, + } for _, opt := range opts { opt(&o) } return func(ctx context.Context, req *ttrpc.Request, resp *ttrpc.Response, info *ttrpc.UnaryClientInfo, inv ttrpc.Invoker) (err error) { - ctx, span := trace.StartSpan( + ctx, span := oc.StartSpan( ctx, convertMethodName(info.FullMethod), trace.WithSampler(o.sampler), - trace.WithSpanKind(trace.SpanKindClient)) + oc.WithClientSpanKind) defer span.End() defer setSpanStatus(span, err) @@ -88,7 +92,9 @@ func ClientInterceptor(opts ...Option) ttrpc.UnaryClientInterceptor { // creates a new span for incoming TTRPC calls, and parents the span to the // span context received via metadata, if it exists. func ServerInterceptor(opts ...Option) ttrpc.UnaryServerInterceptor { - o := options{} + o := options{ + sampler: oc.DefaultSampler, + } for _, opt := range opts { opt(&o) } @@ -96,22 +102,12 @@ func ServerInterceptor(opts ...Option) ttrpc.UnaryServerInterceptor { name := convertMethodName(info.FullMethod) var span *trace.Span + opts := []trace.StartOption{trace.WithSampler(o.sampler), oc.WithServerSpanKind} parent, ok := getParentSpanFromContext(ctx) if ok { - ctx, span = trace.StartSpanWithRemoteParent( - ctx, - name, - parent, - trace.WithSpanKind(trace.SpanKindServer), - trace.WithSampler(o.sampler), - ) + ctx, span = oc.StartSpanWithRemoteParent(ctx, name, parent, opts...) } else { - ctx, span = trace.StartSpan( - ctx, - name, - trace.WithSpanKind(trace.SpanKindServer), - trace.WithSampler(o.sampler), - ) + ctx, span = oc.StartSpan(ctx, name, opts...) } defer span.End() defer setSpanStatus(span, err) diff --git a/test/vendor/github.com/Microsoft/hcsshim/computestorage/attach.go b/test/vendor/github.com/Microsoft/hcsshim/computestorage/attach.go index 05b6ea7bd4..54c4b3bc4a 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/computestorage/attach.go +++ b/test/vendor/github.com/Microsoft/hcsshim/computestorage/attach.go @@ -19,8 +19,8 @@ import ( // // `layerData` is the parent read-only layer data. func AttachLayerStorageFilter(ctx context.Context, layerPath string, layerData LayerData) (err error) { - title := "hcsshim.AttachLayerStorageFilter" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::AttachLayerStorageFilter" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/computestorage/destroy.go b/test/vendor/github.com/Microsoft/hcsshim/computestorage/destroy.go index 8dd942bab9..5058d3b55e 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/computestorage/destroy.go +++ b/test/vendor/github.com/Microsoft/hcsshim/computestorage/destroy.go @@ -14,8 +14,8 @@ import ( // // `layerPath` is a path to a directory containing the layer to export. func DestroyLayer(ctx context.Context, layerPath string) (err error) { - title := "hcsshim.DestroyLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::DestroyLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("layerPath", layerPath)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/computestorage/detach.go b/test/vendor/github.com/Microsoft/hcsshim/computestorage/detach.go index 934ee5b1a6..daf1bfff20 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/computestorage/detach.go +++ b/test/vendor/github.com/Microsoft/hcsshim/computestorage/detach.go @@ -14,8 +14,8 @@ import ( // // `layerPath` is a path to a directory containing the layer to export. func DetachLayerStorageFilter(ctx context.Context, layerPath string) (err error) { - title := "hcsshim.DetachLayerStorageFilter" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::DetachLayerStorageFilter" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("layerPath", layerPath)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/computestorage/export.go b/test/vendor/github.com/Microsoft/hcsshim/computestorage/export.go index cf90d9b6c9..c6370a5c9a 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/computestorage/export.go +++ b/test/vendor/github.com/Microsoft/hcsshim/computestorage/export.go @@ -21,8 +21,8 @@ import ( // // `options` are the export options applied to the exported layer. func ExportLayer(ctx context.Context, layerPath, exportFolderPath string, layerData LayerData, options ExportLayerOptions) (err error) { - title := "hcsshim.ExportLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::ExportLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/computestorage/format.go b/test/vendor/github.com/Microsoft/hcsshim/computestorage/format.go index 05e0729f50..4a5735e989 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/computestorage/format.go +++ b/test/vendor/github.com/Microsoft/hcsshim/computestorage/format.go @@ -11,7 +11,6 @@ import ( "github.com/Microsoft/hcsshim/internal/oc" "github.com/Microsoft/hcsshim/osversion" "github.com/pkg/errors" - "go.opencensus.io/trace" "golang.org/x/sys/windows" ) @@ -43,8 +42,8 @@ func openDisk(path string) (windows.Handle, error) { // // If the VHD is not mounted it will be temporarily mounted. func FormatWritableLayerVhd(ctx context.Context, vhdHandle windows.Handle) (err error) { - title := "hcsshim.FormatWritableLayerVhd" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::FormatWritableLayerVhd" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/test/vendor/github.com/Microsoft/hcsshim/computestorage/import.go b/test/vendor/github.com/Microsoft/hcsshim/computestorage/import.go index a40b4037cc..e1c87416a3 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/computestorage/import.go +++ b/test/vendor/github.com/Microsoft/hcsshim/computestorage/import.go @@ -21,8 +21,8 @@ import ( // // `layerData` is the parent layer data. func ImportLayer(ctx context.Context, layerPath, sourceFolderPath string, layerData LayerData) (err error) { - title := "hcsshim.ImportLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::ImportLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/computestorage/initialize.go b/test/vendor/github.com/Microsoft/hcsshim/computestorage/initialize.go index ddd8f318da..d0c6216056 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/computestorage/initialize.go +++ b/test/vendor/github.com/Microsoft/hcsshim/computestorage/initialize.go @@ -18,8 +18,8 @@ import ( // // `layerData` is the parent read-only layer data. func InitializeWritableLayer(ctx context.Context, layerPath string, layerData LayerData) (err error) { - title := "hcsshim.InitializeWritableLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::InitializeWritableLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/computestorage/mount.go b/test/vendor/github.com/Microsoft/hcsshim/computestorage/mount.go index 6e445e766b..4f4d8ebf2f 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/computestorage/mount.go +++ b/test/vendor/github.com/Microsoft/hcsshim/computestorage/mount.go @@ -8,14 +8,13 @@ import ( "github.com/Microsoft/hcsshim/internal/interop" "github.com/Microsoft/hcsshim/internal/oc" "github.com/pkg/errors" - "go.opencensus.io/trace" "golang.org/x/sys/windows" ) // GetLayerVhdMountPath returns the volume path for a virtual disk of a writable container layer. func GetLayerVhdMountPath(ctx context.Context, vhdHandle windows.Handle) (path string, err error) { - title := "hcsshim.GetLayerVhdMountPath" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::GetLayerVhdMountPath" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/test/vendor/github.com/Microsoft/hcsshim/computestorage/setup.go b/test/vendor/github.com/Microsoft/hcsshim/computestorage/setup.go index 4b27b895ad..faec837ca1 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/computestorage/setup.go +++ b/test/vendor/github.com/Microsoft/hcsshim/computestorage/setup.go @@ -23,8 +23,8 @@ import ( // // `options` are the options applied while processing the layer. func SetupBaseOSLayer(ctx context.Context, layerPath string, vhdHandle windows.Handle, options OsLayerOptions) (err error) { - title := "hcsshim.SetupBaseOSLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::SetupBaseOSLayer" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -54,8 +54,8 @@ func SetupBaseOSVolume(ctx context.Context, layerPath, volumePath string, option if osversion.Build() < 19645 { return errors.New("SetupBaseOSVolume is not present on builds older than 19645") } - title := "hcsshim.SetupBaseOSVolume" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + title := "hcsshim::SetupBaseOSVolume" + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport.go b/test/vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport.go index 00af20be31..1b4c240205 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport.go +++ b/test/vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport.go @@ -3,11 +3,12 @@ package hcn import ( - "fmt" "sync" "github.com/pkg/errors" "github.com/sirupsen/logrus" + + "github.com/Microsoft/hcsshim/internal/log" ) var ( @@ -114,9 +115,9 @@ func getSupportedFeatures() (SupportedFeatures, error) { features.NetworkACL = isFeatureSupported(globals.Version, NetworkACLPolicyVersion) features.NestedIpSet = isFeatureSupported(globals.Version, NestedIpSetVersion) - logrus.WithFields(logrus.Fields{ - "version": fmt.Sprintf("%+v", globals.Version), - "supportedFeatures": fmt.Sprintf("%+v", features), + log.L.WithFields(logrus.Fields{ + "version": globals.Version, + "supportedFeatures": features, }).Info("HCN feature check") return features, nil diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/cmd.go b/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/cmd.go index 758eb78880..d7228619eb 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/cmd.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/cmd.go @@ -13,6 +13,7 @@ import ( "github.com/Microsoft/hcsshim/internal/cow" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" + "github.com/Microsoft/hcsshim/internal/log" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" @@ -111,7 +112,7 @@ func Command(host cow.ProcessHost, name string, arg ...string) *Cmd { Spec: &specs.Process{ Args: append([]string{name}, arg...), }, - Log: logrus.NewEntry(logrus.StandardLogger()), + Log: log.L.Dup(), ExitState: &ExitState{}, } if host.OS() == "windows" { @@ -128,6 +129,7 @@ func Command(host cow.ProcessHost, name string, arg ...string) *Cmd { func CommandContext(ctx context.Context, host cow.ProcessHost, name string, arg ...string) *Cmd { cmd := Command(host, name, arg...) cmd.Context = ctx + cmd.Log = log.G(ctx) return cmd } @@ -239,7 +241,14 @@ func (c *Cmd) Start() error { go func() { select { case <-c.Context.Done(): - _, _ = c.Process.Kill(context.TODO()) + // Process.Kill (via Process.Signal) will not send an RPC if the + // provided context in is cancelled (bridge.AsyncRPC will end early) + ctx := c.Context + if ctx == nil { + ctx = context.Background() + } + kctx := log.Copy(context.Background(), ctx) + _, _ = c.Process.Kill(kctx) case <-c.allDoneCh: } }() diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/copyfile/copyfile.go b/test/vendor/github.com/Microsoft/hcsshim/internal/copyfile/copyfile.go index 61aa2dc405..ea3e65b543 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/copyfile/copyfile.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/copyfile/copyfile.go @@ -20,7 +20,7 @@ var ( // CopyFile is a utility for copying a file using CopyFileW win32 API for // performance. func CopyFile(ctx context.Context, srcFile, destFile string, overwrite bool) (err error) { - ctx, span := trace.StartSpan(ctx, "copyfile::CopyFile") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "copyfile::CopyFile") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/bridge.go b/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/bridge.go index 1e3e7c201d..18d293adf5 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/bridge.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/bridge.go @@ -311,7 +311,7 @@ func (brdg *bridge) recvLoop() error { } brdg.log.WithFields(logrus.Fields{ "payload": string(b), - "type": typ, + "type": typ.String(), "message-id": id}).Debug("bridge receive") switch typ & msgTypeMask { case msgTypeResponse: @@ -412,7 +412,7 @@ func (brdg *bridge) writeMessage(buf *bytes.Buffer, enc *json.Encoder, typ msgTy } brdg.log.WithFields(logrus.Fields{ "payload": string(b), - "type": typ, + "type": typ.String(), "message-id": id}).Debug("bridge send") } diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/container.go b/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/container.go index bf704fb548..84889a8608 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/container.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/container.go @@ -33,7 +33,7 @@ var _ cow.Container = &Container{} // CreateContainer creates a container using ID `cid` and `cfg`. The request // will likely not be cancellable even if `ctx` becomes done. func (gc *GuestConnection) CreateContainer(ctx context.Context, cid string, config interface{}) (_ *Container, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::CreateContainer") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::CreateContainer", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", cid)) @@ -92,7 +92,7 @@ func (c *Container) IsOCI() bool { // Close releases associated with the container. func (c *Container) Close() error { c.closeOnce.Do(func() { - _, span := trace.StartSpan(context.Background(), "gcs::Container::Close") + _, span := oc.StartSpan(context.Background(), "gcs::Container::Close") defer span.End() span.AddAttributes(trace.StringAttribute("cid", c.id)) }) @@ -101,7 +101,7 @@ func (c *Container) Close() error { // CreateProcess creates a process in the container. func (c *Container) CreateProcess(ctx context.Context, config interface{}) (_ cow.Process, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::CreateProcess") + ctx, span := oc.StartSpan(ctx, "gcs::Container::CreateProcess", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -116,7 +116,7 @@ func (c *Container) ID() string { // Modify sends a modify request to the container. func (c *Container) Modify(ctx context.Context, config interface{}) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Modify") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Modify", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -131,7 +131,7 @@ func (c *Container) Modify(ctx context.Context, config interface{}) (err error) // Properties returns the requested container properties targeting a V1 schema container. func (c *Container) Properties(ctx context.Context, types ...schema1.PropertyType) (_ *schema1.ContainerProperties, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Properties") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Properties", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -150,7 +150,7 @@ func (c *Container) Properties(ctx context.Context, types ...schema1.PropertyTyp // PropertiesV2 returns the requested container properties targeting a V2 schema container. func (c *Container) PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (_ *hcsschema.Properties, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::PropertiesV2") + ctx, span := oc.StartSpan(ctx, "gcs::Container::PropertiesV2", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -169,7 +169,7 @@ func (c *Container) PropertiesV2(ctx context.Context, types ...hcsschema.Propert // Start starts the container. func (c *Container) Start(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Start") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Start", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -200,7 +200,7 @@ func (c *Container) shutdown(ctx context.Context, proc rpcProc) error { // might not be terminated by the time the request completes (and might never // terminate). func (c *Container) Shutdown(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Shutdown") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Shutdown", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -214,7 +214,7 @@ func (c *Container) Shutdown(ctx context.Context) (err error) { // might not be terminated by the time the request completes (and might never // terminate). func (c *Container) Terminate(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Container::Terminate") + ctx, span := oc.StartSpan(ctx, "gcs::Container::Terminate", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", c.id)) @@ -236,7 +236,7 @@ func (c *Container) Wait() error { } func (c *Container) waitBackground() { - ctx, span := trace.StartSpan(context.Background(), "gcs::Container::waitBackground") + ctx, span := oc.StartSpan(context.Background(), "gcs::Container::waitBackground") defer span.End() span.AddAttributes(trace.StringAttribute("cid", c.id)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/guestconnection.go b/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/guestconnection.go index bb28d890ff..a90fba15e9 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/guestconnection.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/guestconnection.go @@ -68,7 +68,7 @@ type GuestConnectionConfig struct { // Connect establishes a GCS connection. `gcc.Conn` will be closed by this function. func (gcc *GuestConnectionConfig) Connect(ctx context.Context, isColdStart bool) (_ *GuestConnection, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnectionConfig::Connect") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnectionConfig::Connect", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -167,7 +167,7 @@ func (gc *GuestConnection) connect(ctx context.Context, isColdStart bool, initGu // Modify sends a modify settings request to the null container. This is // generally used to prepare virtual hardware that has been added to the guest. func (gc *GuestConnection) Modify(ctx context.Context, settings interface{}) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::Modify") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::Modify", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -180,7 +180,7 @@ func (gc *GuestConnection) Modify(ctx context.Context, settings interface{}) (er } func (gc *GuestConnection) DumpStacks(ctx context.Context) (response string, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::DumpStacks") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::DumpStacks", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() @@ -193,7 +193,7 @@ func (gc *GuestConnection) DumpStacks(ctx context.Context) (response string, err } func (gc *GuestConnection) DeleteContainerState(ctx context.Context, cid string) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::DeleteContainerState") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::DeleteContainerState", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", cid)) @@ -216,7 +216,7 @@ func (gc *GuestConnection) Close() error { // CreateProcess creates a process in the container host. func (gc *GuestConnection) CreateProcess(ctx context.Context, settings interface{}) (_ cow.Process, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::CreateProcess") + ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::CreateProcess", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/process.go b/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/process.go index 60141e9f70..fab6af75c7 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/process.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/gcs/process.go @@ -124,7 +124,7 @@ func (gc *GuestConnection) exec(ctx context.Context, cid string, params interfac // Close releases resources associated with the process and closes the // associated standard IO streams. func (p *Process) Close() error { - ctx, span := trace.StartSpan(context.Background(), "gcs::Process::Close") + ctx, span := oc.StartSpan(context.Background(), "gcs::Process::Close") defer span.End() span.AddAttributes( trace.StringAttribute("cid", p.cid), @@ -144,7 +144,7 @@ func (p *Process) Close() error { // CloseStdin causes the process to read EOF on its stdin stream. func (p *Process) CloseStdin(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::CloseStdin") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "gcs::Process::CloseStdin") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -158,7 +158,7 @@ func (p *Process) CloseStdin(ctx context.Context) (err error) { } func (p *Process) CloseStdout(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::CloseStdout") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "gcs::Process::CloseStdout") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -169,7 +169,7 @@ func (p *Process) CloseStdout(ctx context.Context) (err error) { } func (p *Process) CloseStderr(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::CloseStderr") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "gcs::Process::CloseStderr") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -195,7 +195,7 @@ func (p *Process) ExitCode() (_ int, err error) { // signal was delivered. The process might not be terminated by the time this // returns. func (p *Process) Kill(ctx context.Context) (_ bool, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::Kill") + ctx, span := oc.StartSpan(ctx, "gcs::Process::Kill") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -213,7 +213,7 @@ func (p *Process) Pid() int { // ResizeConsole requests that the pty associated with the process resize its // window. func (p *Process) ResizeConsole(ctx context.Context, width, height uint16) (err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::ResizeConsole") + ctx, span := oc.StartSpan(ctx, "gcs::Process::ResizeConsole", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -232,7 +232,7 @@ func (p *Process) ResizeConsole(ctx context.Context, width, height uint16) (err // Signal sends a signal to the process, returning whether it was delivered. func (p *Process) Signal(ctx context.Context, options interface{}) (_ bool, err error) { - ctx, span := trace.StartSpan(ctx, "gcs::Process::Signal") + ctx, span := oc.StartSpan(ctx, "gcs::Process::Signal", oc.WithClientSpanKind) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -277,7 +277,7 @@ func (p *Process) Wait() error { } func (p *Process) waitBackground() { - ctx, span := trace.StartSpan(context.Background(), "gcs::Process::waitBackground") + ctx, span := oc.StartSpan(context.Background(), "gcs::Process::waitBackground") defer span.End() span.AddAttributes( trace.StringAttribute("cid", p.cid), diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/hcs/process.go b/test/vendor/github.com/Microsoft/hcsshim/internal/hcs/process.go index 4bf3a167a5..c056636e8b 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/hcs/process.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/hcs/process.go @@ -203,7 +203,7 @@ func (process *Process) Kill(ctx context.Context) (bool, error) { // call multiple times. func (process *Process) waitBackground() { operation := "hcs::Process::waitBackground" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() span.AddAttributes( trace.StringAttribute("cid", process.SystemID()), @@ -314,7 +314,7 @@ func (process *Process) ExitCode() (int, error) { // are the responsibility of the caller to close. func (process *Process) StdioLegacy() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadCloser, err error) { operation := "hcs::Process::StdioLegacy" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -400,7 +400,7 @@ func (process *Process) CloseStdin(ctx context.Context) error { } func (process *Process) CloseStdout(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "hcs::Process::CloseStdout") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "hcs::Process::CloseStdout") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -424,7 +424,7 @@ func (process *Process) CloseStdout(ctx context.Context) (err error) { } func (process *Process) CloseStderr(ctx context.Context) (err error) { - ctx, span := trace.StartSpan(ctx, "hcs::Process::CloseStderr") //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, "hcs::Process::CloseStderr") //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -451,7 +451,7 @@ func (process *Process) CloseStderr(ctx context.Context) (err error) { // or wait on it. func (process *Process) Close() (err error) { operation := "hcs::Process::Close" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go b/test/vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go index ffe2acca97..65f7204c0f 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go @@ -46,7 +46,7 @@ func CreateComputeSystem(ctx context.Context, id string, hcsDocumentInterface in // hcsCreateComputeSystemContext is an async operation. Start the outer span // here to measure the full create time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", id)) @@ -180,7 +180,7 @@ func (computeSystem *System) Start(ctx context.Context) (err error) { // hcsStartComputeSystemContext is an async operation. Start the outer span // here to measure the full start time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -255,7 +255,7 @@ func (computeSystem *System) Terminate(ctx context.Context) error { // safe to call multiple times. func (computeSystem *System) waitBackground() { operation := "hcs::System::waitBackground" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -361,7 +361,7 @@ func (computeSystem *System) Pause(ctx context.Context) (err error) { // hcsPauseComputeSystemContext is an async peration. Start the outer span // here to measure the full pause time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -388,7 +388,7 @@ func (computeSystem *System) Resume(ctx context.Context) (err error) { // hcsResumeComputeSystemContext is an async operation. Start the outer span // here to measure the full restore time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -413,9 +413,9 @@ func (computeSystem *System) Resume(ctx context.Context) (err error) { func (computeSystem *System) Save(ctx context.Context, options interface{}) (err error) { operation := "hcs::System::Save" - // hcsSaveComputeSystemContext is an async peration. Start the outer span + // hcsSaveComputeSystemContext is an async operation. Start the outer span // here to measure the full save time. - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := oc.StartSpan(ctx, operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) @@ -529,7 +529,7 @@ func (computeSystem *System) OpenProcess(ctx context.Context, pid int) (*Process // Close cleans up any state associated with the compute system but does not terminate or wait for it. func (computeSystem *System) Close() (err error) { operation := "hcs::System::Close" - ctx, span := trace.StartSpan(context.Background(), operation) + ctx, span := oc.StartSpan(context.Background(), operation) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/log/context.go b/test/vendor/github.com/Microsoft/hcsshim/internal/log/context.go new file mode 100644 index 0000000000..ae4faf4234 --- /dev/null +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/log/context.go @@ -0,0 +1,116 @@ +package log + +import ( + "context" + + "github.com/sirupsen/logrus" + "go.opencensus.io/trace" +) + +type entryContextKeyType int + +const _entryContextKey entryContextKeyType = iota + +var ( + // L is the default, blank logging entry. WithField and co. all return a copy + // of the original entry, so this will not leak fields between calls. + // + // Do NOT modify fields directly, as that will corrupt state for all users and + // is not thread safe. + // Instead, use `L.With*` or `L.Dup()`. Or `G(context.Background())`. + L = logrus.NewEntry(logrus.StandardLogger()) + + // G is an alias for GetEntry + G = GetEntry + + // S is an alias for SetEntry + S = SetEntry + + // U is an alias for UpdateContext + U = UpdateContext +) + +// GetEntry returns a `logrus.Entry` stored in the context, if one exists. +// Otherwise, it returns a default entry that points to the current context. +// +// Note: if the a new entry is returned, it will reference the passed in context. +// However, existing contexts may be stored in parent contexts and additionally reference +// earlier contexts. +// Use `UpdateContext` to update the entry and context. +func GetEntry(ctx context.Context) *logrus.Entry { + entry := fromContext(ctx) + + if entry == nil { + entry = L.WithContext(ctx) + } + + return entry +} + +// SetEntry updates the log entry in the context with the provided fields, and +// returns both. It is equivlent to: +// entry := GetEntry(ctx).WithFields(fields) +// ctx = WithContext(ctx, entry) +// +// See WithContext for more information. +func SetEntry(ctx context.Context, fields logrus.Fields) (context.Context, *logrus.Entry) { + e := GetEntry(ctx) + if len(fields) > 0 { + e = e.WithFields(fields) + } + return WithContext(ctx, e) +} + +// UpdateContext extracts the log entry from the context, and, if the entry's +// context points to a parent's of the current context, ands the entry +// to the most recent context. It is equivlent to: +// entry :=GetEntry(ctx) +// ctx = WithContext(ctx, entry) +// +// This allows the entry to reference the most recent context and any new +// values (such as span contexts) added to it. +// +// See WithContext for more information. +func UpdateContext(ctx context.Context) context.Context { + // there is no way to check its ctx (and not one of its parents) that contains `e` + // so, at a slight cost, force add `e` to the context + ctx, _ = WithContext(ctx, GetEntry(ctx)) + return ctx +} + +// WithContext returns a context that contains the provided log entry. +// The entry can be extracted with `GetEntry` (`G`) +// +// The entry in the context is a copy of `entry` (generated by `entry.WithContext`) +func WithContext(ctx context.Context, entry *logrus.Entry) (context.Context, *logrus.Entry) { + // regardless of the order, entry.Context != GetEntry(ctx) + // here, the returned entry will reference the supplied context + entry = entry.WithContext(ctx) + ctx = context.WithValue(ctx, _entryContextKey, entry) + + return ctx, entry +} + +// Copy extracts the tracing Span and logging entry from the src Context, if they +// exist, and adds them to the dst Context. +// +// This is useful to share tracing and logging between contexts, but not the +// cancellation. For example, if the src Context has been cancelled but cleanup +// operations triggered by the cancellation require a non-cancelled context to +// execute. +func Copy(dst context.Context, src context.Context) context.Context { + if s := trace.FromContext(src); s != nil { + dst = trace.NewContext(dst, s) + } + + if e := fromContext(src); e != nil { + dst, _ = WithContext(dst, e) + } + + return dst +} + +func fromContext(ctx context.Context) *logrus.Entry { + e, _ := ctx.Value(_entryContextKey).(*logrus.Entry) + return e +} diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/log/g.go b/test/vendor/github.com/Microsoft/hcsshim/internal/log/g.go deleted file mode 100644 index ba6b1a4a53..0000000000 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/log/g.go +++ /dev/null @@ -1,23 +0,0 @@ -package log - -import ( - "context" - - "github.com/sirupsen/logrus" - "go.opencensus.io/trace" -) - -// G returns a `logrus.Entry` with the `TraceID, SpanID` from `ctx` if `ctx` -// contains an OpenCensus `trace.Span`. -func G(ctx context.Context) *logrus.Entry { - span := trace.FromContext(ctx) - if span != nil { - sctx := span.SpanContext() - return logrus.WithFields(logrus.Fields{ - "traceID": sctx.TraceID.String(), - "spanID": sctx.SpanID.String(), - // "parentSpanID": TODO: JTERRY75 - Try to convince OC to export this? - }) - } - return logrus.NewEntry(logrus.StandardLogger()) -} diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/log/hook.go b/test/vendor/github.com/Microsoft/hcsshim/internal/log/hook.go new file mode 100644 index 0000000000..8f89405923 --- /dev/null +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/log/hook.go @@ -0,0 +1,45 @@ +package log + +import ( + "github.com/Microsoft/hcsshim/internal/logfields" + "github.com/sirupsen/logrus" + "go.opencensus.io/trace" +) + +// Hook serves to intercept and format `logrus.Entry`s before they are passed +// to the ETW hook. +// +// The containerd shim discards the (formatted) logrus output, and outputs only via ETW. +// The Linux GCS outputs logrus entries over stdout, which is consumed by the shim and +// then re-output via the ETW hook. +type Hook struct{} + +var _ logrus.Hook = &Hook{} + +func NewHook() *Hook { + return &Hook{} +} + +func (h *Hook) Levels() []logrus.Level { + return logrus.AllLevels +} + +func (h *Hook) Fire(e *logrus.Entry) (err error) { + h.addSpanContext(e) + + return nil +} + +func (h *Hook) addSpanContext(e *logrus.Entry) { + ctx := e.Context + if ctx == nil { + return + } + span := trace.FromContext(ctx) + if span == nil { + return + } + sctx := span.SpanContext() + e.Data[logfields.TraceID] = sctx.TraceID.String() + e.Data[logfields.SpanID] = sctx.SpanID.String() +} diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/oc/span.go b/test/vendor/github.com/Microsoft/hcsshim/internal/oc/span.go index fee4765cbc..0e2b7e9bf6 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/oc/span.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/oc/span.go @@ -1,9 +1,14 @@ package oc import ( + "context" + + "github.com/Microsoft/hcsshim/internal/log" "go.opencensus.io/trace" ) +var DefaultSampler = trace.AlwaysSample() + // SetSpanStatus sets `span.SetStatus` to the proper status depending on `err`. If // `err` is `nil` assumes `trace.StatusCodeOk`. func SetSpanStatus(span *trace.Span, err error) { @@ -15,3 +20,29 @@ func SetSpanStatus(span *trace.Span, err error) { } span.SetStatus(status) } + +// StartSpan wraps "go.opencensus.io/trace".StartSpan, but, if the span is sampling, +// adds a log entry to the context that points to the newly created span. +func StartSpan(ctx context.Context, name string, o ...trace.StartOption) (context.Context, *trace.Span) { + ctx, s := trace.StartSpan(ctx, name, o...) + return update(ctx, s) +} + +// StartSpanWithRemoteParent wraps "go.opencensus.io/trace".StartSpanWithRemoteParent. +// +// See StartSpan for more information. +func StartSpanWithRemoteParent(ctx context.Context, name string, parent trace.SpanContext, o ...trace.StartOption) (context.Context, *trace.Span) { + ctx, s := trace.StartSpanWithRemoteParent(ctx, name, parent, o...) + return update(ctx, s) +} + +func update(ctx context.Context, s *trace.Span) (context.Context, *trace.Span) { + if s.IsRecordingEvents() { + ctx = log.UpdateContext(ctx) + } + + return ctx, s +} + +var WithServerSpanKind = trace.WithSpanKind(trace.SpanKindServer) +var WithClientSpanKind = trace.WithSpanKind(trace.SpanKindClient) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create.go b/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create.go index b07a78bdd3..9b36372ef0 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create.go @@ -243,7 +243,7 @@ func (uvm *UtilityVM) create(ctx context.Context, doc interface{}) error { // Close terminates and releases resources associated with the utility VM. func (uvm *UtilityVM) Close() (err error) { - ctx, span := trace.StartSpan(context.Background(), "uvm::Close") + ctx, span := oc.StartSpan(context.Background(), "uvm::Close") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute(logfields.UVMID, uvm.id)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create_lcow.go b/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create_lcow.go index 596964a308..3792307ab5 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create_lcow.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create_lcow.go @@ -707,7 +707,7 @@ func makeLCOWDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_ *hcs // consumes a set of options derived from various defaults and options // expressed as annotations. func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error) { - ctx, span := trace.StartSpan(ctx, "uvm::CreateLCOW") + ctx, span := oc.StartSpan(ctx, "uvm::CreateLCOW") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create_wcow.go b/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create_wcow.go index ba11257b56..662fe69149 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create_wcow.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/create_wcow.go @@ -8,11 +8,11 @@ import ( "os" "path/filepath" + "github.com/Microsoft/go-winio" + "github.com/Microsoft/go-winio/pkg/guid" "github.com/pkg/errors" "go.opencensus.io/trace" - "github.com/Microsoft/go-winio" - "github.com/Microsoft/go-winio/pkg/guid" "github.com/Microsoft/hcsshim/internal/gcs" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" "github.com/Microsoft/hcsshim/internal/log" @@ -233,7 +233,7 @@ func prepareConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWCOW, uv // - The scratch is always attached to SCSI 0:0 // func CreateWCOW(ctx context.Context, opts *OptionsWCOW) (_ *UtilityVM, err error) { - ctx, span := trace.StartSpan(ctx, "uvm::CreateWCOW") + ctx, span := oc.StartSpan(ctx, "uvm::CreateWCOW") defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/start.go b/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/start.go index 412717aca6..f59259543a 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/start.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/uvm/start.go @@ -87,7 +87,7 @@ func isDisconnectError(err error) bool { func parseLogrus(vmid string) func(r io.Reader) { return func(r io.Reader) { j := json.NewDecoder(r) - e := logrus.NewEntry(logrus.StandardLogger()) + e := log.L.Dup() fields := e.Data for { for k := range fields { diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/vmcompute/vmcompute.go b/test/vendor/github.com/Microsoft/hcsshim/internal/vmcompute/vmcompute.go index ef2e3708b8..3622f3bbee 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/vmcompute/vmcompute.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/vmcompute/vmcompute.go @@ -98,7 +98,7 @@ func execute(ctx gcontext.Context, timeout time.Duration, f func() error) error } func HcsEnumerateComputeSystems(ctx gcontext.Context, query string) (computeSystems, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsEnumerateComputeSystems") + ctx, span := oc.StartSpan(ctx, "HcsEnumerateComputeSystems") defer span.End() defer func() { if result != "" { @@ -125,7 +125,7 @@ func HcsEnumerateComputeSystems(ctx gcontext.Context, query string) (computeSyst } func HcsCreateComputeSystem(ctx gcontext.Context, id string, configuration string, identity syscall.Handle) (computeSystem HcsSystem, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsCreateComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsCreateComputeSystem") defer span.End() defer func() { if result != "" { @@ -150,7 +150,7 @@ func HcsCreateComputeSystem(ctx gcontext.Context, id string, configuration strin } func HcsOpenComputeSystem(ctx gcontext.Context, id string) (computeSystem HcsSystem, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsOpenComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsOpenComputeSystem") defer span.End() defer func() { if result != "" { @@ -170,7 +170,7 @@ func HcsOpenComputeSystem(ctx gcontext.Context, id string) (computeSystem HcsSys } func HcsCloseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem) (hr error) { - ctx, span := trace.StartSpan(ctx, "HcsCloseComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsCloseComputeSystem") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -180,7 +180,7 @@ func HcsCloseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem) (hr er } func HcsStartComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsStartComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsStartComputeSystem") defer span.End() defer func() { if result != "" { @@ -203,7 +203,7 @@ func HcsStartComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, option } func HcsShutdownComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsShutdownComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsShutdownComputeSystem") defer span.End() defer func() { if result != "" { @@ -226,7 +226,7 @@ func HcsShutdownComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, opt } func HcsTerminateComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsTerminateComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsTerminateComputeSystem") defer span.End() defer func() { if result != "" { @@ -249,7 +249,7 @@ func HcsTerminateComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, op } func HcsPauseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsPauseComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsPauseComputeSystem") defer span.End() defer func() { if result != "" { @@ -272,7 +272,7 @@ func HcsPauseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, option } func HcsResumeComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsResumeComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsResumeComputeSystem") defer span.End() defer func() { if result != "" { @@ -295,7 +295,7 @@ func HcsResumeComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, optio } func HcsGetComputeSystemProperties(ctx gcontext.Context, computeSystem HcsSystem, propertyQuery string) (properties, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsGetComputeSystemProperties") + ctx, span := oc.StartSpan(ctx, "HcsGetComputeSystemProperties") defer span.End() defer func() { if result != "" { @@ -322,7 +322,7 @@ func HcsGetComputeSystemProperties(ctx gcontext.Context, computeSystem HcsSystem } func HcsModifyComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, configuration string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsModifyComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsModifyComputeSystem") defer span.End() defer func() { if result != "" { @@ -343,7 +343,7 @@ func HcsModifyComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, confi } func HcsModifyServiceSettings(ctx gcontext.Context, settings string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsModifyServiceSettings") + ctx, span := oc.StartSpan(ctx, "HcsModifyServiceSettings") defer span.End() defer func() { if result != "" { @@ -364,7 +364,7 @@ func HcsModifyServiceSettings(ctx gcontext.Context, settings string) (result str } func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSystem, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsRegisterComputeSystemCallback") + ctx, span := oc.StartSpan(ctx, "HcsRegisterComputeSystemCallback") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -374,7 +374,7 @@ func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSys } func HcsUnregisterComputeSystemCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) { - ctx, span := trace.StartSpan(ctx, "HcsUnregisterComputeSystemCallback") + ctx, span := oc.StartSpan(ctx, "HcsUnregisterComputeSystemCallback") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -384,7 +384,7 @@ func HcsUnregisterComputeSystemCallback(ctx gcontext.Context, callbackHandle Hcs } func HcsCreateProcess(ctx gcontext.Context, computeSystem HcsSystem, processParameters string) (processInformation HcsProcessInformation, process HcsProcess, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsCreateProcess") + ctx, span := oc.StartSpan(ctx, "HcsCreateProcess") defer span.End() defer func() { if result != "" { @@ -410,7 +410,7 @@ func HcsCreateProcess(ctx gcontext.Context, computeSystem HcsSystem, processPara } func HcsOpenProcess(ctx gcontext.Context, computeSystem HcsSystem, pid uint32) (process HcsProcess, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsOpenProcess") + ctx, span := oc.StartSpan(ctx, "HcsOpenProcess") defer span.End() defer func() { if result != "" { @@ -431,7 +431,7 @@ func HcsOpenProcess(ctx gcontext.Context, computeSystem HcsSystem, pid uint32) ( } func HcsCloseProcess(ctx gcontext.Context, process HcsProcess) (hr error) { - ctx, span := trace.StartSpan(ctx, "HcsCloseProcess") + ctx, span := oc.StartSpan(ctx, "HcsCloseProcess") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -441,7 +441,7 @@ func HcsCloseProcess(ctx gcontext.Context, process HcsProcess) (hr error) { } func HcsTerminateProcess(ctx gcontext.Context, process HcsProcess) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsTerminateProcess") + ctx, span := oc.StartSpan(ctx, "HcsTerminateProcess") defer span.End() defer func() { if result != "" { @@ -461,7 +461,7 @@ func HcsTerminateProcess(ctx gcontext.Context, process HcsProcess) (result strin } func HcsSignalProcess(ctx gcontext.Context, process HcsProcess, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsSignalProcess") + ctx, span := oc.StartSpan(ctx, "HcsSignalProcess") defer span.End() defer func() { if result != "" { @@ -482,7 +482,7 @@ func HcsSignalProcess(ctx gcontext.Context, process HcsProcess, options string) } func HcsGetProcessInfo(ctx gcontext.Context, process HcsProcess) (processInformation HcsProcessInformation, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsGetProcessInfo") + ctx, span := oc.StartSpan(ctx, "HcsGetProcessInfo") defer span.End() defer func() { if result != "" { @@ -502,7 +502,7 @@ func HcsGetProcessInfo(ctx gcontext.Context, process HcsProcess) (processInforma } func HcsGetProcessProperties(ctx gcontext.Context, process HcsProcess) (processProperties, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsGetProcessProperties") + ctx, span := oc.StartSpan(ctx, "HcsGetProcessProperties") defer span.End() defer func() { if result != "" { @@ -528,7 +528,7 @@ func HcsGetProcessProperties(ctx gcontext.Context, process HcsProcess) (processP } func HcsModifyProcess(ctx gcontext.Context, process HcsProcess, settings string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsModifyProcess") + ctx, span := oc.StartSpan(ctx, "HcsModifyProcess") defer span.End() defer func() { if result != "" { @@ -549,7 +549,7 @@ func HcsModifyProcess(ctx gcontext.Context, process HcsProcess, settings string) } func HcsGetServiceProperties(ctx gcontext.Context, propertyQuery string) (properties, result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsGetServiceProperties") + ctx, span := oc.StartSpan(ctx, "HcsGetServiceProperties") defer span.End() defer func() { if result != "" { @@ -576,7 +576,7 @@ func HcsGetServiceProperties(ctx gcontext.Context, propertyQuery string) (proper } func HcsRegisterProcessCallback(ctx gcontext.Context, process HcsProcess, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsRegisterProcessCallback") + ctx, span := oc.StartSpan(ctx, "HcsRegisterProcessCallback") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -586,7 +586,7 @@ func HcsRegisterProcessCallback(ctx gcontext.Context, process HcsProcess, callba } func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) { - ctx, span := trace.StartSpan(ctx, "HcsUnregisterProcessCallback") + ctx, span := oc.StartSpan(ctx, "HcsUnregisterProcessCallback") defer span.End() defer func() { oc.SetSpanStatus(span, hr) }() @@ -596,7 +596,7 @@ func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallba } func HcsSaveComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := trace.StartSpan(ctx, "HcsSaveComputeSystem") + ctx, span := oc.StartSpan(ctx, "HcsSaveComputeSystem") defer span.End() defer func() { if result != "" { diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/activatelayer.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/activatelayer.go index 98a79ef4c5..e12253c947 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/activatelayer.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/activatelayer.go @@ -16,7 +16,7 @@ import ( // An activated layer must later be deactivated via DeactivateLayer. func ActivateLayer(ctx context.Context, path string) (err error) { title := "hcsshim::ActivateLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/createlayer.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/createlayer.go index 4e81298514..932475723a 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/createlayer.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/createlayer.go @@ -14,7 +14,7 @@ import ( // the parent layer provided. func CreateLayer(ctx context.Context, path, parent string) (err error) { title := "hcsshim::CreateLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/createscratchlayer.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/createscratchlayer.go index 5750d53e91..5c9d5d2507 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/createscratchlayer.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/createscratchlayer.go @@ -15,7 +15,7 @@ import ( // This requires the full list of paths to all parent layers up to the base func CreateScratchLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) { title := "hcsshim::CreateScratchLayer" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/deactivatelayer.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/deactivatelayer.go index 724af6223d..e3bc77cbc8 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/deactivatelayer.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/deactivatelayer.go @@ -13,7 +13,7 @@ import ( // DeactivateLayer will dismount a layer that was mounted via ActivateLayer. func DeactivateLayer(ctx context.Context, path string) (err error) { title := "hcsshim::DeactivateLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/destroylayer.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/destroylayer.go index 20c5afea7f..d0a59efe12 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/destroylayer.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/destroylayer.go @@ -14,7 +14,7 @@ import ( // path, including that layer's containing folder, if any. func DestroyLayer(ctx context.Context, path string) (err error) { title := "hcsshim::DestroyLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/expandscratchsize.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/expandscratchsize.go index 38071322b7..e2ec27ad08 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/expandscratchsize.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/expandscratchsize.go @@ -18,7 +18,7 @@ import ( // ExpandScratchSize expands the size of a layer to at least size bytes. func ExpandScratchSize(ctx context.Context, path string, size uint64) (err error) { title := "hcsshim::ExpandScratchSize" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go index f3b188e69e..08d6afd3b1 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go @@ -21,7 +21,7 @@ import ( // perform the export. func ExportLayer(ctx context.Context, path string, exportFolderPath string, parentLayerPaths []string) (err error) { title := "hcsshim::ExportLayer" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -57,7 +57,7 @@ type LayerReader interface { // The caller must have taken the SeBackupPrivilege privilege // to call this and any methods on the resulting LayerReader. func NewLayerReader(ctx context.Context, path string, parentLayerPaths []string) (_ LayerReader, err error) { - ctx, span := trace.StartSpan(ctx, "hcsshim::NewLayerReader") + ctx, span := oc.StartSpan(ctx, "hcsshim::NewLayerReader") defer func() { if err != nil { oc.SetSpanStatus(span, err) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/getlayermountpath.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/getlayermountpath.go index 761b5bbd1d..715e06e379 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/getlayermountpath.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/getlayermountpath.go @@ -18,7 +18,7 @@ import ( // folder path at which the layer is stored. func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) { title := "hcsshim::GetLayerMountPath" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/getsharedbaseimages.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/getsharedbaseimages.go index 1da329c7a4..5e400fb209 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/getsharedbaseimages.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/getsharedbaseimages.go @@ -16,7 +16,7 @@ import ( // of registering them with the graphdriver, graph, and tagstore. func GetSharedBaseImages(ctx context.Context) (_ string, err error) { title := "hcsshim::GetSharedBaseImages" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/grantvmaccess.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/grantvmaccess.go index b0da3e71df..20217ed81b 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/grantvmaccess.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/grantvmaccess.go @@ -13,7 +13,7 @@ import ( // GrantVmAccess adds access to a file for a given VM func GrantVmAccess(ctx context.Context, vmid string, filepath string) (err error) { title := "hcsshim::GrantVmAccess" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/importlayer.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/importlayer.go index cd4e470837..b9946c5f4a 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/importlayer.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/importlayer.go @@ -22,7 +22,7 @@ import ( // be present on the system at the paths provided in parentLayerPaths. func ImportLayer(ctx context.Context, path string, importFolderPath string, parentLayerPaths []string) (err error) { title := "hcsshim::ImportLayer" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( @@ -126,7 +126,7 @@ func (r *legacyLayerWriterWrapper) Close() (err error) { // The caller must have taken the SeBackupPrivilege and SeRestorePrivilege privileges // to call this and any methods on the resulting LayerWriter. func NewLayerWriter(ctx context.Context, path string, parentLayerPaths []string) (_ LayerWriter, err error) { - ctx, span := trace.StartSpan(ctx, "hcsshim::NewLayerWriter") + ctx, span := oc.StartSpan(ctx, "hcsshim::NewLayerWriter") defer func() { if err != nil { oc.SetSpanStatus(span, err) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/layerexists.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/layerexists.go index 5ee3379cfb..4d82977ea1 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/layerexists.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/layerexists.go @@ -14,7 +14,7 @@ import ( // to the system. func LayerExists(ctx context.Context, path string) (_ bool, err error) { title := "hcsshim::LayerExists" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/layerid.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/layerid.go index ea459d2d42..d4805f1444 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/layerid.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/layerid.go @@ -14,7 +14,7 @@ import ( // LayerID returns the layer ID of a layer on disk. func LayerID(ctx context.Context, path string) (_ guid.GUID, err error) { title := "hcsshim::LayerID" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/nametoguid.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/nametoguid.go index 30938e3d66..c45fa2750c 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/nametoguid.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/nametoguid.go @@ -16,7 +16,7 @@ import ( // across all clients. func NameToGuid(ctx context.Context, name string) (_ guid.GUID, err error) { title := "hcsshim::NameToGuid" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("objectName", name)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/preparelayer.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/preparelayer.go index 2f128ab153..b66e071245 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/preparelayer.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/preparelayer.go @@ -21,7 +21,7 @@ var prepareLayerLock sync.Mutex // Disabling the filter must be done via UnprepareLayer. func PrepareLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) { title := "hcsshim::PrepareLayer" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := oc.StartSpan(ctx, title) defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes( diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/processimage.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/processimage.go index aaf55d887b..7c49cbda45 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/processimage.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/processimage.go @@ -14,7 +14,7 @@ import ( // The files should have been extracted to \Files. func ProcessBaseLayer(ctx context.Context, path string) (err error) { title := "hcsshim::ProcessBaseLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) @@ -30,7 +30,7 @@ func ProcessBaseLayer(ctx context.Context, path string) (err error) { // The files should have been extracted to \Files. func ProcessUtilityVMImage(ctx context.Context, path string) (err error) { title := "hcsshim::ProcessUtilityVMImage" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/unpreparelayer.go b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/unpreparelayer.go index c53a06ea2c..fe20702c18 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/unpreparelayer.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/wclayer/unpreparelayer.go @@ -14,7 +14,7 @@ import ( // the given id. func UnprepareLayer(ctx context.Context, path string) (err error) { title := "hcsshim::UnprepareLayer" - ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() defer func() { oc.SetSpanStatus(span, err) }() span.AddAttributes(trace.StringAttribute("path", path)) diff --git a/test/vendor/github.com/Microsoft/hcsshim/pkg/octtrpc/interceptor.go b/test/vendor/github.com/Microsoft/hcsshim/pkg/octtrpc/interceptor.go index 4bbf9484c3..673b29b5a6 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/pkg/octtrpc/interceptor.go +++ b/test/vendor/github.com/Microsoft/hcsshim/pkg/octtrpc/interceptor.go @@ -10,6 +10,8 @@ import ( "go.opencensus.io/trace/propagation" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + "github.com/Microsoft/hcsshim/internal/oc" ) type options struct { @@ -62,16 +64,18 @@ func setSpanStatus(span *trace.Span, err error) { // creates a new span for outgoing TTRPC calls, and passes the span context as // metadata on the call. func ClientInterceptor(opts ...Option) ttrpc.UnaryClientInterceptor { - o := options{} + o := options{ + sampler: oc.DefaultSampler, + } for _, opt := range opts { opt(&o) } return func(ctx context.Context, req *ttrpc.Request, resp *ttrpc.Response, info *ttrpc.UnaryClientInfo, inv ttrpc.Invoker) (err error) { - ctx, span := trace.StartSpan( + ctx, span := oc.StartSpan( ctx, convertMethodName(info.FullMethod), trace.WithSampler(o.sampler), - trace.WithSpanKind(trace.SpanKindClient)) + oc.WithClientSpanKind) defer span.End() defer setSpanStatus(span, err) @@ -88,7 +92,9 @@ func ClientInterceptor(opts ...Option) ttrpc.UnaryClientInterceptor { // creates a new span for incoming TTRPC calls, and parents the span to the // span context received via metadata, if it exists. func ServerInterceptor(opts ...Option) ttrpc.UnaryServerInterceptor { - o := options{} + o := options{ + sampler: oc.DefaultSampler, + } for _, opt := range opts { opt(&o) } @@ -96,22 +102,12 @@ func ServerInterceptor(opts ...Option) ttrpc.UnaryServerInterceptor { name := convertMethodName(info.FullMethod) var span *trace.Span + opts := []trace.StartOption{trace.WithSampler(o.sampler), oc.WithServerSpanKind} parent, ok := getParentSpanFromContext(ctx) if ok { - ctx, span = trace.StartSpanWithRemoteParent( - ctx, - name, - parent, - trace.WithSpanKind(trace.SpanKindServer), - trace.WithSampler(o.sampler), - ) + ctx, span = oc.StartSpanWithRemoteParent(ctx, name, parent, opts...) } else { - ctx, span = trace.StartSpan( - ctx, - name, - trace.WithSpanKind(trace.SpanKindServer), - trace.WithSampler(o.sampler), - ) + ctx, span = oc.StartSpan(ctx, name, opts...) } defer span.End() defer setSpanStatus(span, err)