Skip to content

Commit ef018b2

Browse files
committed
storegateway: Add a metric for inuse bytes
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
1 parent e3b4ef8 commit ef018b2

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import (
44
"github.com/prometheus/client_golang/prometheus"
55
"github.com/prometheus/client_golang/prometheus/promauto"
66
"github.com/thanos-io/thanos/pkg/pool"
7+
"time"
78
)
89

10+
const chunkPoolBytesInuseUpdateInterval = 1 * time.Second
11+
912
type chunkBytesPool struct {
1013
pool *pool.BucketedPool[byte]
1114

1215
// Metrics.
13-
poolByteStats *prometheus.CounterVec
16+
poolByteStats *prometheus.CounterVec
17+
poolInUseBytes prometheus.GaugeFunc
1418
}
1519

1620
func newChunkBytesPool(minBucketSize, maxBucketSize int, maxChunkPoolBytes uint64, reg prometheus.Registerer) (*chunkBytesPool, error) {
@@ -25,6 +29,12 @@ func newChunkBytesPool(minBucketSize, maxBucketSize int, maxChunkPoolBytes uint6
2529
Name: "cortex_bucket_store_chunk_pool_operation_bytes_total",
2630
Help: "Total bytes number of bytes pooled by operation.",
2731
}, []string{"operation", "stats"}),
32+
poolInUseBytes: promauto.With(reg).NewGaugeFunc(prometheus.GaugeOpts{
33+
Name: "cortex_bucket_store_chunk_pool_inuse_bytes",
34+
Help: "Total bytes in use in the chunk pool.",
35+
}, func() float64 {
36+
return float64(upstream.UsedBytes())
37+
}),
2838
}, nil
2939
}
3040

pkg/storegateway/chunk_bytes_pool_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package storegateway
33
import (
44
"bytes"
55
"fmt"
6-
"testing"
7-
86
"github.com/prometheus/client_golang/prometheus"
97
"github.com/prometheus/client_golang/prometheus/testutil"
108
"github.com/stretchr/testify/assert"
119
"github.com/stretchr/testify/require"
1210
"github.com/thanos-io/thanos/pkg/store"
11+
"testing"
1312

1413
cortex_tsdb "github.com/cortexproject/cortex/pkg/storage/tsdb"
1514
)
@@ -20,9 +19,15 @@ func TestChunkBytesPool_Get(t *testing.T) {
2019
p, err := newChunkBytesPool(cortex_tsdb.ChunkPoolDefaultMinBucketSize, cortex_tsdb.ChunkPoolDefaultMaxBucketSize, 0, reg)
2120
require.NoError(t, err)
2221
testBytes := []byte("test")
23-
_, err = p.Get(store.EstimatedMaxChunkSize - 1)
22+
b0, err := p.Get(store.EstimatedMaxChunkSize - 1)
2423
require.NoError(t, err)
2524

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

@@ -31,11 +36,21 @@ func TestChunkBytesPool_Get(t *testing.T) {
3136
p.Put(b)
3237

3338
assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(fmt.Sprintf(`
39+
# HELP cortex_bucket_store_chunk_pool_inuse_bytes Total bytes in use in the chunk pool.
40+
# TYPE cortex_bucket_store_chunk_pool_inuse_bytes gauge
41+
cortex_bucket_store_chunk_pool_inuse_bytes %d
3442
# HELP cortex_bucket_store_chunk_pool_operation_bytes_total Total bytes number of bytes pooled by operation.
3543
# TYPE cortex_bucket_store_chunk_pool_operation_bytes_total counter
3644
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="get",stats="cap"} %d
3745
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="get",stats="requested"} %d
3846
cortex_bucket_store_chunk_pool_operation_bytes_total{operation="put",stats="cap"} %d
3947
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)))))
48+
`, 16000, store.EstimatedMaxChunkSize*3, store.EstimatedMaxChunkSize*2, store.EstimatedMaxChunkSize*2, len(testBytes)))))
49+
50+
p.Put(b0)
51+
assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(fmt.Sprintf(`
52+
# HELP cortex_bucket_store_chunk_pool_inuse_bytes Total bytes in use in the chunk pool.
53+
# TYPE cortex_bucket_store_chunk_pool_inuse_bytes gauge
54+
cortex_bucket_store_chunk_pool_inuse_bytes %d
55+
`, 0)), "cortex_bucket_store_chunk_pool_inuse_bytes"))
4156
}

0 commit comments

Comments
 (0)