Skip to content

Commit c25b18d

Browse files
authored
storegateway: Add a metric for inuse bytes (#6310)
1 parent 84c1d2b commit c25b18d

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* [ENHANCEMENT] Ingester/Store Gateway Clients: Introduce an experimental HealthCheck handler to quickly fail requests directed to unhealthy targets. #6225 #6257
2828
* [ENHANCEMENT] Upgrade build image and Go version to 1.23.2. #6261 #6262
2929
* [ENHANCEMENT] Querier/Ruler: Expose `store_gateway_consistency_check_max_attempts` for max retries when querying store gateway in consistency check. #6276
30+
* [ENHANCEMENT] StoreGateway: Add new `cortex_bucket_store_chunk_pool_inuse_bytes` metric to track the usage in chunk pool. #6310
3031
* [BUGFIX] Runtime-config: Handle absolute file paths when working directory is not / #6224
3132

3233
## 1.18.1 2024-10-14

pkg/storegateway/chunk_bytes_pool.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ type chunkBytesPool struct {
1010
pool *pool.BucketedPool[byte]
1111

1212
// Metrics.
13-
poolByteStats *prometheus.CounterVec
13+
poolByteStats *prometheus.CounterVec
14+
poolInUseBytes prometheus.GaugeFunc
1415
}
1516

1617
func newChunkBytesPool(minBucketSize, maxBucketSize int, maxChunkPoolBytes uint64, reg prometheus.Registerer) (*chunkBytesPool, error) {
@@ -25,6 +26,12 @@ func newChunkBytesPool(minBucketSize, maxBucketSize int, maxChunkPoolBytes uint6
2526
Name: "cortex_bucket_store_chunk_pool_operation_bytes_total",
2627
Help: "Total bytes number of bytes pooled by operation.",
2728
}, []string{"operation", "stats"}),
29+
poolInUseBytes: promauto.With(reg).NewGaugeFunc(prometheus.GaugeOpts{
30+
Name: "cortex_bucket_store_chunk_pool_inuse_bytes",
31+
Help: "Total bytes in use in the chunk pool.",
32+
}, func() float64 {
33+
return float64(upstream.UsedBytes())
34+
}),
2835
}, nil
2936
}
3037

pkg/storegateway/chunk_bytes_pool_test.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ func TestChunkBytesPool_Get(t *testing.T) {
2020
p, err := newChunkBytesPool(cortex_tsdb.ChunkPoolDefaultMinBucketSize, cortex_tsdb.ChunkPoolDefaultMaxBucketSize, 0, reg)
2121
require.NoError(t, err)
2222
testBytes := []byte("test")
23-
_, err = p.Get(store.EstimatedMaxChunkSize - 1)
23+
b0, err := p.Get(store.EstimatedMaxChunkSize - 1)
2424
require.NoError(t, err)
2525

26+
assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(fmt.Sprintf(`
27+
# HELP cortex_bucket_store_chunk_pool_inuse_bytes Total bytes in use in the chunk pool.
28+
# TYPE cortex_bucket_store_chunk_pool_inuse_bytes gauge
29+
cortex_bucket_store_chunk_pool_inuse_bytes %d
30+
`, 16000)), "cortex_bucket_store_chunk_pool_inuse_bytes"))
31+
2632
b, err := p.Get(store.EstimatedMaxChunkSize + 1)
2733
require.NoError(t, err)
2834

@@ -31,11 +37,21 @@ func TestChunkBytesPool_Get(t *testing.T) {
3137
p.Put(b)
3238

3339
assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(fmt.Sprintf(`
40+
# HELP cortex_bucket_store_chunk_pool_inuse_bytes Total bytes in use in the chunk pool.
41+
# TYPE cortex_bucket_store_chunk_pool_inuse_bytes gauge
42+
cortex_bucket_store_chunk_pool_inuse_bytes %d
3443
# HELP cortex_bucket_store_chunk_pool_operation_bytes_total Total bytes number of bytes pooled by operation.
3544
# TYPE cortex_bucket_store_chunk_pool_operation_bytes_total counter
3645
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="get",stats="cap"} %d
3746
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="get",stats="requested"} %d
3847
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="put",stats="cap"} %d
3948
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="put",stats="len"} %d
40-
`, store.EstimatedMaxChunkSize*3, store.EstimatedMaxChunkSize*2, store.EstimatedMaxChunkSize*2, len(testBytes)))))
49+
`, 16000, store.EstimatedMaxChunkSize*3, store.EstimatedMaxChunkSize*2, store.EstimatedMaxChunkSize*2, len(testBytes)))))
50+
51+
p.Put(b0)
52+
assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(fmt.Sprintf(`
53+
# HELP cortex_bucket_store_chunk_pool_inuse_bytes Total bytes in use in the chunk pool.
54+
# TYPE cortex_bucket_store_chunk_pool_inuse_bytes gauge
55+
cortex_bucket_store_chunk_pool_inuse_bytes %d
56+
`, 0)), "cortex_bucket_store_chunk_pool_inuse_bytes"))
4157
}

0 commit comments

Comments
 (0)