Search in sources :

Example 1 with ClusterDropStats

use of io.grpc.xds.LoadStatsManager2.ClusterDropStats in project grpc-java by grpc.

the class LoadStatsManager2Test method dropCounterDelayedDeletionAfterReported.

@Test
public void dropCounterDelayedDeletionAfterReported() {
    ClusterDropStats counter = loadStatsManager.getClusterDropStats(CLUSTER_NAME1, EDS_SERVICE_NAME1);
    counter.recordDroppedRequest("lb");
    ClusterStats stats = Iterables.getOnlyElement(loadStatsManager.getClusterStatsReports(CLUSTER_NAME1));
    assertThat(stats.droppedRequestsList()).hasSize(1);
    assertThat(Iterables.getOnlyElement(stats.droppedRequestsList()).droppedCount()).isEqualTo(1L);
    assertThat(stats.totalDroppedRequests()).isEqualTo(1L);
    counter.release();
    stats = Iterables.getOnlyElement(loadStatsManager.getClusterStatsReports(CLUSTER_NAME1));
    assertThat(stats.droppedRequestsList()).isEmpty();
    assertThat(stats.totalDroppedRequests()).isEqualTo(0L);
    assertThat(loadStatsManager.getClusterStatsReports(CLUSTER_NAME1)).isEmpty();
}
Also used : ClusterStats(io.grpc.xds.Stats.ClusterStats) ClusterDropStats(io.grpc.xds.LoadStatsManager2.ClusterDropStats) Test(org.junit.Test)

Example 2 with ClusterDropStats

use of io.grpc.xds.LoadStatsManager2.ClusterDropStats 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();
}
Also used : UpstreamLocalityStats(io.grpc.xds.Stats.UpstreamLocalityStats) ClusterStats(io.grpc.xds.Stats.ClusterStats) ClusterDropStats(io.grpc.xds.LoadStatsManager2.ClusterDropStats) ClusterLocalityStats(io.grpc.xds.LoadStatsManager2.ClusterLocalityStats) Test(org.junit.Test)

Example 3 with ClusterDropStats

use of io.grpc.xds.LoadStatsManager2.ClusterDropStats 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);
}
Also used : ClusterDropStats(io.grpc.xds.LoadStatsManager2.ClusterDropStats) ClusterLocalityStats(io.grpc.xds.LoadStatsManager2.ClusterLocalityStats)

Example 4 with ClusterDropStats

use of io.grpc.xds.LoadStatsManager2.ClusterDropStats in project grpc-java by grpc.

the class ClientXdsClientTestBase method reportLoadStatsToServer.

@Test
public void reportLoadStatsToServer() {
    xdsClient.watchLdsResource(LDS_RESOURCE, ldsResourceWatcher);
    String clusterName = "cluster-foo.googleapis.com";
    ClusterDropStats dropStats = xdsClient.addClusterDropStats(lrsServerInfo, clusterName, null);
    LrsRpcCall lrsCall = loadReportCalls.poll();
    // initial LRS request
    lrsCall.verifyNextReportClusters(Collections.<String[]>emptyList());
    lrsCall.sendResponse(Collections.singletonList(clusterName), 1000L);
    fakeClock.forwardNanos(1000L);
    lrsCall.verifyNextReportClusters(Collections.singletonList(new String[] { clusterName, null }));
    dropStats.release();
    fakeClock.forwardNanos(1000L);
    // In case of having unreported cluster stats, one last report will be sent after corresponding
    // stats object released.
    lrsCall.verifyNextReportClusters(Collections.singletonList(new String[] { clusterName, null }));
    fakeClock.forwardNanos(1000L);
    // Currently load reporting continues (with empty stats) even if all stats objects have been
    // released.
    // no more stats reported
    lrsCall.verifyNextReportClusters(Collections.<String[]>emptyList());
// See more test on LoadReportClientTest.java
}
Also used : ClusterDropStats(io.grpc.xds.LoadStatsManager2.ClusterDropStats) Test(org.junit.Test)

Example 5 with ClusterDropStats

use of io.grpc.xds.LoadStatsManager2.ClusterDropStats in project grpc-java by grpc.

the class LoadStatsManager2Test method sharedDropCounterStatsAggregation.

@Test
public void sharedDropCounterStatsAggregation() {
    ClusterDropStats ref1 = loadStatsManager.getClusterDropStats(CLUSTER_NAME1, EDS_SERVICE_NAME1);
    ClusterDropStats ref2 = loadStatsManager.getClusterDropStats(CLUSTER_NAME1, EDS_SERVICE_NAME1);
    ref1.recordDroppedRequest("lb");
    ref2.recordDroppedRequest("throttle");
    ref1.recordDroppedRequest();
    ref2.recordDroppedRequest();
    ClusterStats stats = Iterables.getOnlyElement(loadStatsManager.getClusterStatsReports(CLUSTER_NAME1));
    assertThat(stats.droppedRequestsList()).hasSize(2);
    assertThat(findDroppedRequestCount(stats.droppedRequestsList(), "lb")).isEqualTo(1L);
    assertThat(findDroppedRequestCount(stats.droppedRequestsList(), "throttle")).isEqualTo(1L);
    // 2 cagetorized + 2 uncategoized
    assertThat(stats.totalDroppedRequests()).isEqualTo(4L);
}
Also used : ClusterStats(io.grpc.xds.Stats.ClusterStats) ClusterDropStats(io.grpc.xds.LoadStatsManager2.ClusterDropStats) Test(org.junit.Test)

Aggregations

ClusterDropStats (io.grpc.xds.LoadStatsManager2.ClusterDropStats)6 Test (org.junit.Test)4 ClusterStats (io.grpc.xds.Stats.ClusterStats)3 ClusterLocalityStats (io.grpc.xds.LoadStatsManager2.ClusterLocalityStats)2 UpstreamLocalityStats (io.grpc.xds.Stats.UpstreamLocalityStats)1