Skip to content

Commit

Permalink
only pass through the URL params we need
Browse files Browse the repository at this point in the history
  • Loading branch information
demmer committed Mar 23, 2024
1 parent bb3a83c commit 19d06e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
3 changes: 0 additions & 3 deletions go/vt/vtgateproxy/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ func RegisterJsonDiscovery() {
log.Infof("Registered JSON discovery scheme %v to watch: %v\n", jsonDiscovery.Scheme(), *jsonDiscoveryConfig)
}

type hostFilters = map[string]string

// exampleResolver is a
// Resolver(https://godoc.org/google.golang.org/grpc/resolver#Resolver).
type JSONGateConfigResolver struct {
target resolver.Target
Expand Down
27 changes: 18 additions & 9 deletions go/vt/vtgateproxy/vtgateproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,31 @@ func (proxy *VTGateProxy) getConnection(ctx context.Context, target string) (*vt

func (proxy *VTGateProxy) NewSession(ctx context.Context, options *querypb.ExecuteOptions, connectionAttributes map[string]string) (*vtgateconn.VTGateSession, error) {

if *poolTypeAttr != "" {
_, ok := connectionAttributes[*poolTypeAttr]
if !ok {
return nil, vterrors.Errorf(vtrpcpb.Code_UNAVAILABLE, "pool type attribute %s not supplied by client", *poolTypeAttr)
}
}

targetUrl := url.URL{
Scheme: "vtgate",
Host: "pool",
}

values := url.Values{}
for k, v := range connectionAttributes {
values.Set(k, v)

if *poolTypeAttr != "" {
poolType, ok := connectionAttributes[*poolTypeAttr]
if ok {
values.Set(*poolTypeAttr, poolType)
} else {
return nil, vterrors.Errorf(vtrpcpb.Code_UNAVAILABLE, "pool type attribute %s not supplied by client", *poolTypeAttr)
}
}

if *affinityAttr != "" {
affinity, ok := connectionAttributes[*affinityAttr]
if ok {
values.Set(*affinityAttr, affinity)
} else {
return nil, vterrors.Errorf(vtrpcpb.Code_UNAVAILABLE, "pool type attribute %s not supplied by client", *affinityAttr)
}
}

targetUrl.RawQuery = values.Encode()

conn, err := proxy.getConnection(ctx, targetUrl.String())
Expand Down

0 comments on commit 19d06e2

Please sign in to comment.