Skip to content

Commit b38ba42

Browse files
committed
add enabled and disabled tenants in storegateway
Signed-off-by: Shashank <[email protected]>
1 parent 7a08f8c commit b38ba42

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/storegateway/gateway.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
cortex_tsdb "github.com/cortexproject/cortex/pkg/storage/tsdb"
2424
"github.com/cortexproject/cortex/pkg/storegateway/storegatewaypb"
2525
"github.com/cortexproject/cortex/pkg/util"
26+
"github.com/cortexproject/cortex/pkg/util/flagext"
2627
"github.com/cortexproject/cortex/pkg/util/services"
2728
"github.com/cortexproject/cortex/pkg/util/validation"
2829
)
@@ -54,6 +55,9 @@ type Config struct {
5455
ShardingEnabled bool `yaml:"sharding_enabled"`
5556
ShardingRing RingConfig `yaml:"sharding_ring" doc:"description=The hash ring configuration. This option is required only if blocks sharding is enabled."`
5657
ShardingStrategy string `yaml:"sharding_strategy"`
58+
59+
EnabledTenants flagext.StringSliceCSV `yaml:"enabled_tenants"`
60+
DisabledTenants flagext.StringSliceCSV `yaml:"disabled_tenants"`
5761
}
5862

5963
// RegisterFlags registers the Config flags.
@@ -62,6 +66,8 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
6266

6367
f.BoolVar(&cfg.ShardingEnabled, "store-gateway.sharding-enabled", false, "Shard blocks across multiple store gateway instances."+sharedOptionWithQuerier)
6468
f.StringVar(&cfg.ShardingStrategy, "store-gateway.sharding-strategy", util.ShardingStrategyDefault, fmt.Sprintf("The sharding strategy to use. Supported values are: %s.", strings.Join(supportedShardingStrategies, ", ")))
69+
f.Var(&cfg.EnabledTenants, "store-gateway.enabled_tenants", "Comma separated list of tenants whose store metrics this storegateway can process. If specified, only these tenants will be handled by storegateway, otherwise this storegateway will be enabled for all the tenants in the store-gateway cluster.")
70+
f.Var(&cfg.DisabledTenants, "store-gateway.disabled_tenants", "Comma separated list of tenants whose store metrics this storegateway cannot process. If specified, a storegateway that would normally pick the specified tenant(s) for processing will ignore them instead.")
6571
}
6672

6773
// Validate the Config.
@@ -99,6 +105,8 @@ type StoreGateway struct {
99105
subservicesWatcher *services.FailureWatcher
100106

101107
bucketSync *prometheus.CounterVec
108+
109+
allowedTenants *util.AllowedTenants
102110
}
103111

104112
func NewStoreGateway(gatewayCfg Config, storageCfg cortex_tsdb.BlocksStorageConfig, limits *validation.Overrides, logLevel logging.Level, logger log.Logger, reg prometheus.Registerer) (*StoreGateway, error) {
@@ -135,13 +143,21 @@ func newStoreGateway(gatewayCfg Config, storageCfg cortex_tsdb.BlocksStorageConf
135143
Name: "cortex_storegateway_bucket_sync_total",
136144
Help: "Total number of times the bucket sync operation triggered.",
137145
}, []string{"reason"}),
146+
allowedTenants: util.NewAllowedTenants(gatewayCfg.EnabledTenants, gatewayCfg.DisabledTenants),
138147
}
139148

140149
// Init metrics.
141150
g.bucketSync.WithLabelValues(syncReasonInitial)
142151
g.bucketSync.WithLabelValues(syncReasonPeriodic)
143152
g.bucketSync.WithLabelValues(syncReasonRingChange)
144153

154+
if len(gatewayCfg.EnabledTenants) > 0 {
155+
level.Info(g.logger).Log("msg", "storegateway using enabled users", "enabled", strings.Join(gatewayCfg.EnabledTenants, ", "))
156+
}
157+
if len(gatewayCfg.DisabledTenants) > 0 {
158+
level.Info(g.logger).Log("msg", "storegateway using disabled users", "disabled", strings.Join(gatewayCfg.DisabledTenants, ", "))
159+
}
160+
145161
// Init sharding strategy.
146162
var shardingStrategy ShardingStrategy
147163

0 commit comments

Comments
 (0)