-
Notifications
You must be signed in to change notification settings - Fork 55
Getting hosts from vitess API #70
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package config | ||
|
|
||
| // | ||
| // HAProxy-specific configuration | ||
| // | ||
|
|
||
| type VitessConfigurationSettings struct { | ||
| API string | ||
| Keyspace string | ||
| Shard string | ||
| } | ||
|
|
||
| func (settings *VitessConfigurationSettings) IsEmpty() bool { | ||
| if settings.API == "" { | ||
| return true | ||
| } | ||
| if settings.Keyspace == "" { | ||
| return true | ||
| } | ||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package vitess | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "io/ioutil" | ||
| "net/http" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| // Tablet represents information about a running instance of vttablet. | ||
| type Tablet struct { | ||
| MysqlHostname string `json:"mysql_hostname,omitempty"` | ||
| MysqlPort int32 `json:"mysql_port,omitempty"` | ||
| } | ||
|
|
||
| var httpClient = http.Client{ | ||
| Timeout: 1 * time.Second, | ||
| } | ||
|
|
||
| func constructAPIURL(api string, keyspace string, shard string) (url string) { | ||
| api = strings.TrimRight(api, "/") | ||
| if !strings.HasSuffix(api, "/api") { | ||
| api = fmt.Sprintf("%s/api", api) | ||
| } | ||
| url = fmt.Sprintf("%s/ks_tablets/%s/%s", api, keyspace, shard) | ||
|
|
||
| return url | ||
| } | ||
|
|
||
| // ParseTablets reads from vitess /api/ks_tablets/<keyspace>/[shard] and returns a | ||
| // tblet (mysql_hostname, mysql_port) listing | ||
| func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, err error) { | ||
| url := constructAPIURL(api, keyspace, shard) | ||
| resp, err := httpClient.Get(url) | ||
| if err != nil { | ||
| return tablets, err | ||
| } | ||
|
|
||
| defer resp.Body.Close() | ||
| body, err := ioutil.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return tablets, err | ||
| } | ||
|
|
||
| err = json.Unmarshal(body, &tablets) | ||
| return tablets, err | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you connecting to consul and directly reading the data from there? That seems like it will miss tablets that are in different cells than the consul service you're attached to. It seems like this could break if vitess decides to change their data structure, and it won't work if someone decides to use another key storage system like
etcdorzookeeperwhich are also supported by vitess.I have an example of how to call the vitess client through gRPC here that may be helpful as an alternative:
<redacted>There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gtowey
frenodoes not read data from Consul here. It accesses a newvtctldWeb API endpoint. That endpoint only exists in our internal Vitess code right now, but once tested for a few days it will be shared upstream, at which point I will drop a link in this public repo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I wasn't aware
vtctldhad a web api -- I thought it was all through grpc. Well then, carry on =)