Merge pull request #5040 from estesp/http-trace
Enable Go HTTP tracing of registry interactions
This commit is contained in:
commit
1dcfe7fa8e
@ -17,7 +17,9 @@
|
|||||||
package images
|
package images
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http/httptrace"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -332,3 +334,23 @@ var removeCommand = cli.Command{
|
|||||||
return exitErr
|
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")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ package images
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http/httptrace"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
@ -54,6 +55,10 @@ command. As part of this process, we do the following:
|
|||||||
Name: "all-platforms",
|
Name: "all-platforms",
|
||||||
Usage: "pull content and metadata from all platforms",
|
Usage: "pull content and metadata from all platforms",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "trace",
|
||||||
|
Usage: "enable HTTP tracing for registry interactions",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "all-metadata",
|
Name: "all-metadata",
|
||||||
Usage: "Pull metadata for all platforms",
|
Usage: "Pull metadata for all platforms",
|
||||||
@ -88,6 +93,9 @@ command. As part of this process, we do the following:
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if context.Bool("trace") {
|
||||||
|
ctx = httptrace.WithClientTrace(ctx, NewDebugClientTrace(ctx))
|
||||||
|
}
|
||||||
img, err := content.Fetch(ctx, client, ref, config)
|
img, err := content.Fetch(ctx, client, ref, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -18,6 +18,7 @@ package images
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
gocontext "context"
|
||||||
|
"net/http/httptrace"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
@ -59,6 +60,9 @@ var pushCommand = cli.Command{
|
|||||||
Name: "manifest-type",
|
Name: "manifest-type",
|
||||||
Usage: "media type of manifest digest",
|
Usage: "media type of manifest digest",
|
||||||
Value: ocispec.MediaTypeImageManifest,
|
Value: ocispec.MediaTypeImageManifest,
|
||||||
|
}, cli.BoolFlag{
|
||||||
|
Name: "trace",
|
||||||
|
Usage: "enable HTTP tracing for registry interactions",
|
||||||
}, cli.StringSliceFlag{
|
}, cli.StringSliceFlag{
|
||||||
Name: "platform",
|
Name: "platform",
|
||||||
Usage: "push content from a specific platform",
|
Usage: "push content from a specific platform",
|
||||||
@ -119,6 +123,9 @@ var pushCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if context.Bool("trace") {
|
||||||
|
ctx = httptrace.WithClientTrace(ctx, NewDebugClientTrace(ctx))
|
||||||
|
}
|
||||||
resolver, err := commands.GetResolver(ctx, context)
|
resolver, err := commands.GetResolver(ctx, context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user