github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/chunk/table_provisioning.go (about) 1 package chunk 2 3 import "flag" 4 5 // ProvisionConfig holds config for provisioning capacity for index and chunk tables (on DynamoDB for now) 6 type ProvisionConfig struct { 7 ActiveTableProvisionConfig `yaml:",inline"` 8 InactiveTableProvisionConfig `yaml:",inline"` 9 } 10 11 // RegisterFlags adds the flags required to config this to the given FlagSet. 12 func (cfg *ProvisionConfig) RegisterFlags(argPrefix string, f *flag.FlagSet) { 13 // defaults for ActiveTableProvisionConfig 14 cfg.ProvisionedWriteThroughput = 1000 15 cfg.ProvisionedReadThroughput = 300 16 cfg.ProvisionedThroughputOnDemandMode = false 17 18 cfg.ActiveTableProvisionConfig.RegisterFlags(argPrefix, f) 19 cfg.InactiveTableProvisionConfig.RegisterFlags(argPrefix, f) 20 } 21 22 type ActiveTableProvisionConfig struct { 23 ProvisionedThroughputOnDemandMode bool `yaml:"enable_ondemand_throughput_mode"` 24 ProvisionedWriteThroughput int64 `yaml:"provisioned_write_throughput"` 25 ProvisionedReadThroughput int64 `yaml:"provisioned_read_throughput"` 26 27 WriteScale AutoScalingConfig `yaml:"write_scale"` 28 ReadScale AutoScalingConfig `yaml:"read_scale"` 29 } 30 31 // RegisterFlags adds the flags required to config this to the given FlagSet. 32 // Make sure defaults are set in the respective fields before calling RegisterFlags. 33 func (cfg *ActiveTableProvisionConfig) RegisterFlags(argPrefix string, f *flag.FlagSet) { 34 f.Int64Var(&cfg.ProvisionedWriteThroughput, argPrefix+".write-throughput", cfg.ProvisionedWriteThroughput, "Table default write throughput. Supported by DynamoDB") 35 f.Int64Var(&cfg.ProvisionedReadThroughput, argPrefix+".read-throughput", cfg.ProvisionedReadThroughput, "Table default read throughput. Supported by DynamoDB") 36 f.BoolVar(&cfg.ProvisionedThroughputOnDemandMode, argPrefix+".enable-ondemand-throughput-mode", cfg.ProvisionedThroughputOnDemandMode, "Enables on demand throughput provisioning for the storage provider (if supported). Applies only to tables which are not autoscaled. Supported by DynamoDB") 37 38 cfg.WriteScale.RegisterFlags(argPrefix+".write-throughput.scale", f) 39 cfg.ReadScale.RegisterFlags(argPrefix+".read-throughput.scale", f) 40 } 41 42 type InactiveTableProvisionConfig struct { 43 InactiveThroughputOnDemandMode bool `yaml:"enable_inactive_throughput_on_demand_mode"` 44 InactiveWriteThroughput int64 `yaml:"inactive_write_throughput"` 45 InactiveReadThroughput int64 `yaml:"inactive_read_throughput"` 46 47 InactiveWriteScale AutoScalingConfig `yaml:"inactive_write_scale"` 48 InactiveReadScale AutoScalingConfig `yaml:"inactive_read_scale"` 49 50 InactiveWriteScaleLastN int64 `yaml:"inactive_write_scale_lastn"` 51 InactiveReadScaleLastN int64 `yaml:"inactive_read_scale_lastn"` 52 } 53 54 // RegisterFlags adds the flags required to config this to the given FlagSet. 55 func (cfg *InactiveTableProvisionConfig) RegisterFlags(argPrefix string, f *flag.FlagSet) { 56 f.Int64Var(&cfg.InactiveWriteThroughput, argPrefix+".inactive-write-throughput", 1, "Table write throughput for inactive tables. Supported by DynamoDB") 57 f.Int64Var(&cfg.InactiveReadThroughput, argPrefix+".inactive-read-throughput", 300, "Table read throughput for inactive tables. Supported by DynamoDB") 58 f.BoolVar(&cfg.InactiveThroughputOnDemandMode, argPrefix+".inactive-enable-ondemand-throughput-mode", false, "Enables on demand throughput provisioning for the storage provider (if supported). Applies only to tables which are not autoscaled. Supported by DynamoDB") 59 60 cfg.InactiveWriteScale.RegisterFlags(argPrefix+".inactive-write-throughput.scale", f) 61 cfg.InactiveReadScale.RegisterFlags(argPrefix+".inactive-read-throughput.scale", f) 62 63 f.Int64Var(&cfg.InactiveWriteScaleLastN, argPrefix+".inactive-write-throughput.scale-last-n", 4, "Number of last inactive tables to enable write autoscale.") 64 f.Int64Var(&cfg.InactiveReadScaleLastN, argPrefix+".inactive-read-throughput.scale-last-n", 4, "Number of last inactive tables to enable read autoscale.") 65 } 66 67 func (cfg ActiveTableProvisionConfig) BuildTableDesc(tableName string, tags Tags) TableDesc { 68 table := TableDesc{ 69 Name: tableName, 70 ProvisionedRead: cfg.ProvisionedReadThroughput, 71 ProvisionedWrite: cfg.ProvisionedWriteThroughput, 72 UseOnDemandIOMode: cfg.ProvisionedThroughputOnDemandMode, 73 Tags: tags, 74 } 75 76 if cfg.WriteScale.Enabled { 77 table.WriteScale = cfg.WriteScale 78 table.UseOnDemandIOMode = false 79 } 80 81 if cfg.ReadScale.Enabled { 82 table.ReadScale = cfg.ReadScale 83 table.UseOnDemandIOMode = false 84 } 85 86 return table 87 } 88 89 func (cfg InactiveTableProvisionConfig) BuildTableDesc(tableName string, tags Tags, disableAutoscale bool) TableDesc { 90 table := TableDesc{ 91 Name: tableName, 92 ProvisionedRead: cfg.InactiveReadThroughput, 93 ProvisionedWrite: cfg.InactiveWriteThroughput, 94 UseOnDemandIOMode: cfg.InactiveThroughputOnDemandMode, 95 Tags: tags, 96 } 97 98 if !disableAutoscale { 99 if cfg.InactiveWriteScale.Enabled { 100 table.WriteScale = cfg.InactiveWriteScale 101 table.UseOnDemandIOMode = false 102 } 103 104 if cfg.InactiveReadScale.Enabled { 105 table.ReadScale = cfg.InactiveReadScale 106 table.UseOnDemandIOMode = false 107 } 108 } 109 110 return table 111 }