Skip to content

Commit

Permalink
switch to oc.StartSpan to update log context
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
  • Loading branch information
helsaawy committed Apr 29, 2022
1 parent e099f32 commit c967588
Show file tree
Hide file tree
Showing 110 changed files with 396 additions and 355 deletions.
3 changes: 1 addition & 2 deletions cmd/containerd-shim-runhcs-v1/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }()

Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 6 additions & 3 deletions cmd/containerd-shim-runhcs-v1/exec_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,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()
Expand Down
44 changes: 22 additions & 22 deletions cmd/containerd-shim-runhcs-v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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) }()

Expand All @@ -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 {
Expand All @@ -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) }()

Expand All @@ -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 {
Expand All @@ -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) }()

Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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))

Expand Down
5 changes: 3 additions & 2 deletions cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))

Expand All @@ -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))

Expand Down
Loading

0 comments on commit c967588

Please sign in to comment.