Skip to content

Commit

Permalink
include vtgate hostname in debug page
Browse files Browse the repository at this point in the history
  • Loading branch information
demmer committed May 15, 2024
1 parent 10d4525 commit 7a74f22
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit 7a74f22

Please sign in to comment.