Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: dump goroutine in e2e #980

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/daemon/peer/peertask_conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ loop:
}

// update content length
if piecePacket.ContentLength > 0 {
if piecePacket.ContentLength > -1 {
pt.SetContentLength(piecePacket.ContentLength)
_ = pt.UpdateStorage(false)
pt.Debugf("update content length: %d", pt.GetContentLength())
Expand Down Expand Up @@ -731,7 +731,7 @@ loop:

func (pt *peerTaskConductor) init(piecePacket *base.PiecePacket, pieceBufferSize uint32) (chan *DownloadPieceRequest, bool) {
pt.contentLength.Store(piecePacket.ContentLength)
if piecePacket.ContentLength > 0 {
if piecePacket.ContentLength > -1 {
pt.span.SetAttributes(config.AttributeTaskContentLength.Int64(piecePacket.ContentLength))
}
if err := pt.InitStorage(); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion client/daemon/peer/peertask_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ func (ptm *peerTaskManager) getOrCreatePeerTaskConductor(ctx context.Context, ta
// double check
if p, ok := ptm.findPeerTaskConductor(taskID); ok {
ptm.conductorLock.Unlock()
logger.Debugf("same peer task found: %s/%s, cancel created peer task %s/%s",
p.taskID, p.peerID, ptc.taskID, ptc.peerID)
// cancel duplicate peer task
ptc.cancel(base.Code_ClientContextCanceled, reasonContextCanceled)
return p, nil
Expand Down Expand Up @@ -231,7 +233,7 @@ func (ptm *peerTaskManager) Stop(ctx context.Context) error {
}

func (ptm *peerTaskManager) PeerTaskDone(taskID string) {
logger.Debugf("delete task %s in running tasks", taskID)
logger.Debugf("delete done task %s in running tasks", taskID)
ptm.runningPeerTasks.Delete(taskID)
}

Expand Down
7 changes: 6 additions & 1 deletion client/daemon/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,12 @@ func (proxy *Proxy) handleHTTP(span trace.Span, w http.ResponseWriter, req *http
w.WriteHeader(resp.StatusCode)
span.SetAttributes(semconv.HTTPStatusCodeKey.Int(resp.StatusCode))
if n, err := io.Copy(w, resp.Body); err != nil && err != io.EOF {
logger.Errorf("failed to write http body: %v", err)
if peerID := resp.Header.Get(config.HeaderDragonflyPeer); peerID != "" {
logger.Errorf("failed to write http body: %v, peer: %s, task: %s",
err, peerID, resp.Header.Get(config.HeaderDragonflyTask))
} else {
logger.Errorf("failed to write http body: %v", err)
}
span.RecordError(err)
} else {
span.SetAttributes(semconv.HTTPResponseContentLengthKey.Int64(n))
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type server struct {
namespace string
logDirName string
replicas int
pprofPort int
}

var servers = map[string]server{
Expand All @@ -66,11 +67,13 @@ var servers = map[string]server{
namespace: dragonflyNamespace,
logDirName: "daemon",
replicas: 1,
pprofPort: 9999,
},
proxyServerName: {
name: proxyServerName,
namespace: dragonflyE2ENamespace,
logDirName: "daemon",
replicas: 3,
pprofPort: 9999,
},
}
1 change: 1 addition & 0 deletions test/e2e/dfget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func singleDfgetTest(name, ns, label, podNamePrefix, container string) {
}

for url, path := range urls {
fmt.Printf("--------------------------------------------------------------------------------\n\n")
fmt.Println("download url: " + url)
// get original file digest
out, err = e2eutil.DockerCommand("sha256sum", path).CombinedOutput()
Expand Down
9 changes: 8 additions & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ = AfterSuite(func() {
out, err = pod.Command("sh", "-c", fmt.Sprintf(`
set -x
cp -r /var/log/dragonfly/%s /tmp/artifact/%s-%d
find /tmp/artifact -type d -exec chmod 777 {} \;
find /tmp/artifact -type d -exec chmod 777 {} \;
`, server.logDirName, server.name, i)).CombinedOutput()
if err != nil {
fmt.Printf("copy log output: %s, error: %s\n", string(out), err)
Expand All @@ -75,6 +75,13 @@ var _ = AfterSuite(func() {
fmt.Printf("upload pod %s artifact prev stdout file error: %v\n", podName, err)
}

if server.pprofPort > 0 {
if out, err := e2eutil.UploadArtifactPProf(server.namespace, podName,
fmt.Sprintf("%s-%d", server.name, i), server.name, server.pprofPort); err != nil {
fmt.Printf("upload pod %s artifact pprof error: %v, output: %s\n", podName, err, out)
}
}

}
}
})
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/e2eutil/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ func UploadArtifactPrevStdout(namespace, podName, logDirName, logPrefix string)

return nil
}

func UploadArtifactPProf(namespace, podName, logDirName, logPrefix string, pprofPort int) (string, error) {
logDirname := fmt.Sprintf("/tmp/artifact/%s/", logDirName)
out, err := KubeCtlCommand("-n", namespace, "exec", podName, "--", "sh", "-c", fmt.Sprintf(`
set -x
port=%d
dir=%s
prefix=%s
ip=$(hostname -i)
wget $ip:$port/debug/pprof/"goroutine?debug=1" -O $dir/$prefix-pprof-goroutine-1.log
wget $ip:$port/debug/pprof/"goroutine?debug=2" -O $dir/$prefix-pprof-goroutine-2.log
`, pprofPort, logDirname, logPrefix)).CombinedOutput()
return string(out), err
}
2 changes: 2 additions & 0 deletions test/testdata/charts/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dfdaemon:
hostPath:
path: /tmp/artifact
config:
verbose: true
pprofPort: 9999
scheduler:
disableAutoBackSource: true
proxy:
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/k8s/proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ data:
dfget.yaml: |-
aliveTime: 0s
gcInterval: 1m0s
keepStorage: false
keepStorage: true
verbose: true
pprof-port: 0
pprof-port: 9999
scheduler:
manager:
enable: true
Expand Down