Support polling a specific Vitess cell · github/freno@42d5227 · GitHub
Skip to content

Commit 42d5227

Browse files
Support polling a specific Vitess cell
1 parent 5f8f6db commit 42d5227

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

‎pkg/config/mysql_config.go‎

Lines changed: 4 additions & 0 deletions

‎pkg/config/vitess_config.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package config
66

77
type VitessConfigurationSettings struct {
88
API string
9+
Cell string
910
Keyspace string
1011
Shard string
1112
TimeoutSecs uint

‎pkg/vitess/api_client.go‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ const defaultTimeout = time.Duration(5) * time.Second
1616

1717
// Tablet represents information about a running instance of vttablet.
1818
type Tablet struct {
19-
MysqlHostname string `json:"mysql_hostname,omitempty"`
20-
MysqlPort int32 `json:"mysql_port,omitempty"`
21-
Type topodata.TabletType `json:"type,omitempty"`
19+
Alias *topodata.TabletAlias `json:"alias,omitempty"`
20+
MysqlHostname string `json:"mysql_hostname,omitempty"`
21+
MysqlPort int32 `json:"mysql_port,omitempty"`
22+
Type topodata.TabletType `json:"type,omitempty"`
2223
}
2324

2425
// IsValidReplica returns a bool reflecting if a tablet type is REPLICA
@@ -41,8 +42,11 @@ func constructAPIURL(settings config.VitessConfigurationSettings) (url string) {
4142
}
4243

4344
// filterReplicaTablets parses a list of tablets, returning replica tablets only
44-
func filterReplicaTablets(tablets []Tablet) (replicas []Tablet) {
45+
func filterReplicaTablets(settings config.VitessConfigurationSettings, tablets []Tablet) (replicas []Tablet) {
4546
for _, tablet := range tablets {
47+
if settings.Cell != "" && tablet.Alias.Cell != settings.Cell {
48+
continue
49+
}
4650
if tablet.IsValidReplica() {
4751
replicas = append(replicas, tablet)
4852
}
@@ -72,5 +76,5 @@ func ParseTablets(settings config.VitessConfigurationSettings) (tablets []Tablet
7276
}
7377

7478
err = json.Unmarshal(body, &tablets)
75-
return filterReplicaTablets(tablets), err
79+
return filterReplicaTablets(settings, tablets), err
7680
}

‎pkg/vitess/api_client_test.go‎

Lines changed: 33 additions & 3 deletions

0 commit comments

Comments
 (0)