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 (
{{$p}} | +{{$p}} | |||
---|---|---|---|---|
{{.Addr}} | +{{.Hostname}} | +{{.Addr}} | {{.Affinity}} |