From 39cc18a7446cf0c3d1d1ad7a617a8a6eb6e45d46 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Fri, 4 Jun 2021 15:40:06 -0700 Subject: [PATCH] [c2p_id_random] c2p: add random number to xDS node ID in google-c2p resolver --- xds/googledirectpath/googlec2p.go | 5 ++++- xds/googledirectpath/googlec2p_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/xds/googledirectpath/googlec2p.go b/xds/googledirectpath/googlec2p.go index b514f03bfbfa..b320c5b0f9e5 100644 --- a/xds/googledirectpath/googlec2p.go +++ b/xds/googledirectpath/googlec2p.go @@ -27,6 +27,7 @@ package googledirectpath import ( "fmt" + "math/rand" "time" v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" @@ -152,13 +153,15 @@ var ipv6EnabledMetadata = &structpb.Struct{ }, } +var id = fmt.Sprintf("C2P-%d", rand.Int()) + // newNode makes a copy of defaultNode, and populate it's Metadata and // Locality fields. func newNode(zone string, ipv6Capable bool) *v3corepb.Node { ret := &v3corepb.Node{ // Not all required fields are set in defaultNote. Metadata will be set // if ipv6 is enabled. Locality will be set to the value from metadata. - Id: "C2P", + Id: id, UserAgentName: gRPCUserAgentName, UserAgentVersionType: &v3corepb.Node_UserAgentVersion{UserAgentVersion: grpc.Version}, ClientFeatures: []string{clientFeatureNoOverprovisioning}, diff --git a/xds/googledirectpath/googlec2p_test.go b/xds/googledirectpath/googlec2p_test.go index 5b8085ef34c3..fb68fa23a1d0 100644 --- a/xds/googledirectpath/googlec2p_test.go +++ b/xds/googledirectpath/googlec2p_test.go @@ -194,7 +194,7 @@ func TestBuildXDS(t *testing.T) { } wantNode := &v3corepb.Node{ - Id: "C2P", + Id: id, Metadata: nil, Locality: &v3corepb.Locality{Zone: testZone}, UserAgentName: gRPCUserAgentName,