Skip to content

Find, verify, and analyze leaked credentials

[chore] - Record metrics before reset (#2556)

ahrav800cc6d90b88
diff --git a/pkg/writers/buffer/buffer.go b/pkg/writers/buffer/buffer.go
index f4b443811..9a7c5cf1b 100644
--- a/pkg/writers/buffer/buffer.go
+++ b/pkg/writers/buffer/buffer.go
@@ -24,10 +24,11 @@ func (poolMetrics) recordBufferRetrival() {
bufferCount.Inc()
}
-func (poolMetrics) recordBufferReturn(bufCap, bufLen int64) {
+func (poolMetrics) recordBufferReturn(buf *Buffer) {
activeBufferCount.Dec()
- totalBufferSize.Add(float64(bufCap))
- totalBufferLength.Add(float64(bufLen))
+ totalBufferSize.Add(float64(buf.Len()))
+ totalBufferLength.Add(float64(buf.Len()))
+ buf.recordMetric()
}
// PoolOpts is a function that configures a BufferPool.
@@ -73,7 +74,7 @@ func (p *Pool) Get(ctx context.Context) *Buffer {
// Put returns a Buffer to the pool.
func (p *Pool) Put(buf *Buffer) {
- p.metrics.recordBufferReturn(int64(buf.Cap()), int64(buf.Len()))
+ p.metrics.recordBufferReturn(buf)
// If the Buffer is more than twice the default size, replace it with a new Buffer.
// This prevents us from returning very large buffers to the pool.
@@ -85,7 +86,6 @@ func (p *Pool) Put(buf *Buffer) {
// Reset the Buffer to clear any existing data.
buf.Reset()
}
- buf.recordMetric()
p.Pool.Put(buf)
}