diff options
author | John Cai <jcai@gitlab.com> | 2019-07-25 00:30:51 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-07-25 00:30:51 +0300 |
commit | 1cb2541eecc6d32e4816d0f817db7e42e0c69f50 (patch) | |
tree | f290e3094eb9cc5a4dfaf5579edc0fadece1dbb8 | |
parent | f24118a6eb0e46aa6e0fe90cc7114307f020f5e8 (diff) | |
parent | 7513eb98d12d5b7fff673a5d0760182ff78668e0 (diff) |
Merge branch 'jv-http-progress' into 'master'
Show server progress in gitaly-debug clone analyzers
See merge request gitlab-org/gitaly!1368
-rw-r--r-- | cmd/gitaly-debug/analyzehttp.go | 7 | ||||
-rw-r--r-- | cmd/gitaly-debug/simulatehttp.go | 25 |
2 files changed, 27 insertions, 5 deletions
diff --git a/cmd/gitaly-debug/analyzehttp.go b/cmd/gitaly-debug/analyzehttp.go index c645b7ef3..5f2fff6ff 100644 --- a/cmd/gitaly-debug/analyzehttp.go +++ b/cmd/gitaly-debug/analyzehttp.go @@ -5,6 +5,7 @@ import ( "compress/gzip" "fmt" "net/http" + "os" "strings" "time" @@ -191,6 +192,12 @@ func doBenchPost(cloneURL string, wants []string) { sideBandHistogram[band]++ + // Print progress data as-is + if band == 2 { + _, err := os.Stdout.Write(data[1:]) + noError(err) + } + n := len(data[1:]) totalSize[band] += int64(n) payloadSizeHistogram[n]++ diff --git a/cmd/gitaly-debug/simulatehttp.go b/cmd/gitaly-debug/simulatehttp.go index 31b3766fc..c87b4f5ee 100644 --- a/cmd/gitaly-debug/simulatehttp.go +++ b/cmd/gitaly-debug/simulatehttp.go @@ -4,12 +4,12 @@ import ( "bufio" "bytes" "fmt" - "io" - "io/ioutil" "os" "os/exec" "regexp" "time" + + "gitlab.com/gitlab-org/gitaly/internal/git/pktline" ) func simulateHTTPClone(gitDir string) { @@ -38,7 +38,7 @@ func simulateHTTPClone(gitDir string) { } request := &bytes.Buffer{} - refsHeads := regexp.MustCompile(`^[a-f0-9]{44} refs/heads/`) + refsHeads := regexp.MustCompile(`^[a-f0-9]{44} refs/(heads|tags)/`) firstLine := true for _, line := range infoLines { if !refsHeads.MatchString(line) { @@ -66,8 +66,23 @@ func simulateHTTPClone(gitDir string) { start = time.Now() noError(uploadPack.Start()) - n, err := io.Copy(ioutil.Discard, out) - noError(err) + var n int64 + scanner := pktline.NewScanner(out) + for scanner.Scan() { + n += int64(len(scanner.Bytes())) + data := pktline.Data(scanner.Bytes()) + if len(data) == 0 { + continue + } + + // Print progress data + if data[0] == 2 { + _, err := os.Stdout.Write(data[1:]) + noError(err) + } + } + + noError(scanner.Err()) msg("simulated POST \"/git-upload-pack\" returned %s, took %v", humanBytes(n), time.Since(start)) } |