diff --git a/app/router.go b/app/router.go index f818a52ad..7ce3748ba 100644 --- a/app/router.go +++ b/app/router.go @@ -100,21 +100,6 @@ func RegisterTopologyRoutes(router *mux.Router, r Reporter) { gzipHandler(requestContextDecorator(makeProbeHandler(r)))) } -type byteCounter struct { - next io.ReadCloser - count *uint64 -} - -func (c byteCounter) Read(p []byte) (n int, err error) { - n, err = c.next.Read(p) - *c.count += uint64(n) - return n, err -} - -func (c byteCounter) Close() error { - return c.next.Close() -} - // RegisterReportPostHandler registers the handler for report submission func RegisterReportPostHandler(a Adder, router *mux.Router) { post := router.Methods("POST").Subrouter() diff --git a/report/marshal.go b/report/marshal.go index 3630482d2..7c35f05f2 100644 --- a/report/marshal.go +++ b/report/marshal.go @@ -5,6 +5,7 @@ import ( "encoding/gob" "io" + log "github.com/Sirupsen/logrus" "github.com/ugorji/go/codec" ) @@ -21,18 +22,40 @@ func (rep Report) WriteBinary(w io.Writer) error { return nil } +type byteCounter struct { + next io.Reader + count *uint64 +} + +func (c byteCounter) Read(p []byte) (n int, err error) { + n, err = c.next.Read(p) + *c.count += uint64(n) + return n, err +} + // ReadBinary reads bytes into a Report. // // Will decompress the binary if gzipped is true, and will use the given // codecHandle to decode it. If codecHandle is nil, will decode as a gob. func (rep *Report) ReadBinary(r io.Reader, gzipped bool, codecHandle codec.Handle) error { var err error + var compressedSize, uncompressedSize uint64 + + // We have historically had trouble with reports being too large. We are + // keeping this instrumentation around to help us implement + // weaveworks/scope#985. + if log.GetLevel() == log.DebugLevel { + r = byteCounter{next: r, count: &compressedSize} + } if gzipped { r, err = gzip.NewReader(r) if err != nil { return err } } + if log.GetLevel() == log.DebugLevel { + r = byteCounter{next: r, count: &uncompressedSize} + } var decoder func(interface{}) error if codecHandle != nil { decoder = codec.NewDecoder(r, codecHandle).Decode @@ -42,6 +65,12 @@ func (rep *Report) ReadBinary(r io.Reader, gzipped bool, codecHandle codec.Handl if err := decoder(&rep); err != nil { return err } + log.Debugf( + "Received report sizes: compressed %d bytes, uncompressed %d bytes (%.2f%%)", + compressedSize, + uncompressedSize, + float32(compressedSize)/float32(uncompressedSize)*100, + ) return nil }