use of io.grpc.xds.LoadStatsManager2.ClusterLocalityStats in project grpc-java by grpc.
the class ClientXdsClient method addClusterLocalityStats.
@Override
ClusterLocalityStats addClusterLocalityStats(final ServerInfo serverInfo, String clusterName, @Nullable String edsServiceName, Locality locality) {
ClusterLocalityStats loadCounter = loadStatsManager.getClusterLocalityStats(clusterName, edsServiceName, locality);
syncContext.execute(new Runnable() {
@Override
public void run() {
if (!reportingLoad) {
serverLrsClientMap.get(serverInfo).startLoadReporting();
reportingLoad = true;
}
}
});
return loadCounter;
}
use of io.grpc.xds.LoadStatsManager2.ClusterLocalityStats in project grpc-java by grpc.
the class LoadStatsManager2Test method loadCounterDelayedDeletionAfterAllInProgressRequestsReported.
@Test
public void loadCounterDelayedDeletionAfterAllInProgressRequestsReported() {
ClusterLocalityStats counter = loadStatsManager.getClusterLocalityStats(CLUSTER_NAME1, EDS_SERVICE_NAME1, LOCALITY1);
counter.recordCallStarted();
counter.recordCallStarted();
ClusterStats stats = Iterables.getOnlyElement(loadStatsManager.getClusterStatsReports(CLUSTER_NAME1));
UpstreamLocalityStats localityStats = Iterables.getOnlyElement(stats.upstreamLocalityStatsList());
assertThat(localityStats.totalIssuedRequests()).isEqualTo(2L);
assertThat(localityStats.totalSuccessfulRequests()).isEqualTo(0L);
assertThat(localityStats.totalErrorRequests()).isEqualTo(0L);
assertThat(localityStats.totalRequestsInProgress()).isEqualTo(2L);
// release the counter, but requests still in-flight
counter.release();
stats = Iterables.getOnlyElement(loadStatsManager.getClusterStatsReports(CLUSTER_NAME1));
localityStats = Iterables.getOnlyElement(stats.upstreamLocalityStatsList());
assertThat(localityStats.totalIssuedRequests()).isEqualTo(0L);
assertThat(localityStats.totalSuccessfulRequests()).isEqualTo(0L);
assertThat(localityStats.totalErrorRequests()).isEqualTo(0L);
assertThat(localityStats.totalRequestsInProgress()).isEqualTo(// retained by in-flight calls
2L);
counter.recordCallFinished(Status.OK);
counter.recordCallFinished(Status.UNAVAILABLE);
stats = Iterables.getOnlyElement(loadStatsManager.getClusterStatsReports(CLUSTER_NAME1));
localityStats = Iterables.getOnlyElement(stats.upstreamLocalityStatsList());
assertThat(localityStats.totalIssuedRequests()).isEqualTo(0L);
assertThat(localityStats.totalSuccessfulRequests()).isEqualTo(1L);
assertThat(localityStats.totalErrorRequests()).isEqualTo(1L);
assertThat(localityStats.totalRequestsInProgress()).isEqualTo(0L);
assertThat(loadStatsManager.getClusterStatsReports(CLUSTER_NAME1)).isEmpty();
}
use of io.grpc.xds.LoadStatsManager2.ClusterLocalityStats in project grpc-java by grpc.
the class LoadStatsManager2Test method sharedLoadCounterStatsAggregation.
@Test
public void sharedLoadCounterStatsAggregation() {
ClusterLocalityStats ref1 = loadStatsManager.getClusterLocalityStats(CLUSTER_NAME1, EDS_SERVICE_NAME1, LOCALITY1);
ClusterLocalityStats ref2 = loadStatsManager.getClusterLocalityStats(CLUSTER_NAME1, EDS_SERVICE_NAME1, LOCALITY1);
ref1.recordCallStarted();
ref1.recordCallFinished(Status.OK);
ref2.recordCallStarted();
ref2.recordCallStarted();
ref2.recordCallFinished(Status.UNAVAILABLE);
ClusterStats stats = Iterables.getOnlyElement(loadStatsManager.getClusterStatsReports(CLUSTER_NAME1));
UpstreamLocalityStats localityStats = Iterables.getOnlyElement(stats.upstreamLocalityStatsList());
assertThat(localityStats.totalIssuedRequests()).isEqualTo(1L + 2L);
assertThat(localityStats.totalSuccessfulRequests()).isEqualTo(1L);
assertThat(localityStats.totalErrorRequests()).isEqualTo(1L);
assertThat(localityStats.totalRequestsInProgress()).isEqualTo(1L + 2L - 1L - 1L);
}
use of io.grpc.xds.LoadStatsManager2.ClusterLocalityStats in project grpc-java by grpc.
the class LoadStatsManager2Test method recordAndGetReport.
@Test
public void recordAndGetReport() {
ClusterDropStats dropCounter1 = loadStatsManager.getClusterDropStats(CLUSTER_NAME1, EDS_SERVICE_NAME1);
ClusterDropStats dropCounter2 = loadStatsManager.getClusterDropStats(CLUSTER_NAME1, EDS_SERVICE_NAME2);
ClusterLocalityStats loadCounter1 = loadStatsManager.getClusterLocalityStats(CLUSTER_NAME1, EDS_SERVICE_NAME1, LOCALITY1);
ClusterLocalityStats loadCounter2 = loadStatsManager.getClusterLocalityStats(CLUSTER_NAME1, EDS_SERVICE_NAME1, LOCALITY2);
ClusterLocalityStats loadCounter3 = loadStatsManager.getClusterLocalityStats(CLUSTER_NAME2, null, LOCALITY3);
dropCounter1.recordDroppedRequest("lb");
dropCounter1.recordDroppedRequest("throttle");
for (int i = 0; i < 19; i++) {
loadCounter1.recordCallStarted();
}
fakeClock.forwardTime(5L, TimeUnit.SECONDS);
dropCounter2.recordDroppedRequest();
loadCounter1.recordCallFinished(Status.OK);
for (int i = 0; i < 9; i++) {
loadCounter2.recordCallStarted();
}
loadCounter2.recordCallFinished(Status.UNAVAILABLE);
fakeClock.forwardTime(10L, TimeUnit.SECONDS);
loadCounter3.recordCallStarted();
List<ClusterStats> allStats = loadStatsManager.getAllClusterStatsReports();
// three cluster:edsServiceName
assertThat(allStats).hasSize(3);
ClusterStats stats1 = findClusterStats(allStats, CLUSTER_NAME1, EDS_SERVICE_NAME1);
assertThat(stats1.loadReportIntervalNano()).isEqualTo(TimeUnit.SECONDS.toNanos(5L + 10L));
assertThat(stats1.droppedRequestsList()).hasSize(2);
assertThat(findDroppedRequestCount(stats1.droppedRequestsList(), "lb")).isEqualTo(1L);
assertThat(findDroppedRequestCount(stats1.droppedRequestsList(), "throttle")).isEqualTo(1L);
assertThat(stats1.totalDroppedRequests()).isEqualTo(1L + 1L);
// two localities
assertThat(stats1.upstreamLocalityStatsList()).hasSize(2);
UpstreamLocalityStats loadStats1 = findLocalityStats(stats1.upstreamLocalityStatsList(), LOCALITY1);
assertThat(loadStats1.totalIssuedRequests()).isEqualTo(19L);
assertThat(loadStats1.totalSuccessfulRequests()).isEqualTo(1L);
assertThat(loadStats1.totalErrorRequests()).isEqualTo(0L);
assertThat(loadStats1.totalRequestsInProgress()).isEqualTo(19L - 1L);
UpstreamLocalityStats loadStats2 = findLocalityStats(stats1.upstreamLocalityStatsList(), LOCALITY2);
assertThat(loadStats2.totalIssuedRequests()).isEqualTo(9L);
assertThat(loadStats2.totalSuccessfulRequests()).isEqualTo(0L);
assertThat(loadStats2.totalErrorRequests()).isEqualTo(1L);
assertThat(loadStats2.totalRequestsInProgress()).isEqualTo(9L - 1L);
ClusterStats stats2 = findClusterStats(allStats, CLUSTER_NAME1, EDS_SERVICE_NAME2);
assertThat(stats2.loadReportIntervalNano()).isEqualTo(TimeUnit.SECONDS.toNanos(5L + 10L));
// no categorized drops
assertThat(stats2.droppedRequestsList()).isEmpty();
assertThat(stats2.totalDroppedRequests()).isEqualTo(1L);
// no per-locality stats
assertThat(stats2.upstreamLocalityStatsList()).isEmpty();
ClusterStats stats3 = findClusterStats(allStats, CLUSTER_NAME2, null);
assertThat(stats3.loadReportIntervalNano()).isEqualTo(TimeUnit.SECONDS.toNanos(5L + 10L));
assertThat(stats3.droppedRequestsList()).isEmpty();
// no drops recorded
assertThat(stats3.totalDroppedRequests()).isEqualTo(0L);
// one localities
assertThat(stats3.upstreamLocalityStatsList()).hasSize(1);
UpstreamLocalityStats loadStats3 = Iterables.getOnlyElement(stats3.upstreamLocalityStatsList());
assertThat(loadStats3.totalIssuedRequests()).isEqualTo(1L);
assertThat(loadStats3.totalSuccessfulRequests()).isEqualTo(0L);
assertThat(loadStats3.totalErrorRequests()).isEqualTo(0L);
assertThat(loadStats3.totalRequestsInProgress()).isEqualTo(1L);
fakeClock.forwardTime(3L, TimeUnit.SECONDS);
List<ClusterStats> clusterStatsList = loadStatsManager.getClusterStatsReports(CLUSTER_NAME1);
assertThat(clusterStatsList).hasSize(2);
stats1 = findClusterStats(clusterStatsList, CLUSTER_NAME1, EDS_SERVICE_NAME1);
assertThat(stats1.loadReportIntervalNano()).isEqualTo(TimeUnit.SECONDS.toNanos(3L));
assertThat(stats1.droppedRequestsList()).isEmpty();
// no new drops recorded
assertThat(stats1.totalDroppedRequests()).isEqualTo(0L);
// two localities
assertThat(stats1.upstreamLocalityStatsList()).hasSize(2);
loadStats1 = findLocalityStats(stats1.upstreamLocalityStatsList(), LOCALITY1);
assertThat(loadStats1.totalIssuedRequests()).isEqualTo(0L);
assertThat(loadStats1.totalSuccessfulRequests()).isEqualTo(0L);
assertThat(loadStats1.totalErrorRequests()).isEqualTo(0L);
// still in-progress
assertThat(loadStats1.totalRequestsInProgress()).isEqualTo(18L);
loadStats2 = findLocalityStats(stats1.upstreamLocalityStatsList(), LOCALITY2);
assertThat(loadStats2.totalIssuedRequests()).isEqualTo(0L);
assertThat(loadStats2.totalSuccessfulRequests()).isEqualTo(0L);
assertThat(loadStats2.totalErrorRequests()).isEqualTo(0L);
// still in-progress
assertThat(loadStats2.totalRequestsInProgress()).isEqualTo(8L);
stats2 = findClusterStats(clusterStatsList, CLUSTER_NAME1, EDS_SERVICE_NAME2);
assertThat(stats2.loadReportIntervalNano()).isEqualTo(TimeUnit.SECONDS.toNanos(3L));
assertThat(stats2.droppedRequestsList()).isEmpty();
// no new drops recorded
assertThat(stats2.totalDroppedRequests()).isEqualTo(0L);
// no per-locality stats
assertThat(stats2.upstreamLocalityStatsList()).isEmpty();
}
use of io.grpc.xds.LoadStatsManager2.ClusterLocalityStats in project grpc-java by grpc.
the class LoadReportClientTest method addFakeStatsData.
private void addFakeStatsData() {
ClusterDropStats dropStats1 = loadStatsManager.getClusterDropStats(CLUSTER1, EDS_SERVICE_NAME1);
for (int i = 0; i < 52; i++) {
dropStats1.recordDroppedRequest("lb");
}
ClusterDropStats dropStats2 = loadStatsManager.getClusterDropStats(CLUSTER2, EDS_SERVICE_NAME2);
for (int i = 0; i < 23; i++) {
dropStats2.recordDroppedRequest("throttle");
}
ClusterLocalityStats localityStats1 = loadStatsManager.getClusterLocalityStats(CLUSTER1, EDS_SERVICE_NAME1, LOCALITY1);
for (int i = 0; i < 31; i++) {
localityStats1.recordCallStarted();
}
ClusterLocalityStats localityStats2 = loadStatsManager.getClusterLocalityStats(CLUSTER2, EDS_SERVICE_NAME2, LOCALITY2);
for (int i = 0; i < 45; i++) {
localityStats2.recordCallStarted();
}
localityStats2.recordCallFinished(Status.OK);
}
Aggregations