Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Couder <chriscool@tuxfamily.org>2021-12-09 16:54:13 +0300
committerChristian Couder <chriscool@tuxfamily.org>2021-12-09 16:54:13 +0300
commit34fd7dec6f48c74db80db6e04b25bb1d7be92c92 (patch)
treebe8f703f8d4a371b87d3a2c1512ba9666c2afa70
parent4ba8618078d9107d52c0d735f76286ab0b113a8a (diff)
parentbe15b6e5eb470bb866045c5c013596fe6e7e6bdf (diff)
Merge branch 'jv-log-ssh-bytes' into 'master'
SSHUploadPack: log response size in bytes See merge request gitlab-org/gitaly!4182
-rw-r--r--internal/gitaly/service/hook/pack_objects.go13
-rw-r--r--internal/gitaly/service/ssh/upload_pack.go6
-rw-r--r--internal/helper/count.go16
3 files changed, 21 insertions, 14 deletions
diff --git a/internal/gitaly/service/hook/pack_objects.go b/internal/gitaly/service/hook/pack_objects.go
index 2dfadfec0..f75204cea 100644
--- a/internal/gitaly/service/hook/pack_objects.go
+++ b/internal/gitaly/service/hook/pack_objects.go
@@ -142,7 +142,7 @@ func (s *server) runPackObjects(ctx context.Context, w io.Writer, repo *gitalypb
defer stdin.Close()
- counter := &countingWriter{W: w}
+ counter := &helper.CountingWriter{W: w}
sw := pktline.NewSidebandWriter(counter)
stdout := bufio.NewWriterSize(sw.Writer(bandStdout), pktline.MaxSidebandData)
stderrBuf := &bytes.Buffer{}
@@ -287,17 +287,6 @@ func bufferStdin(r io.Reader, h hash.Hash) (_ io.ReadCloser, err error) {
return f, nil
}
-type countingWriter struct {
- W io.Writer
- N int64
-}
-
-func (cw *countingWriter) Write(p []byte) (int, error) {
- n, err := cw.W.Write(p)
- cw.N += int64(n)
- return n, err
-}
-
func (s *server) PackObjectsHookWithSidechannel(ctx context.Context, req *gitalypb.PackObjectsHookWithSidechannelRequest) (*gitalypb.PackObjectsHookWithSidechannelResponse, error) {
if req.GetRepository() == nil {
return nil, helper.ErrInvalidArgument(errors.New("repository is empty"))
diff --git a/internal/gitaly/service/ssh/upload_pack.go b/internal/gitaly/service/ssh/upload_pack.go
index f935491ae..d2ac79a7a 100644
--- a/internal/gitaly/service/ssh/upload_pack.go
+++ b/internal/gitaly/service/ssh/upload_pack.go
@@ -58,9 +58,9 @@ func (s *server) sshUploadPack(stream gitalypb.SSHService_SSHUploadPackServer, r
// synchronize writing stdout and stderrr.
var m sync.Mutex
- stdout := streamio.NewSyncWriter(&m, func(p []byte) error {
+ stdout := &helper.CountingWriter{W: streamio.NewSyncWriter(&m, func(p []byte) error {
return stream.Send(&gitalypb.SSHUploadPackResponse{Stdout: p})
- })
+ })}
stderr := streamio.NewSyncWriter(&m, func(p []byte) error {
return stream.Send(&gitalypb.SSHUploadPackResponse{Stderr: p})
@@ -135,6 +135,8 @@ func (s *server) sshUploadPack(stream gitalypb.SSHService_SSHUploadPackServer, r
pw.Close()
wg.Wait()
+ ctxlogrus.Extract(ctx).WithField("response_bytes", stdout.N).Info("request details")
+
return nil
}
diff --git a/internal/helper/count.go b/internal/helper/count.go
new file mode 100644
index 000000000..c5b7c419b
--- /dev/null
+++ b/internal/helper/count.go
@@ -0,0 +1,16 @@
+package helper
+
+import "io"
+
+// CountingWriter wraps an io.Writer and counts all the writes. Accessing
+// the count N is not thread-safe.
+type CountingWriter struct {
+ W io.Writer
+ N int64
+}
+
+func (cw *CountingWriter) Write(p []byte) (int, error) {
+ n, err := cw.W.Write(p)
+ cw.N += int64(n)
+ return n, err
+}