Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating new metric around chunks bytespool #5552

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [CHANGE] Store Gateway: Remove `idle_timeout`, `max_conn_age`, `pool_size`, `min_idle_conns` fields for Redis index cache and caching bucket. #5448
* [CHANGE] Store Gateway: Add flag `-store-gateway.sharding-ring.zone-stable-shuffle-sharding` to enable store gateway to use zone stable shuffle sharding. #5489
* [CHANGE] Bucket Index: Add `series_max_size` and `chunk_max_size` to bucket index. #5489
* [CHANGE] StoreGateway: Rename `cortex_bucket_store_chunk_pool_returned_bytes_total` and `cortex_bucket_store_chunk_pool_requested_bytes_total` to `cortex_bucket_store_chunk_pool_operation_bytes_total`. #5552
* [CHANGE] Query Frontend/Querier: Make build info API disabled by default and add feature flag `api.build-info-enabled` to enable it. #5533
* [FEATURE] Store Gateway: Add `max_downloaded_bytes_per_request` to limit max bytes to download per store gateway request.
* [FEATURE] Added 2 flags `-alertmanager.alertmanager-client.grpc-max-send-msg-size` and ` -alertmanager.alertmanager-client.grpc-max-recv-msg-size` to configure alert manager grpc client message size limits. #5338
Expand Down
21 changes: 9 additions & 12 deletions pkg/storegateway/chunk_bytes_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ type chunkBytesPool struct {
pool *pool.BucketedBytes

// Metrics.
requestedBytes prometheus.Counter
returnedBytes prometheus.Counter
poolByteStats *prometheus.CounterVec
}

func newChunkBytesPool(minBucketSize, maxBucketSize int, maxChunkPoolBytes uint64, reg prometheus.Registerer) (*chunkBytesPool, error) {
Expand All @@ -22,14 +21,10 @@ func newChunkBytesPool(minBucketSize, maxBucketSize int, maxChunkPoolBytes uint6

return &chunkBytesPool{
pool: upstream,
requestedBytes: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "cortex_bucket_store_chunk_pool_requested_bytes_total",
Help: "Total bytes requested to chunk bytes pool.",
}),
returnedBytes: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "cortex_bucket_store_chunk_pool_returned_bytes_total",
Help: "Total bytes returned by the chunk bytes pool.",
}),
poolByteStats: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
Name: "cortex_bucket_store_chunk_pool_operation_bytes_total",
Help: "Total bytes number of bytes pooled by operation.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion for this would be "Bytes checkout or returned to the chunk pool"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

humm.. idk.. i think s too verbose

}, []string{"operation", "stats"}),
}, nil
}

Expand All @@ -39,12 +34,14 @@ func (p *chunkBytesPool) Get(sz int) (*[]byte, error) {
return buffer, err
}

p.requestedBytes.Add(float64(sz))
p.returnedBytes.Add(float64(cap(*buffer)))
p.poolByteStats.WithLabelValues("get", "requested").Add(float64(sz))
p.poolByteStats.WithLabelValues("get", "cap").Add(float64(cap(*buffer)))

return buffer, err
}

func (p *chunkBytesPool) Put(b *[]byte) {
p.poolByteStats.WithLabelValues("put", "len").Add(float64(len(*b)))
p.poolByteStats.WithLabelValues("put", "cap").Add(float64(cap(*b)))
p.pool.Put(b)
}
23 changes: 13 additions & 10 deletions pkg/storegateway/chunk_bytes_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@ func TestChunkBytesPool_Get(t *testing.T) {
reg := prometheus.NewPedanticRegistry()
p, err := newChunkBytesPool(cortex_tsdb.ChunkPoolDefaultMinBucketSize, cortex_tsdb.ChunkPoolDefaultMaxBucketSize, 0, reg)
require.NoError(t, err)

testBytes := []byte("test")
_, err = p.Get(store.EstimatedMaxChunkSize - 1)
require.NoError(t, err)

_, err = p.Get(store.EstimatedMaxChunkSize + 1)
b, err := p.Get(store.EstimatedMaxChunkSize + 1)
require.NoError(t, err)

*b = append(*b, testBytes...)

p.Put(b)

assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(fmt.Sprintf(`
# HELP cortex_bucket_store_chunk_pool_requested_bytes_total Total bytes requested to chunk bytes pool.
# TYPE cortex_bucket_store_chunk_pool_requested_bytes_total counter
cortex_bucket_store_chunk_pool_requested_bytes_total %d

# HELP cortex_bucket_store_chunk_pool_returned_bytes_total Total bytes returned by the chunk bytes pool.
# TYPE cortex_bucket_store_chunk_pool_returned_bytes_total counter
cortex_bucket_store_chunk_pool_returned_bytes_total %d
`, store.EstimatedMaxChunkSize*2, store.EstimatedMaxChunkSize*3))))
# HELP cortex_bucket_store_chunk_pool_operation_bytes_total Total bytes number of bytes pooled by operation.
# TYPE cortex_bucket_store_chunk_pool_operation_bytes_total counter
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="get",stats="cap"} %d
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="get",stats="requested"} %d
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="put",stats="cap"} %d
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="put",stats="len"} %d
`, store.EstimatedMaxChunkSize*3, store.EstimatedMaxChunkSize*2, store.EstimatedMaxChunkSize*2, len(testBytes)))))
}
Loading