@@ -24,6 +24,7 @@ import (
24
24
25
25
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
26
26
"github.com/google/go-cmp/cmp"
27
+ "github.com/google/go-cmp/cmp/cmpopts"
27
28
"github.com/google/uuid"
28
29
"google.golang.org/grpc/internal/testutils/xds/fakeserver"
29
30
"google.golang.org/grpc/xds/internal/testutils"
@@ -35,6 +36,22 @@ import (
35
36
v3lrspb "github.com/envoyproxy/go-control-plane/envoy/service/load_stats/v3"
36
37
)
37
38
39
+ const (
40
+ testLocality1 = `{"region":"test-region1"}`
41
+ testLocality2 = `{"region":"test-region2"}`
42
+ testKey1 = "test-key1"
43
+ testKey2 = "test-key2"
44
+ )
45
+
46
+ var (
47
+ toleranceCmpOpt = cmpopts .EquateApprox (0 , 1e-5 )
48
+ ignoreOrderCmpOpt = protocmp .FilterField (& v3endpointpb.ClusterStats {}, "upstream_locality_stats" ,
49
+ cmpopts .SortSlices (func (a , b protocmp.Message ) bool {
50
+ return a .String () < b .String ()
51
+ }),
52
+ )
53
+ )
54
+
38
55
func (s ) TestReportLoad (t * testing.T ) {
39
56
// Create a fake xDS management server listening on a local port.
40
57
mgmtServer , cleanup := startFakeManagementServer (t )
@@ -74,6 +91,13 @@ func (s) TestReportLoad(t *testing.T) {
74
91
75
92
// Push some loads on the received store.
76
93
store1 .PerCluster ("cluster1" , "eds1" ).CallDropped ("test" )
94
+ store1 .PerCluster ("cluster1" , "eds1" ).CallStarted (testLocality1 )
95
+ store1 .PerCluster ("cluster1" , "eds1" ).CallServerLoad (testLocality1 , testKey1 , 3.14 )
96
+ store1 .PerCluster ("cluster1" , "eds1" ).CallServerLoad (testLocality1 , testKey1 , 2.718 )
97
+ store1 .PerCluster ("cluster1" , "eds1" ).CallFinished (testLocality1 , nil )
98
+ store1 .PerCluster ("cluster1" , "eds1" ).CallStarted (testLocality2 )
99
+ store1 .PerCluster ("cluster1" , "eds1" ).CallServerLoad (testLocality2 , testKey2 , 1.618 )
100
+ store1 .PerCluster ("cluster1" , "eds1" ).CallFinished (testLocality2 , nil )
77
101
78
102
// Ensure the initial request is received.
79
103
req , err := mgmtServer .LRSRequestChan .Receive (ctx )
@@ -115,8 +139,23 @@ func (s) TestReportLoad(t *testing.T) {
115
139
ClusterServiceName : "eds1" ,
116
140
TotalDroppedRequests : 1 ,
117
141
DroppedRequests : []* v3endpointpb.ClusterStats_DroppedRequests {{Category : "test" , DroppedCount : 1 }},
142
+ UpstreamLocalityStats : []* v3endpointpb.UpstreamLocalityStats {
143
+ {
144
+ Locality : & v3corepb.Locality {Region : "test-region1" },
145
+ LoadMetricStats : []* v3endpointpb.EndpointLoadMetricStats {
146
+ // TotalMetricValue is the aggregation of 3.14 + 2.718 = 5.858
147
+ {MetricName : testKey1 , NumRequestsFinishedWithMetric : 2 , TotalMetricValue : 5.858 }},
148
+ TotalSuccessfulRequests : 1 ,
149
+ },
150
+ {
151
+ Locality : & v3corepb.Locality {Region : "test-region2" },
152
+ LoadMetricStats : []* v3endpointpb.EndpointLoadMetricStats {
153
+ {MetricName : testKey2 , NumRequestsFinishedWithMetric : 1 , TotalMetricValue : 1.618 }},
154
+ TotalSuccessfulRequests : 1 ,
155
+ },
156
+ },
118
157
}
119
- if diff := cmp .Diff (wantLoad , gotLoad [0 ], protocmp .Transform ()); diff != "" {
158
+ if diff := cmp .Diff (wantLoad , gotLoad [0 ], protocmp .Transform (), toleranceCmpOpt , ignoreOrderCmpOpt ); diff != "" {
120
159
t .Fatalf ("Unexpected diff in LRS request (-got, +want):\n %s" , diff )
121
160
}
122
161
0 commit comments