Skip to content
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

vtgateproxy: include vtgate hostname in debug page #345

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions go/vt/vtgateproxy/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type JSONGateResolverBuilder struct {
}

type targetHost struct {
Hostname string
Addr string
PoolType string
Affinity string
Expand Down Expand Up @@ -244,6 +245,7 @@ func (b *JSONGateResolverBuilder) parse() (bool, error) {

var targets = map[string][]targetHost{}
for _, host := range hosts {
hostname, hasHostname := host["host"]
address, hasAddress := host[b.addressField]
port, hasPort := host[b.portField]
poolType, hasPoolType := host[b.poolTypeField]
Expand All @@ -257,6 +259,10 @@ func (b *JSONGateResolverBuilder) parse() (bool, error) {
return false, fmt.Errorf("error parsing JSON discovery file %s: port field %s not present", b.jsonPath, b.portField)
}

if !hasHostname {
hostname = address
}

if b.poolTypeField != "" && !hasPoolType {
return false, fmt.Errorf("error parsing JSON discovery file %s: pool type field %s not present", b.jsonPath, b.poolTypeField)
}
Expand All @@ -283,7 +289,7 @@ func (b *JSONGateResolverBuilder) parse() (bool, error) {
return false, fmt.Errorf("error parsing JSON discovery file %s: port field %s has invalid value %v", b.jsonPath, b.portField, port)
}

target := targetHost{fmt.Sprintf("%s:%s", address, port), poolType.(string), affinity.(string)}
target := targetHost{hostname.(string), fmt.Sprintf("%s:%s", address, port), poolType.(string), affinity.(string)}
targets[target.PoolType] = append(targets[target.PoolType], target)
}

Expand Down Expand Up @@ -423,10 +429,11 @@ const (
</style>
<table>
{{range $i, $p := .Pools}} <tr>
<th colspan="2">{{$p}}</th>
<th colspan="3">{{$p}}</th>
</tr>
{{range index $.Targets $p}} <tr>
<td>{{.Addr}}</td>
<td>{{.Hostname}}</td>
<td>{{.Addr}}</td>
<td>{{.Affinity}}</td>
</tr>{{end}}
{{end}}
Expand Down
Loading