From 7a74f22c839a0e559256236cd915231eebfa31fc Mon Sep 17 00:00:00 2001 From: Michael Demmer Date: Wed, 15 May 2024 07:33:39 -0700 Subject: [PATCH] include vtgate hostname in debug page --- go/vt/vtgateproxy/discovery.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/go/vt/vtgateproxy/discovery.go b/go/vt/vtgateproxy/discovery.go index a4b48340bfd..f8a596a9cee 100644 --- a/go/vt/vtgateproxy/discovery.go +++ b/go/vt/vtgateproxy/discovery.go @@ -88,6 +88,7 @@ type JSONGateResolverBuilder struct { } type targetHost struct { + Hostname string Addr string PoolType string Affinity string @@ -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] @@ -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) } @@ -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) } @@ -423,10 +429,11 @@ const ( {{range $i, $p := .Pools}} - + {{range index $.Targets $p}} - + + {{end}} {{end}}
{{$p}}{{$p}}
{{.Addr}}{{.Hostname}}{{.Addr}} {{.Affinity}}