Skip to content

Commit

Permalink
instrument in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblum committed Feb 13, 2020
1 parent 88a7c3e commit 8a50107
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions go/libkb/client.go
Expand Up @@ -302,24 +302,29 @@ func (b *InstrumentedBody) Read(p []byte) (n int, err error) {
func (b *InstrumentedBody) Close() (err error) {
// instrument the full body size even if the caller hasn't consumed it.
_, _ = io.Copy(ioutil.Discard, b.body)
if b.uncompressed {
// gzip the body we stored and instrument the compressed size
var buf bytes.Buffer
writer, reclaim := b.gzipGetter(&buf)
defer reclaim()
if _, err = writer.Write(b.gzipBuf.Bytes()); err != nil {
return err
// Do actual instrumentation in the background
go func() {
if b.uncompressed {
// gzip the body we stored and instrument the compressed size
var buf bytes.Buffer
writer, reclaim := b.gzipGetter(&buf)
defer reclaim()
if _, err = writer.Write(b.gzipBuf.Bytes()); err != nil {
b.G().Log.CDebugf(context.TODO(), "InstrumentedBody:unable to write gzip %v", err)
return
}
if err = writer.Close(); err != nil {
b.G().Log.CDebugf(context.TODO(), "InstrumentedBody:unable to close gzip %v", err)
return
}
b.record.IncrementSize(int64(buf.Len()))
} else {
b.record.IncrementSize(int64(b.n))
}
if err = writer.Close(); err != nil {
return err
if err := b.record.Finish(); err != nil {
b.G().Log.CDebugf(context.TODO(), "InstrumentedBody: unable to instrument network request: %s, %s", b.record, err)
}
b.n = b.gzipBuf.Len()
}
b.record.IncrementSize(int64(b.n))
if err := b.record.Finish(); err != nil {
b.G().Log.CDebugf(context.TODO(), "InstrumentedBody: unable to instrument network request: %s, %s", b.record, err)
return err
}
}()
return b.body.Close()
}

Expand Down

0 comments on commit 8a50107

Please sign in to comment.