Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throttler: refactor global configuration setting as throttler member #14853

Merged
merged 1 commit into from
Dec 26, 2023
Merged
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
9 changes: 3 additions & 6 deletions go/vt/vttablet/tabletserver/throttle/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ limitations under the License.

package config

// Instance is the one configuration for the throttler
var Instance = &ConfigurationSettings{}

// Settings returns the settings of the global instance of Configuration
func Settings() *ConfigurationSettings {
return Instance
// NewConfigurationSettings creates new throttler configuration settings.
func NewConfigurationSettings() *ConfigurationSettings {
return &ConfigurationSettings{}
}

// ConfigurationSettings models a set of configurable values, that can be
Expand Down
11 changes: 6 additions & 5 deletions go/vt/vttablet/tabletserver/throttle/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ type Throttler struct {
mysqlAggregateInterval time.Duration
throttledAppsSnapshotInterval time.Duration

configSettings *config.ConfigurationSettings
env tabletenv.Env
pool *connpool.Pool
tabletTypeFunc func() topodatapb.TabletType
Expand Down Expand Up @@ -308,20 +309,20 @@ func (throttler *Throttler) GetMetricsThreshold() float64 {
func (throttler *Throttler) initConfig() {
log.Infof("Throttler: initializing config")

config.Instance = &config.ConfigurationSettings{
throttler.configSettings = &config.ConfigurationSettings{
Stores: config.StoresSettings{
MySQL: config.MySQLConfigurationSettings{
IgnoreDialTCPErrors: true,
Clusters: map[string](*config.MySQLClusterConfigurationSettings){},
},
},
}
config.Instance.Stores.MySQL.Clusters[selfStoreName] = &config.MySQLClusterConfigurationSettings{
throttler.configSettings.Stores.MySQL.Clusters[selfStoreName] = &config.MySQLClusterConfigurationSettings{
MetricQuery: throttler.GetMetricsQuery(),
ThrottleThreshold: &throttler.MetricsThreshold,
IgnoreHostsCount: 0,
}
config.Instance.Stores.MySQL.Clusters[shardStoreName] = &config.MySQLClusterConfigurationSettings{
throttler.configSettings.Stores.MySQL.Clusters[shardStoreName] = &config.MySQLClusterConfigurationSettings{
MetricQuery: throttler.GetMetricsQuery(),
ThrottleThreshold: &throttler.MetricsThreshold,
IgnoreHostsCount: 0,
Expand Down Expand Up @@ -857,7 +858,7 @@ func (throttler *Throttler) refreshMySQLInventory(ctx context.Context) error {
}
}

for clusterName, clusterSettings := range config.Settings().Stores.MySQL.Clusters {
for clusterName, clusterSettings := range throttler.configSettings.Stores.MySQL.Clusters {
clusterName := clusterName
clusterSettings.MetricQuery = metricsQuery
clusterSettings.ThrottleThreshold.Store(metricsThreshold)
Expand Down Expand Up @@ -931,7 +932,7 @@ func (throttler *Throttler) aggregateMySQLMetrics(ctx context.Context) error {
metricName := fmt.Sprintf("mysql/%s", clusterName)
ignoreHostsCount := throttler.mysqlInventory.IgnoreHostsCount[clusterName]
ignoreHostsThreshold := throttler.mysqlInventory.IgnoreHostsThreshold[clusterName]
aggregatedMetric := aggregateMySQLProbes(ctx, probes, clusterName, throttler.mysqlInventory.TabletMetrics, ignoreHostsCount, config.Settings().Stores.MySQL.IgnoreDialTCPErrors, ignoreHostsThreshold)
aggregatedMetric := aggregateMySQLProbes(ctx, probes, clusterName, throttler.mysqlInventory.TabletMetrics, ignoreHostsCount, throttler.configSettings.Stores.MySQL.IgnoreDialTCPErrors, ignoreHostsThreshold)
throttler.aggregatedMetrics.Set(metricName, aggregatedMetric, cache.DefaultExpiration)
}
return nil
Expand Down
13 changes: 8 additions & 5 deletions go/vt/vttablet/tabletserver/throttle/throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ func (w FakeHeartbeatWriter) RequestHeartbeats() {

func newTestThrottler() *Throttler {
metricsQuery := "select 1"
config.Settings().Stores.MySQL.Clusters = map[string]*config.MySQLClusterConfigurationSettings{
configSettings := config.NewConfigurationSettings()
configSettings.Stores.MySQL.Clusters = map[string]*config.MySQLClusterConfigurationSettings{
selfStoreName: {},
shardStoreName: {},
}
clusters := config.Settings().Stores.MySQL.Clusters
for _, s := range clusters {
for _, s := range configSettings.Stores.MySQL.Clusters {
s.MetricQuery = metricsQuery
s.ThrottleThreshold = &atomic.Uint64{}
s.ThrottleThreshold.Store(1)
Expand All @@ -121,6 +121,7 @@ func newTestThrottler() *Throttler {
tabletTypeFunc: func() topodatapb.TabletType { return topodatapb.TabletType_PRIMARY },
overrideTmClient: &fakeTMClient{},
}
throttler.configSettings = configSettings
throttler.mysqlThrottleMetricChan = make(chan *mysql.MySQLThrottleMetric)
throttler.mysqlInventoryChan = make(chan *mysql.Inventory, 1)
throttler.mysqlClusterProbesChan = make(chan *mysql.ClusterProbes)
Expand Down Expand Up @@ -222,24 +223,26 @@ func TestIsAppExempted(t *testing.T) {
// `PRIMARY` tablet, probes other tablets). On the leader, the list is expected to be non-empty.
func TestRefreshMySQLInventory(t *testing.T) {
metricsQuery := "select 1"
config.Settings().Stores.MySQL.Clusters = map[string]*config.MySQLClusterConfigurationSettings{
configSettings := config.NewConfigurationSettings()
clusters := map[string]*config.MySQLClusterConfigurationSettings{
selfStoreName: {},
"ks1": {},
"ks2": {},
}
clusters := config.Settings().Stores.MySQL.Clusters
for _, s := range clusters {
s.MetricQuery = metricsQuery
s.ThrottleThreshold = &atomic.Uint64{}
s.ThrottleThreshold.Store(1)
}
configSettings.Stores.MySQL.Clusters = clusters

throttler := &Throttler{
mysqlClusterProbesChan: make(chan *mysql.ClusterProbes),
mysqlClusterThresholds: cache.New(cache.NoExpiration, 0),
ts: &FakeTopoServer{},
mysqlInventory: mysql.NewInventory(),
}
throttler.configSettings = configSettings
throttler.metricsQuery.Store(metricsQuery)
throttler.initThrottleTabletTypes()

Expand Down
Loading