Allow HTTP tracing in push/pull via --trace flag

Signed-off-by: Phil Estes <estesp@amazon.com>
This commit is contained in:
Phil Estes
2021-02-16 21:01:52 -05:00
parent 88d97362b3
commit 51992133af
3 changed files with 37 additions and 0 deletions

View File

@@ -17,7 +17,9 @@
package images
import (
"context"
"fmt"
"net/http/httptrace"
"os"
"sort"
"strings"
@@ -332,3 +334,23 @@ 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")
},
}
}