diff --git a/xds/internal/balancer/lrs/lrs_test.go b/xds/internal/balancer/lrs/lrs_test.go index 09b22ac9..b18c3d7e 100644 --- a/xds/internal/balancer/lrs/lrs_test.go +++ b/xds/internal/balancer/lrs/lrs_test.go @@ -39,6 +39,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/grpc/xds/internal" + "google.golang.org/grpc/xds/internal/testutils" ) const ( @@ -286,7 +287,7 @@ func Test_lrsStore_buildStats_rpcCounts(t *testing.T) { ) } upstreamLocalityStats = append(upstreamLocalityStats, &endpointpb.UpstreamLocalityStats{ - Locality: l.ToProto(), + Locality: testutils.LocalityIDToProto(l), TotalSuccessfulRequests: count.success, TotalRequestsInProgress: tempInProgress, TotalErrorRequests: count.failure, @@ -298,7 +299,7 @@ func Test_lrsStore_buildStats_rpcCounts(t *testing.T) { for l, c := range inProgressCounts { if _, ok := counts[l]; !ok { upstreamLocalityStats = append(upstreamLocalityStats, &endpointpb.UpstreamLocalityStats{ - Locality: l.ToProto(), + Locality: testutils.LocalityIDToProto(l), TotalRequestsInProgress: c, }) } diff --git a/xds/internal/internal.go b/xds/internal/internal.go index b2c98000..8b17cf93 100644 --- a/xds/internal/internal.go +++ b/xds/internal/internal.go @@ -21,8 +21,6 @@ package internal import ( "fmt" - - corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" ) type clientID string @@ -49,12 +47,3 @@ type LocalityID struct { func (l LocalityID) String() string { return fmt.Sprintf("%s-%s-%s", l.Region, l.Zone, l.SubZone) } - -// ToProto convert Locality to the proto representation. -func (l LocalityID) ToProto() *corepb.Locality { - return &corepb.Locality{ - Region: l.Region, - Zone: l.Zone, - SubZone: l.SubZone, - } -} diff --git a/xds/internal/testutils/locality.go b/xds/internal/testutils/locality.go new file mode 100644 index 00000000..a4e4cc59 --- /dev/null +++ b/xds/internal/testutils/locality.go @@ -0,0 +1,32 @@ +/* + * + * Copyright 2020 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package testutils + +import ( + corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" + "google.golang.org/grpc/xds/internal" +) + +// LocalityIDToProto converts a LocalityID to its proto representation. +func LocalityIDToProto(l internal.LocalityID) *corepb.Locality { + return &corepb.Locality{ + Region: l.Region, + Zone: l.Zone, + SubZone: l.SubZone, + } +}