From 01d10fff845a00d29591e19d6fb5003d3013c8f1 Mon Sep 17 00:00:00 2001 From: Michael Demmer Date: Tue, 21 May 2024 09:13:03 -0700 Subject: [PATCH] include vtgate hostname in debug page (#345) --- 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 ee5512830ea..2d78e00e748 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 @@ -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] @@ -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) } @@ -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) } @@ -433,10 +439,11 @@ const ( {{range $i, $p := .Pools}} - + {{range index $.Targets $p}} - + + {{end}} {{end}}
{{$p}}{{$p}}
{{.Addr}}{{.Hostname}}{{.Addr}} {{.Affinity}}