Skip to content

Commit

Permalink
include vtgate hostname in debug page (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
demmer authored May 21, 2024
1 parent 62f39e4 commit 01d10ff
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 @@ -242,6 +243,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 @@ -255,6 +257,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 @@ -281,7 +287,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 @@ -433,10 +439,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 01d10ff

Please sign in to comment.