Skip to content

Commit a028184

Browse files
Vitess: include cells filter in Vtctld API call (#137)
* Vitess: send cell filter list to Vtctld API * Rename var * Rename var 2 * Use net/url for building URL
1 parent 5f347a4 commit a028184

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pkg/vitess/api_client.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io/ioutil"
77
"net/http"
8+
"net/url"
89
"strings"
910
"time"
1011

@@ -44,14 +45,21 @@ var httpClient = http.Client{
4445
Timeout: defaultTimeout,
4546
}
4647

47-
func constructAPIURL(settings config.VitessConfigurationSettings) (url string) {
48+
func constructAPIURL(settings config.VitessConfigurationSettings) (apiUrl string) {
4849
api := strings.TrimRight(settings.API, "/")
4950
if !strings.HasSuffix(api, "/api") {
5051
api = fmt.Sprintf("%s/api", api)
5152
}
52-
url = fmt.Sprintf("%s/keyspace/%s/tablets/%s", api, settings.Keyspace, settings.Shard)
53-
54-
return url
53+
queryParams := url.Values{}
54+
validCells := ParseCells(settings)
55+
if len(validCells) > 0 {
56+
queryParams.Add("cells", strings.Join(validCells, ","))
57+
}
58+
apiUrl = fmt.Sprintf("%s/keyspace/%s/tablets/%s", api, settings.Keyspace, settings.Shard)
59+
if len(queryParams) > 0 {
60+
apiUrl = fmt.Sprintf("%s?%s", apiUrl, queryParams.Encode())
61+
}
62+
return apiUrl
5563
}
5664

5765
// ParseCells returns a slice of non-empty Vitess cell names

pkg/vitess/api_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func TestParseTablets(t *testing.T) {
1616
vitessApi := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1717
switch r.URL.String() {
18-
case "/api/keyspace/test/tablets/00":
18+
case "/api/keyspace/test/tablets/00", "/api/keyspace/test/tablets/00?cells=cell2":
1919
data, _ := json.Marshal([]Tablet{
2020
{
2121
Alias: &topodata.TabletAlias{Cell: "cell1"},

0 commit comments

Comments
 (0)