Skip to content

Commit

Permalink
Use hard-coded list of block durations in store-gateway (#6129)
Browse files Browse the repository at this point in the history
Use a hard-coded list of durations instead of requiring the store-gateway
to be aware of compactor-specific configuration.

Related #6074

Signed-off-by: Nick Pillitteri <[email protected]>
  • Loading branch information
56quarters authored Sep 25, 2023
1 parent 48fe3c5 commit c584ed3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* [ENHANCEMENT] Ingester: exported summary `cortex_ingester_inflight_push_requests_summary` tracking total number of inflight requests in percentile buckets. #5845
* [ENHANCEMENT] Query-scheduler: add `cortex_query_scheduler_enqueue_duration_seconds` metric that records the time taken to enqueue or reject a query request. #5879
* [ENHANCEMENT] Query-frontend: add `cortex_query_frontend_enqueue_duration_seconds` metric that records the time taken to enqueue or reject a query request. #5879 #6087
* [ENHANCEMENT] Store-gateway: add metric `cortex_bucket_store_blocks_loaded_by_duration` for counting the loaded number of blocks based on their duration. #6074
* [ENHANCEMENT] Store-gateway: add metric `cortex_bucket_store_blocks_loaded_by_duration` for counting the loaded number of blocks based on their duration. #6074 #6129
* [ENHANCEMENT] Expose `/sync/mutex/wait/total:seconds` Go runtime metric as `go_sync_mutex_wait_total_seconds_total` from all components. #5879
* [ENHANCEMENT] Query-scheduler: improve latency with many concurrent queriers. #5880
* [ENHANCEMENT] Implement support for `limit`, `limit_per_metric` and `metric` parameters for `<Prometheus HTTP prefix>/api/v1/metadata` endpoint. #5890
Expand Down
4 changes: 2 additions & 2 deletions pkg/storegateway/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ func (s *BucketStore) RemoveBlocksAndClose() error {
}

// Stats returns statistics about the BucketStore instance.
func (s *BucketStore) Stats(durations tsdb.DurationList) BucketStoreStats {
func (s *BucketStore) Stats(durations []time.Duration) BucketStoreStats {
s.blocksMx.RLock()
defer s.blocksMx.RUnlock()

return buildStoreStats(durations, s.blocks)
}

func buildStoreStats(durations tsdb.DurationList, blocks map[ulid.ULID]*bucketBlock) BucketStoreStats {
func buildStoreStats(durations []time.Duration, blocks map[ulid.ULID]*bucketBlock) BucketStoreStats {
stats := BucketStoreStats{}
stats.BlocksLoaded = make(map[time.Duration]int)

Expand Down
13 changes: 9 additions & 4 deletions pkg/storegateway/bucket_stores.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ import (
// (This is now separate from DeprecatedTenantIDExternalLabel to signify different use case.)
const GrpcContextMetadataTenantID = "__org_id__"

// defaultBlockDurations is the expected duration of blocks the compactor generates. This is used for
// metrics emitted by the store-gateway, so it's fine to hardcode it here instead of using the durations
// that are actually configured to avoid coupling to compactor configuration.
var defaultBlockDurations = []time.Duration{2 * time.Hour, 12 * time.Hour, 24 * time.Hour}

// BucketStores is a multi-tenant wrapper of Thanos BucketStore.
type BucketStores struct {
logger log.Logger
Expand Down Expand Up @@ -561,16 +566,16 @@ func (u *BucketStores) closeBucketStoreAndDeleteLocalFilesForExcludedTenants(inc
}

// countBlocksLoaded returns the total number of blocks loaded and the number of blocks
// loaded bucketed by the configured block durations, summed for all users.
func (u *BucketStores) countBlocksLoaded() (int, map[time.Duration]int) {
// loaded bucketed by the provided block durations, summed for all users.
func (u *BucketStores) countBlocksLoaded(durations []time.Duration) (int, map[time.Duration]int) {
byDuration := make(map[time.Duration]int)
total := 0

u.storesMu.RLock()
defer u.storesMu.RUnlock()

for _, store := range u.stores {
stats := store.Stats(u.cfg.TSDB.BlockRanges)
stats := store.Stats(durations)
for d, n := range stats.BlocksLoaded {
byDuration[d] += n
total += n
Expand All @@ -586,7 +591,7 @@ func (u *BucketStores) Describe(descs chan<- *prometheus.Desc) {
}

func (u *BucketStores) Collect(metrics chan<- prometheus.Metric) {
total, byDuration := u.countBlocksLoaded()
total, byDuration := u.countBlocksLoaded(defaultBlockDurations)
metrics <- prometheus.MustNewConstMetric(u.blocksLoaded, prometheus.GaugeValue, float64(total))
for d, n := range byDuration {
// Convert time.Duration to model.Duration here since the string format is nicer
Expand Down

0 comments on commit c584ed3

Please sign in to comment.