Support HTTP debug in ctr

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko
2021-03-22 09:32:34 -07:00
parent 4e919ffaba
commit 22ef69d77d
7 changed files with 104 additions and 37 deletions

View File

@@ -17,9 +17,7 @@
package images
import (
"context"
"fmt"
"net/http/httptrace"
"os"
"sort"
"strings"
@@ -334,23 +332,3 @@ var removeCommand = cli.Command{
return exitErr
},
}
// NewDebugClientTrace returns a Go http trace client predefined to write DNS and connection
// information to the log. This is used via the --trace flag on push and pull operations in ctr.
func NewDebugClientTrace(ctx context.Context) *httptrace.ClientTrace {
return &httptrace.ClientTrace{
DNSStart: func(dnsInfo httptrace.DNSStartInfo) {
log.G(ctx).WithField("host", dnsInfo.Host).Debugf("DNS lookup")
},
DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
if dnsInfo.Err != nil {
log.G(ctx).WithField("lookup_err", dnsInfo.Err).Debugf("DNS lookup error")
} else {
log.G(ctx).WithField("result", dnsInfo.Addrs[0].String()).WithField("coalesced", dnsInfo.Coalesced).Debugf("DNS lookup complete")
}
},
GotConn: func(connInfo httptrace.GotConnInfo) {
log.G(ctx).WithField("reused", connInfo.Reused).WithField("remote_addr", connInfo.Conn.RemoteAddr().String()).Debugf("Connection successful")
},
}
}

View File

@@ -18,7 +18,6 @@ package images
import (
"fmt"
"net/http/httptrace"
"time"
"github.com/containerd/containerd"
@@ -56,10 +55,6 @@ command. As part of this process, we do the following:
Name: "all-platforms",
Usage: "pull content and metadata from all platforms",
},
cli.BoolFlag{
Name: "trace",
Usage: "enable HTTP tracing for registry interactions",
},
cli.BoolFlag{
Name: "all-metadata",
Usage: "Pull metadata for all platforms",
@@ -94,9 +89,6 @@ command. As part of this process, we do the following:
return err
}
if context.Bool("trace") {
ctx = httptrace.WithClientTrace(ctx, NewDebugClientTrace(ctx))
}
img, err := content.Fetch(ctx, client, ref, config)
if err != nil {
return err

View File

@@ -60,9 +60,6 @@ var pushCommand = cli.Command{
Name: "manifest-type",
Usage: "media type of manifest digest",
Value: ocispec.MediaTypeImageManifest,
}, cli.BoolFlag{
Name: "trace",
Usage: "enable HTTP tracing for registry interactions",
}, cli.StringSliceFlag{
Name: "platform",
Usage: "push content from a specific platform",
@@ -123,8 +120,8 @@ var pushCommand = cli.Command{
}
}
if context.Bool("trace") {
ctx = httptrace.WithClientTrace(ctx, NewDebugClientTrace(ctx))
if context.Bool("http-trace") {
ctx = httptrace.WithClientTrace(ctx, commands.NewDebugClientTrace(ctx))
}
resolver, err := commands.GetResolver(ctx, context)
if err != nil {