Skip to content

Commit 917ddb5

Browse files
Re-add api url to ParseTablets()
1 parent 4f949a4 commit 917ddb5

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ 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-
VitessAPITimeoutSecs int // timeout for Vitess vtctld HTTP API
111+
VitessAPITimeoutSecs int // timeout for Vitess vtctld HTTP API(s)
112112
Stores StoresSettings
113113
}
114114

pkg/throttle/throttler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ func (throttler *Throttler) refreshMySQLInventory() error {
322322

323323
if !clusterSettings.VitessSettings.IsEmpty() {
324324
if throttler.vitessClient == nil {
325-
apiTimeout := time.Duration(config.Settings().VitessAPITimeoutSecs) * time.Second
326-
throttler.vitessClient = vitess.New(apiTimeout)
325+
throttler.vitessClient = vitess.New(
326+
time.Duration(config.Settings().VitessAPITimeoutSecs) * time.Second,
327+
)
327328
}
328329
log.Debugf("getting vitess data from %s", clusterSettings.VitessSettings.API)
329330
keyspace := clusterSettings.VitessSettings.Keyspace

pkg/vitess/api_client.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ func (t Tablet) IsValidReplica() bool {
2424
return t.Type == topodata.TabletType_REPLICA
2525
}
2626

27-
// Client gathers info from the Vitess API
28-
type Client struct {
29-
client *http.Client
30-
}
31-
32-
// New returns a new Client
33-
func New(apiTimeout time.Duration) *Client {
34-
return &Client{
35-
client: base.SetupHttpClient(apiTimeout),
36-
}
37-
}
38-
3927
func constructAPIURL(api string, keyspace string, shard string) (url string) {
4028
api = strings.TrimRight(api, "/")
4129
if !strings.HasSuffix(api, "/api") {
@@ -56,9 +44,21 @@ func filterReplicaTablets(tablets []Tablet) (replicas []Tablet) {
5644
return replicas
5745
}
5846

47+
// Client gathers info from the Vitess API
48+
type Client struct {
49+
client *http.Client
50+
}
51+
52+
// New returns a new Client
53+
func New(timeout time.Duration) *Client {
54+
return &Client{
55+
client: base.SetupHttpClient(timeout),
56+
}
57+
}
58+
5959
// ParseTablets reads from vitess /api/ks_tablets/<keyspace>/[shard] and returns a
6060
// listing (mysql_hostname, mysql_port, type) of REPLICA tablets
61-
func (c *Client) ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, err error) {
61+
func (c *Client) ParseTablets(api, keyspace, shard string) (tablets []Tablet, err error) {
6262
url := constructAPIURL(api, keyspace, shard)
6363
resp, err := c.client.Get(url)
6464
if err != nil {

pkg/vitess/api_client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ func TestParseTablets(t *testing.T) {
5050
}))
5151
defer vitessApi.Close()
5252

53-
vt := New(time.Second)
53+
vtClient := New(time.Second)
5454

5555
t.Run("success", func(t *testing.T) {
56-
tablets, err := vt.ParseTablets(vitessApi.URL, "test", "00")
56+
tablets, err := vtClient.ParseTablets(vitessApi.URL, "test", "00")
5757
if err != nil {
5858
t.Fatalf("Expected no error, got %q", err)
5959
}
@@ -68,7 +68,7 @@ func TestParseTablets(t *testing.T) {
6868
})
6969

7070
t.Run("not-found", func(t *testing.T) {
71-
tablets, err := vt.ParseTablets(vitessApi.URL, "not-found", "00")
71+
tablets, err := vtClient.ParseTablets(vitessApi.URL, "not-found", "00")
7272
if err != nil {
7373
t.Fatalf("Expected no error, got %q", err)
7474
}
@@ -80,7 +80,7 @@ func TestParseTablets(t *testing.T) {
8080

8181
t.Run("failed", func(t *testing.T) {
8282
vitessApi.Close() // kill the mock vitess API
83-
_, err := vt.ParseTablets(vitessApi.URL, "fail", "00")
83+
_, err := vtClient.ParseTablets(vitessApi.URL, "fail", "00")
8484
if err == nil {
8585
t.Fatal("Expected error, got nil")
8686
}

0 commit comments

Comments
 (0)