Skip to content

Commit

Permalink
resolve comments & add doc
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah committed Oct 13, 2023
1 parent 73b339f commit 9ab60bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions internal/trace/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"sync/atomic"
)

var count uint64
// requestCount records the number of logged request-response pairs and will
// be used as the unique id for the next pair.
var requestCount uint64

// Transport is an http.RoundTripper that keeps track of the in-flight
// request and add hooks to report HTTP tracing events.
Expand All @@ -39,13 +41,13 @@ func NewTransport(base http.RoundTripper) *Transport {

// RoundTrip calls base roundtrip while keeping track of the current request.
func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
number := atomic.AddUint64(&count, 1) - 1
id := atomic.AddUint64(&requestCount, 1) - 1
ctx := req.Context()
e := Logger(ctx)

// log the request
e.Debugf("Request #%d\n> Request URL: %q\n> Request method: %q\n> Request headers:\n%s",
number, req.URL, req.Method, logHeader(req.Header))
id, req.URL, req.Method, logHeader(req.Header))

// log the response
resp, err = t.RoundTripper.RoundTrip(req)
Expand All @@ -55,7 +57,7 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error
e.Errorf("No response obtained for request %s %q", req.Method, req.URL)
} else {
e.Debugf("Response #%d\n< Response Status: %q\n< Response headers:\n%s",
number, resp.Status, logHeader(resp.Header))
id, resp.Status, logHeader(resp.Header))
}
return resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite/command/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var _ = Describe("1.1 registry users:", func() {
CompareRef(src, dst)
})

It("should copy and show debug logs with duplication", func() {
It("should copy and show logs with deduplicated id", func() {
src := RegistryRef(ZOTHost, ArtifactRepo, blob.Tag)
dst := RegistryRef(ZOTHost, cpTestRepo("debug-log"), "copied")
session := ORAS("cp", src, dst, "-d").Exec()
Expand Down

0 comments on commit 9ab60bb

Please sign in to comment.