libnetwork/diagnostic: print newline after stackdump log path

The response would not have a trailing newline, which made it difficult
to copy the path. While updating, also include the path of the stackdump
in the daemon log that's produced.

Before this:

    root@fa87ff1bcd00:/go/src/github.com/docker/docker# curl -s http://127.0.0.1:123/stackdump
    OK
    goroutine stacks written to /tmp/goroutine-stacks-2025-01-19T160337Z.logroot@fa87ff1bcd00:/go/src/github.com/docker/docker#

After this:

    root@fa87ff1bcd00:/go/src/github.com/docker/docker# curl -s http://127.0.0.1:123/stackdump
    OK
    goroutine stacks written to /tmp/goroutine-stacks-2025-01-19T160922Z.log
    root@fa87ff1bcd00:/go/src/github.com/docker/docker#

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-01-19 17:21:35 +01:00
parent 8cc0e11823
commit 1e6449dfc7

View File

@@ -176,15 +176,16 @@ func stackTrace(w http.ResponseWriter, r *http.Request) {
// audit logs
logger := log.G(context.TODO()).WithFields(log.Fields{"component": "diagnostic", "remoteIP": r.RemoteAddr, "method": caller.Name(0), "url": r.URL.String()})
logger.Info("stack trace")
logger.Info("collecting stack trace")
// FIXME(thaJeztah): make path configurable, or use same location as used by daemon.setupDumpStackTrap
path, err := stack.DumpToFile("/tmp/")
if err != nil {
logger.WithError(err).Error("failed to write goroutines dump")
logger.WithError(err).Error("failed to write stack trace to file")
_, _ = HTTPReply(w, FailCommand(err), jsonOutput)
} else {
logger.Info("stack trace done")
_, _ = HTTPReply(w, CommandSucceed(&StringCmd{Info: "goroutine stacks written to " + path}), jsonOutput)
logger.WithField("file", path).Info("wrote stack trace to file")
_, _ = HTTPReply(w, CommandSucceed(&StringCmd{Info: "goroutine stacks written to " + path + "\n"}), jsonOutput)
}
}