Skip to content

Commit 126e476

Browse files
Allow Vitess HTTP client timeout override
1 parent 32efe2d commit 126e476

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

pkg/config/config.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,23 @@ type ConfigurationSettings struct {
108108
BackendMySQLPassword string
109109
MemcacheServers []string // if given, freno will report to aggregated values to given memcache
110110
MemcachePath string // use as prefix to metric path in memcache key, e.g. if `MemcachePath` is "myprefix" the key would be "myprefix/mysql/maincluster". Default: "freno"
111+
VitessHTTPTimeoutSec int
111112
Stores StoresSettings
112113
}
113114

114115
func newConfigurationSettings() *ConfigurationSettings {
115116
return &ConfigurationSettings{
116-
ListenPort: 8087,
117-
RaftBind: "127.0.0.1:10008",
118-
RaftDataDir: "",
119-
DefaultRaftPort: 0,
120-
RaftNodes: []string{},
121-
BackendMySQLHost: "",
122-
BackendMySQLSchema: "",
123-
BackendMySQLPort: 3306,
124-
MemcacheServers: []string{},
125-
MemcachePath: "freno",
117+
ListenPort: 8087,
118+
RaftBind: "127.0.0.1:10008",
119+
RaftDataDir: "",
120+
DefaultRaftPort: 0,
121+
RaftNodes: []string{},
122+
BackendMySQLHost: "",
123+
BackendMySQLSchema: "",
124+
BackendMySQLPort: 3306,
125+
MemcacheServers: []string{},
126+
MemcachePath: "freno",
127+
VitessHTTPTimeoutSec: 3,
126128
//Debug: false,
127129
//ListenSocket: "",
128130
//AnExampleListOfStrings: []string{"*"},

pkg/throttle/throttler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ func (throttler *Throttler) refreshMySQLInventory() error {
323323
log.Debugf("getting vitess data from %s", clusterSettings.VitessSettings.API)
324324
keyspace := clusterSettings.VitessSettings.Keyspace
325325
shard := clusterSettings.VitessSettings.Shard
326-
tablets, err := vitess.ParseTablets(clusterSettings.VitessSettings.API, keyspace, shard)
326+
vtManager := vitess.NewManager(config.Settings().VitessHTTPTimeoutSec)
327+
tablets, err := vtManager.ParseTablets(clusterSettings.VitessSettings.API, keyspace, shard)
327328
if err != nil {
328329
return log.Errorf("Unable to get vitess hosts from %s, %s/%s: %+v", clusterSettings.VitessSettings.API, keyspace, shard, err)
329330
}

pkg/vitess/api_client.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ type Tablet struct {
1515
MysqlPort int32 `json:"mysql_port,omitempty"`
1616
}
1717

18-
var httpClient = http.Client{
19-
Timeout: 1 * time.Second,
18+
// Manager gathers info from Vitess
19+
type Manager struct {
20+
httpClient http.Client
21+
}
22+
23+
// NewManager returns a new manager for Vitess
24+
func NewManager(timeoutSec int) *Manager {
25+
return &Manager{httpClient: http.Client{
26+
Timeout: time.Duration(timeoutSec) * time.Second,
27+
}}
2028
}
2129

2230
func constructAPIURL(api string, keyspace string, shard string) (url string) {
@@ -31,9 +39,9 @@ func constructAPIURL(api string, keyspace string, shard string) (url string) {
3139

3240
// ParseTablets reads from vitess /api/ks_tablets/<keyspace>/[shard] and returns a
3341
// tblet (mysql_hostname, mysql_port) listing
34-
func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, err error) {
42+
func (m *Manager) ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, err error) {
3543
url := constructAPIURL(api, keyspace, shard)
36-
resp, err := httpClient.Get(url)
44+
resp, err := m.httpClient.Get(url)
3745
if err != nil {
3846
return tablets, err
3947
}

0 commit comments

Comments
 (0)