Skip to content

Commit

Permalink
Add support to dump stacks for ncproxy when requested
Browse files Browse the repository at this point in the history
Signed-off-by: Kathryn Baldauf <[email protected]>
  • Loading branch information
katiewasnothere committed Jul 13, 2021
1 parent e36a7ab commit 43b43e5
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 147 deletions.
13 changes: 3 additions & 10 deletions cmd/containerd-shim-runhcs-v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"context"
"os"
"runtime"
"runtime/debug"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -432,15 +432,8 @@ func (s *service) DiagStacks(ctx context.Context, req *shimdiag.StacksRequest) (
span.AddAttributes(trace.StringAttribute("pod-id", s.tid))
}

buf := make([]byte, 4096)
for {
buf = buf[:runtime.Stack(buf, true)]
if len(buf) < cap(buf) {
break
}
buf = make([]byte, 2*len(buf))
}
resp := &shimdiag.StacksResponse{Stacks: string(buf)}
stacks := debug.Stack()
resp := &shimdiag.StacksResponse{Stacks: string(stacks)}

t, _ := s.getTask(s.tid)
if t != nil {
Expand Down
18 changes: 16 additions & 2 deletions cmd/ncproxy/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime/debug"
"syscall"
"time"

"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/cmd/ncproxy/nodenetsvc"
"github.com/Microsoft/hcsshim/internal/computeagent"
"github.com/Microsoft/hcsshim/internal/log"
Expand Down Expand Up @@ -45,14 +48,25 @@ var (
runSvc = flag.Bool("run-service", false, "Run ncproxy as a Windows service.")
)

func etwCallback(sourceID guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) {
if state == etw.ProviderStateCaptureState {
stacks := debug.Stack()
logrus.WithField("stack", string(stacks)).Info("ncproxy goroutine stack dump")
}
}

// Run ncproxy
func run() error {
flag.Parse()

// Provider ID: cf9f01fe-87b3-568d-ecef-9f54b7c5ff70
// Hook isn't closed explicitly, as it will exist until process exit.
if hook, err := etwlogrus.NewHook("Microsoft.Virtualization.NCProxy"); err == nil {
logrus.AddHook(hook)
if provider, err := etw.NewProvider("Microsoft.Virtualization.NCProxy", etwCallback); err == nil {
if hook, err := etwlogrus.NewHookFromProvider(provider); err == nil {
logrus.AddHook(hook)
} else {
logrus.Error(err)
}
} else {
logrus.Error(err)
}
Expand Down
15 changes: 0 additions & 15 deletions internal/debug/dumpstacks.go

This file was deleted.

6 changes: 3 additions & 3 deletions internal/guest/bridge/bridge_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package bridge
import (
"context"
"encoding/json"
"runtime/debug"
"syscall"
"time"

"github.com/Microsoft/hcsshim/internal/debug"
"github.com/Microsoft/hcsshim/internal/guest/commonutils"
"github.com/Microsoft/hcsshim/internal/guest/gcserr"
"github.com/Microsoft/hcsshim/internal/guest/prot"
Expand Down Expand Up @@ -492,10 +492,10 @@ func (b *Bridge) dumpStacksV2(r *Request) (_ RequestResponse, err error) {
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()

stacks := debug.DumpStacks()
stacks := debug.Stack()

return &prot.DumpStacksResponse{
GuestStacks: stacks,
GuestStacks: string(stacks),
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/Microsoft/go-winio v0.4.17
github.com/Microsoft/hcsshim v0.8.16
github.com/containerd/containerd v1.5.1
github.com/containerd/containerd v1.5.2
github.com/containerd/go-runc v1.0.0
github.com/containerd/ttrpc v1.0.2
github.com/containerd/typeurl v1.0.2
Expand Down
2 changes: 2 additions & 0 deletions test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ github.com/containerd/containerd v1.5.0-beta.3/go.mod h1:/wr9AVtEM7x9c+n0+stptlo
github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoTJseu1FGOKuoA4nNb2s=
github.com/containerd/containerd v1.5.1 h1:xWHPAoe6VkUiI9GAvndJM7s/0MTrmwX3AQiYTr3olf0=
github.com/containerd/containerd v1.5.1/go.mod h1:0DOxVqwDy2iZvrZp2JUx/E+hS0UNTVn7dJnIOwtYR4g=
github.com/containerd/containerd v1.5.2 h1:MG/Bg1pbmMb61j3wHCFWPxESXHieiKr2xG64px/k8zQ=
github.com/containerd/containerd v1.5.2/go.mod h1:0DOxVqwDy2iZvrZp2JUx/E+hS0UNTVn7dJnIOwtYR4g=
github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20191127005431-f65d91d395eb/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20200710164510-efbc4488d8fe/go.mod h1:cECdGN1O8G9bgKTlLhuPJimka6Xb/Gg7vYzCTNVxhvo=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 43b43e5

Please sign in to comment.