Skip to content
Open
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 @@ -7,6 +7,7 @@
* Flags: Renamed `-querier.parquet-queryable-shard-cache-size` to `-querier.parquet-shard-cache-size` and `-querier.parquet-queryable-shard-cache-ttl` to `-querier.parquet-shard-cache-ttl`.
* Config: Renamed `parquet_queryable_shard_cache_size` to `parquet_shard_cache_size` and `parquet_queryable_shard_cache_ttl` to `parquet_shard_cache_ttl`.
* [FEATURE] StoreGateway: Introduces a new parquet mode. #7046
* [FEATURE] StoreGateway: Add a parquet shard cache to parquet mode. #7166
* [FEATURE] Distributor: Add a per-tenant flag `-distributor.enable-type-and-unit-labels` that enables adding `__unit__` and `__type__` labels for remote write v2 and OTLP requests. This is a breaking change; the `-distributor.otlp.enable-type-and-unit-labels` flag is now deprecated, operates as a no-op, and has been consolidated into this new flag. #7077
* [ENHANCEMENT] StoreGateway: Add tracings to parquet mode. #7125
* [ENHANCEMENT] Alertmanager: Upgrade alertmanger to 0.29.0 and add a new incidentIO integration. #7092
Expand Down
8 changes: 8 additions & 0 deletions docs/blocks-storage/querier.md
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,14 @@ blocks_storage:
# CLI flag: -blocks-storage.bucket-store.token-bucket-bytes-limiter.request-token-bucket-size
[request_token_bucket_size: <int> | default = 4194304]

# [Experimental] Maximum size of the Parquet shard cache. 0 to disable.
# CLI flag: -blocks-storage.bucket-store.parquet-shard-cache-size
[parquet_shard_cache_size: <int> | default = 512]

# [Experimental] TTL of the Parquet shard cache. 0 to no TTL.
# CLI flag: -blocks-storage.bucket-store.parquet-shard-cache-ttl
[parquet_shard_cache_ttl: <duration> | default = 24h]

tsdb:
# Local directory to store TSDBs in the ingesters.
# CLI flag: -blocks-storage.tsdb.dir
Expand Down
8 changes: 8 additions & 0 deletions docs/blocks-storage/store-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,14 @@ blocks_storage:
# CLI flag: -blocks-storage.bucket-store.token-bucket-bytes-limiter.request-token-bucket-size
[request_token_bucket_size: <int> | default = 4194304]

# [Experimental] Maximum size of the Parquet shard cache. 0 to disable.
# CLI flag: -blocks-storage.bucket-store.parquet-shard-cache-size
[parquet_shard_cache_size: <int> | default = 512]

# [Experimental] TTL of the Parquet shard cache. 0 to no TTL.
# CLI flag: -blocks-storage.bucket-store.parquet-shard-cache-ttl
[parquet_shard_cache_ttl: <duration> | default = 24h]

tsdb:
# Local directory to store TSDBs in the ingesters.
# CLI flag: -blocks-storage.tsdb.dir
Expand Down
8 changes: 8 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2477,6 +2477,14 @@ bucket_store:
# CLI flag: -blocks-storage.bucket-store.token-bucket-bytes-limiter.request-token-bucket-size
[request_token_bucket_size: <int> | default = 4194304]

# [Experimental] Maximum size of the Parquet shard cache. 0 to disable.
# CLI flag: -blocks-storage.bucket-store.parquet-shard-cache-size
[parquet_shard_cache_size: <int> | default = 512]

# [Experimental] TTL of the Parquet shard cache. 0 to no TTL.
# CLI flag: -blocks-storage.bucket-store.parquet-shard-cache-ttl
[parquet_shard_cache_ttl: <duration> | default = 24h]

tsdb:
# Local directory to store TSDBs in the ingesters.
# CLI flag: -blocks-storage.tsdb.dir
Expand Down
11 changes: 11 additions & 0 deletions integration/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,17 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
if strings.Contains(testCfg.chunkCacheBackend, tsdb.CacheBackendRedis) {
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Greater(float64(0)), "thanos_cache_redis_requests_total"))
}

// ensure parquet shard cache works
require.NoError(t, storeGateways.WaitSumMetricsWithOptions(e2e.Greater(float64(0)), []string{"cortex_parquet_cache_hits_total"}, e2e.WithLabelMatchers(
labels.MustNewMatcher(labels.MatchEqual, "component", "store-gateway"),
labels.MustNewMatcher(labels.MatchEqual, "name", "parquet-shards"))))
require.NoError(t, storeGateways.WaitSumMetricsWithOptions(e2e.Greater(float64(0)), []string{"cortex_parquet_cache_item_count"}, e2e.WithLabelMatchers(
labels.MustNewMatcher(labels.MatchEqual, "component", "store-gateway"),
labels.MustNewMatcher(labels.MatchEqual, "name", "parquet-shards"))))
require.NoError(t, storeGateways.WaitSumMetricsWithOptions(e2e.Greater(float64(0)), []string{"cortex_parquet_cache_misses_total"}, e2e.WithLabelMatchers(
labels.MustNewMatcher(labels.MatchEqual, "component", "store-gateway"),
labels.MustNewMatcher(labels.MatchEqual, "name", "parquet-shards"))))
}

// Query metadata.
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/tsdb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cortexproject/cortex/pkg/storage/bucket"
"github.com/cortexproject/cortex/pkg/util/flagext"
util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/cortexproject/cortex/pkg/util/parquetutil"
"github.com/cortexproject/cortex/pkg/util/users"
)

Expand Down Expand Up @@ -332,6 +333,8 @@ type BucketStoreConfig struct {

// Token bucket configs
TokenBucketBytesLimiter TokenBucketBytesLimiterConfig `yaml:"token_bucket_bytes_limiter"`
// Parquet shard cache config
ParquetShardCache parquetutil.CacheConfig `yaml:",inline"`
}

type TokenBucketBytesLimiterConfig struct {
Expand Down Expand Up @@ -393,6 +396,7 @@ func (cfg *BucketStoreConfig) RegisterFlags(f *flag.FlagSet) {
f.Float64Var(&cfg.TokenBucketBytesLimiter.FetchedChunksTokenFactor, "blocks-storage.bucket-store.token-bucket-bytes-limiter.fetched-chunks-token-factor", 0, "Multiplication factor used for fetched chunks token")
f.Float64Var(&cfg.TokenBucketBytesLimiter.TouchedChunksTokenFactor, "blocks-storage.bucket-store.token-bucket-bytes-limiter.touched-chunks-token-factor", 1, "Multiplication factor used for touched chunks token")
f.IntVar(&cfg.MatchersCacheMaxItems, "blocks-storage.bucket-store.matchers-cache-max-items", 0, "Maximum number of entries in the regex matchers cache. 0 to disable.")
cfg.ParquetShardCache.RegisterFlagsWithPrefix("blocks-storage.bucket-store.", f)
}

// Validate the config.
Expand Down
2 changes: 2 additions & 0 deletions pkg/storegateway/bucket_stores_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/store/storepb"
"github.com/weaveworks/common/logging"
"github.com/weaveworks/common/user"
"go.uber.org/atomic"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -761,6 +762,7 @@ func querySeries(stores BucketStores, userID, metricName string, minT, maxT int6
}

ctx := setUserIDToGRPCContext(context.Background(), userID)
ctx = user.InjectOrgID(ctx, userID)
srv := newBucketStoreSeriesServer(ctx)
err = stores.Series(req, srv)

Expand Down
4 changes: 3 additions & 1 deletion pkg/storegateway/parquet_bucket_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cortexproject/cortex/pkg/util/parquetutil"
"github.com/cortexproject/cortex/pkg/util/spanlogger"
"github.com/cortexproject/cortex/pkg/util/validation"
)
Expand All @@ -37,7 +38,8 @@ type parquetBucketStore struct {

chunksDecoder *schema.PrometheusParquetChunksDecoder

matcherCache storecache.MatchersCache
matcherCache storecache.MatchersCache
parquetShardCache parquetutil.CacheInterface[parquet_storage.ParquetShard]
}

func (p *parquetBucketStore) Close() error {
Expand Down
82 changes: 53 additions & 29 deletions pkg/storegateway/parquet_bucket_stores.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import (
"github.com/cortexproject/cortex/pkg/storage/tsdb"
cortex_util "github.com/cortexproject/cortex/pkg/util"
cortex_errors "github.com/cortexproject/cortex/pkg/util/errors"
"github.com/cortexproject/cortex/pkg/util/parquetutil"
"github.com/cortexproject/cortex/pkg/util/spanlogger"
"github.com/cortexproject/cortex/pkg/util/users"
"github.com/cortexproject/cortex/pkg/util/validation"
)

Expand All @@ -52,7 +54,8 @@ type ParquetBucketStores struct {

chunksDecoder *schema.PrometheusParquetChunksDecoder

matcherCache storecache.MatchersCache
matcherCache storecache.MatchersCache
parquetShardCache parquetutil.CacheInterface[parquet_storage.ParquetShard]

inflightRequests *cortex_util.InflightRequestTracker
}
Expand All @@ -65,15 +68,21 @@ func newParquetBucketStores(cfg tsdb.BlocksStorageConfig, bucketClient objstore.
return nil, err
}

parquetShardCache, err := parquetutil.NewParquetShardCache[parquet_storage.ParquetShard](&cfg.BucketStore.ParquetShardCache, "parquet-shards", reg)
if err != nil {
return nil, err
}

u := &ParquetBucketStores{
logger: logger,
cfg: cfg,
limits: limits,
bucket: cachingBucket,
stores: map[string]*parquetBucketStore{},
storesErrors: map[string]error{},
chunksDecoder: schema.NewPrometheusParquetChunksDecoder(chunkenc.NewPool()),
inflightRequests: cortex_util.NewInflightRequestTracker(),
logger: logger,
cfg: cfg,
limits: limits,
bucket: cachingBucket,
stores: map[string]*parquetBucketStore{},
storesErrors: map[string]error{},
chunksDecoder: schema.NewPrometheusParquetChunksDecoder(chunkenc.NewPool()),
inflightRequests: cortex_util.NewInflightRequestTracker(),
parquetShardCache: parquetShardCache,
}

if cfg.BucketStore.MatchersCacheMaxItems > 0 {
Expand Down Expand Up @@ -246,12 +255,13 @@ func (u *ParquetBucketStores) createParquetBucketStore(userID string, userLogger
userBucket := bucket.NewUserBucketClient(userID, u.bucket, u.limits)

store := &parquetBucketStore{
logger: userLogger,
bucket: userBucket,
limits: u.limits,
concurrency: 4, // TODO: make this configurable
chunksDecoder: u.chunksDecoder,
matcherCache: u.matcherCache,
logger: userLogger,
bucket: userBucket,
limits: u.limits,
concurrency: 4, // TODO: make this configurable
chunksDecoder: u.chunksDecoder,
matcherCache: u.matcherCache,
parquetShardCache: u.parquetShardCache,
}

return store, nil
Expand All @@ -265,21 +275,35 @@ type parquetBlock struct {
}

func (p *parquetBucketStore) newParquetBlock(ctx context.Context, name string, labelsFileOpener, chunksFileOpener parquet_storage.ParquetOpener, d *schema.PrometheusParquetChunksDecoder, rowCountQuota *search.Quota, chunkBytesQuota *search.Quota, dataBytesQuota *search.Quota) (*parquetBlock, error) {
shard, err := parquet_storage.NewParquetShardOpener(
context.WithoutCancel(ctx),
name,
labelsFileOpener,
chunksFileOpener,
0,
parquet_storage.WithFileOptions(
parquet.SkipMagicBytes(true),
parquet.ReadBufferSize(100*1024),
parquet.SkipBloomFilters(true),
parquet.OptimisticRead(true),
),
)
userID, err := users.TenantID(ctx)
if err != nil {
return nil, errors.Wrapf(err, "failed to open parquet shard. block: %v", name)
return nil, err
}

cacheKey := fmt.Sprintf("%v-%v", userID, name)
shard := p.parquetShardCache.Get(cacheKey)

if shard == nil {
// cache miss, open parquet files
shard, err = parquet_storage.NewParquetShardOpener(
context.WithoutCancel(ctx),
name,
labelsFileOpener,
chunksFileOpener,
0, // we always only have 1 shard - shard 0
parquet_storage.WithFileOptions(
parquet.SkipMagicBytes(true),
parquet.ReadBufferSize(100*1024),
parquet.SkipBloomFilters(true),
parquet.OptimisticRead(true),
),
)
if err != nil {
return nil, errors.Wrapf(err, "failed to open parquet shard. block: %v", name)
}

// set shard to cache
p.parquetShardCache.Set(cacheKey, shard)
}

s, err := shard.TSDBSchema()
Expand Down
13 changes: 13 additions & 0 deletions schemas/cortex-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2600,6 +2600,19 @@
},
"type": "object"
},
"parquet_shard_cache_size": {
"default": 512,
"description": "[Experimental] Maximum size of the Parquet shard cache. 0 to disable.",
"type": "number",
"x-cli-flag": "blocks-storage.bucket-store.parquet-shard-cache-size"
},
"parquet_shard_cache_ttl": {
"default": "24h0m0s",
"description": "[Experimental] TTL of the Parquet shard cache. 0 to no TTL.",
"type": "string",
"x-cli-flag": "blocks-storage.bucket-store.parquet-shard-cache-ttl",
"x-format": "duration"
},
"series_batch_size": {
"default": 10000,
"description": "Controls how many series to fetch per batch in Store Gateway. Default value is 10000.",
Expand Down
Loading