Skip to content

Commit

Permalink
[ring_hash_policy_working] fixes not in ringhash folder
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Sep 14, 2021
1 parent 923ca92 commit 6c5199f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions xds/internal/balancer/clusterresolver/config.go
Expand Up @@ -23,8 +23,10 @@ import (
"fmt"
"strings"

"google.golang.org/grpc/balancer/roundrobin"
internalserviceconfig "google.golang.org/grpc/internal/serviceconfig"
"google.golang.org/grpc/serviceconfig"
"google.golang.org/grpc/xds/internal/balancer/ringhash"
)

// DiscoveryMechanismType is the type of discovery mechanism.
Expand Down Expand Up @@ -167,8 +169,8 @@ type LBConfig struct {
}

const (
rrName = "ROUND_ROBIN"
rhName = "RING_HASH"
rrName = roundrobin.Name
rhName = ringhash.Name
)

func parseConfig(c json.RawMessage) (*LBConfig, error) {
Expand Down
5 changes: 3 additions & 2 deletions xds/internal/balancer/clusterresolver/config_test.go
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc/internal/balancer/stub"
internalserviceconfig "google.golang.org/grpc/internal/serviceconfig"
"google.golang.org/grpc/xds/internal/balancer/ringhash"
)

func TestDiscoveryMechanismTypeMarshalJSON(t *testing.T) {
Expand Down Expand Up @@ -136,7 +137,7 @@ const (
"type": "EDS",
"edsServiceName": "test-eds-service-name"
}],
"xdsLbPolicy":[{"RING_HASH":{}}]
"xdsLbPolicy":[{"ring_hash_experimental":{}}]
}`
testJSONConfig5 = `{
"discoveryMechanisms": [{
Expand Down Expand Up @@ -234,7 +235,7 @@ func TestParseConfig(t *testing.T) {
},
},
XDSLBPolicy: &internalserviceconfig.BalancerConfig{
Name: "RING_HASH",
Name: ringhash.Name,
Config: nil,
},
},
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/resolver/serviceconfig.go
Expand Up @@ -226,7 +226,7 @@ func (cs *configSelector) generateHash(rpcInfo iresolver.RPCInfo, hashPolicies [
var generatedPolicyHash bool
switch policy.HashPolicyType {
case xdsclient.HashPolicyTypeHeader:
md, ok := metadata.FromIncomingContext(rpcInfo.Context)
md, ok := metadata.FromOutgoingContext(rpcInfo.Context)
if !ok {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/resolver/serviceconfig_test.go
Expand Up @@ -73,7 +73,7 @@ func (s) TestGenerateRequestHash(t *testing.T) {
}},
requestHashWant: xxhash.Sum64String("/new-products"),
rpcInfo: iresolver.RPCInfo{
Context: metadata.NewIncomingContext(context.Background(), metadata.Pairs(":path", "/products")),
Context: metadata.NewOutgoingContext(context.Background(), metadata.Pairs(":path", "/products")),
Method: "/some-method",
},
},
Expand Down Expand Up @@ -101,7 +101,7 @@ func (s) TestGenerateRequestHash(t *testing.T) {
}},
requestHashWant: xxhash.Sum64String("eaebece"),
rpcInfo: iresolver.RPCInfo{
Context: metadata.NewIncomingContext(context.Background(), metadata.Pairs(":path", "abc")),
Context: metadata.NewOutgoingContext(context.Background(), metadata.Pairs(":path", "abc")),
Method: "/some-method",
},
},
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/resolver/xds_resolver_test.go
Expand Up @@ -510,7 +510,7 @@ func (s) TestXDSResolverRequestHash(t *testing.T) {
}
// Selecting a config when there was a hash policy specified in the route
// that will be selected should put a request hash in the config's context.
res, err := cs.SelectConfig(iresolver.RPCInfo{Context: metadata.NewIncomingContext(context.Background(), metadata.Pairs(":path", "/products"))})
res, err := cs.SelectConfig(iresolver.RPCInfo{Context: metadata.NewOutgoingContext(context.Background(), metadata.Pairs(":path", "/products"))})
if err != nil {
t.Fatalf("Unexpected error from cs.SelectConfig(_): %v", err)
}
Expand Down

0 comments on commit 6c5199f

Please sign in to comment.