Search in sources :

Example 1 with GetMetricStatisticsResponse

use of software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsResponse in project beam by apache.

the class SimplifiedKinesisClientTest method shouldCountBytesWhenSingleDataPointReturned.

@Test
public void shouldCountBytesWhenSingleDataPointReturned() throws Exception {
    Instant countSince = new Instant("2017-04-06T10:00:00.000Z");
    Instant countTo = new Instant("2017-04-06T11:00:00.000Z");
    Minutes periodTime = Minutes.minutesBetween(countSince, countTo);
    GetMetricStatisticsRequest metricStatisticsRequest = underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime);
    GetMetricStatisticsResponse result = GetMetricStatisticsResponse.builder().datapoints(Datapoint.builder().sum(1.0).build()).build();
    when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenReturn(result);
    long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);
    assertThat(backlogBytes).isEqualTo(1L);
}
Also used : GetMetricStatisticsRequest(software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsRequest) GetMetricStatisticsResponse(software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsResponse) Instant(org.joda.time.Instant) Minutes(org.joda.time.Minutes) Test(org.junit.Test)

Example 2 with GetMetricStatisticsResponse

use of software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsResponse in project beam by apache.

the class SimplifiedKinesisClientTest method shouldCountBytesWhenMultipleDataPointsReturned.

@Test
public void shouldCountBytesWhenMultipleDataPointsReturned() throws Exception {
    Instant countSince = new Instant("2017-04-06T10:00:00.000Z");
    Instant countTo = new Instant("2017-04-06T11:00:00.000Z");
    Minutes periodTime = Minutes.minutesBetween(countSince, countTo);
    GetMetricStatisticsRequest metricStatisticsRequest = underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime);
    GetMetricStatisticsResponse result = GetMetricStatisticsResponse.builder().datapoints(Datapoint.builder().sum(1.0).build(), Datapoint.builder().sum(3.0).build(), Datapoint.builder().sum(2.0).build()).build();
    when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenReturn(result);
    long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);
    assertThat(backlogBytes).isEqualTo(6L);
}
Also used : GetMetricStatisticsRequest(software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsRequest) GetMetricStatisticsResponse(software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsResponse) Instant(org.joda.time.Instant) Minutes(org.joda.time.Minutes) Test(org.junit.Test)

Example 3 with GetMetricStatisticsResponse

use of software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsResponse in project beam by apache.

the class SimplifiedKinesisClient method getBacklogBytes.

/**
 * Gets total size in bytes of all events that remain in Kinesis stream between specified
 * instants.
 *
 * @return total size in bytes of all Kinesis events after specified instant
 */
public long getBacklogBytes(final String streamName, final Instant countSince, final Instant countTo) throws TransientKinesisException {
    return wrapExceptions(() -> {
        Minutes period = Minutes.minutesBetween(countSince, countTo);
        if (period.isLessThan(Minutes.ONE)) {
            return 0L;
        }
        GetMetricStatisticsRequest request = createMetricStatisticsRequest(streamName, countSince, countTo, period);
        long totalSizeInBytes = 0;
        GetMetricStatisticsResponse response = cloudWatch.getMetricStatistics(request);
        for (Datapoint point : response.datapoints()) {
            totalSizeInBytes += point.sum().longValue();
        }
        return totalSizeInBytes;
    });
}
Also used : Datapoint(software.amazon.awssdk.services.cloudwatch.model.Datapoint) GetMetricStatisticsRequest(software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsRequest) GetMetricStatisticsResponse(software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsResponse) Minutes(org.joda.time.Minutes)

Aggregations

Minutes (org.joda.time.Minutes)3 GetMetricStatisticsRequest (software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsRequest)3 GetMetricStatisticsResponse (software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsResponse)3 Instant (org.joda.time.Instant)2 Test (org.junit.Test)2 Datapoint (software.amazon.awssdk.services.cloudwatch.model.Datapoint)1