xds: fix bug of missing total_dropped_requests field in ClusterStats proto (#5862)

This commit is contained in:
Chengyuan Zhang 2019-06-10 14:22:16 -07:00 committed by GitHub
parent f7077a565a
commit c98fb2d03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View File

@ -92,11 +92,15 @@ final class XdsLoadStatsStore implements StatsStore {
localityLoadCounters.remove(entry.getKey());
}
}
long totalDrops = 0;
for (Map.Entry<String, AtomicLong> entry : dropCounters.entrySet()) {
long drops = entry.getValue().getAndSet(0);
totalDrops += drops;
statsBuilder.addDroppedRequests(DroppedRequests.newBuilder()
.setCategory(entry.getKey())
.setDroppedCount(entry.getValue().getAndSet(0)));
.setDroppedCount(drops));
}
statsBuilder.setTotalDroppedRequests(totalDrops);
return statsBuilder.build();
}

View File

@ -374,6 +374,7 @@ public class XdsLoadReportClientImplTest {
.addDroppedRequests(DroppedRequests.newBuilder()
.setCategory("throttle")
.setDroppedCount(numThrottleDrops))
.setTotalDroppedRequests(numLbDrops + numThrottleDrops)
.build();
ClusterStats expectedStats2 = ClusterStats.newBuilder()
.setClusterName(SERVICE_AUTHORITY)
@ -387,6 +388,7 @@ public class XdsLoadReportClientImplTest {
.addDroppedRequests(DroppedRequests.newBuilder()
.setCategory("throttle")
.setDroppedCount(0))
.setTotalDroppedRequests(0)
.build();
when(statsStore.generateLoadReport())
.thenReturn(expectedStats1, expectedStats2);

View File

@ -135,6 +135,7 @@ public class XdsLoadStatsStoreTest {
private static void assertClusterStatsEqual(ClusterStats expected, ClusterStats actual) {
assertThat(actual.getClusterName()).isEqualTo(expected.getClusterName());
assertThat(actual.getLoadReportInterval()).isEqualTo(expected.getLoadReportInterval());
assertThat(actual.getTotalDroppedRequests()).isEqualTo(expected.getTotalDroppedRequests());
assertThat(actual.getDroppedRequestsCount()).isEqualTo(expected.getDroppedRequestsCount());
assertThat(new HashSet<>(actual.getDroppedRequestsList()))
.isEqualTo(new HashSet<>(expected.getDroppedRequestsList()));