Search in sources :

Example 91 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class MetricCollectionAggregatorTest method smallValuesAreNormalizedToZeroWithSummaryMetrics.

@Test
public void smallValuesAreNormalizedToZeroWithSummaryMetrics() {
    // Really small values (close to 0) result in CloudWatch failing with an "unsupported value" error. Make sure that we
    // floor those values to 0 to prevent that error.
    MetricCollectionAggregator aggregator = defaultAggregator();
    MetricCollector collector = collector();
    SdkMetric<Double> metric = someMetric(Double.class);
    collector.reportMetric(metric, -1E-10);
    collector.reportMetric(metric, 1E-10);
    aggregator.addCollection(collectToFixedTime(collector));
    assertThat(aggregator.getRequests()).hasOnlyOneElementSatisfying(request -> {
        assertThat(request.metricData()).hasOnlyOneElementSatisfying(metricData -> {
            StatisticSet stats = metricData.statisticValues();
            assertThat(stats.minimum()).isEqualTo(0.0);
            assertThat(stats.maximum()).isEqualTo(0.0);
            assertThat(stats.sum()).isEqualTo(0.0);
            assertThat(stats.sampleCount()).isEqualTo(2.0);
        });
    });
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector) StatisticSet(software.amazon.awssdk.services.cloudwatch.model.StatisticSet) Test(org.junit.jupiter.api.Test)

Example 92 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class MetricCollectionAggregatorTest method getRequestsResetsState.

@Test
public void getRequestsResetsState() {
    MetricCollectionAggregator aggregator = defaultAggregator();
    MetricCollector collector = collector();
    collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 1);
    aggregator.addCollection(collectToFixedTime(collector));
    assertThat(aggregator.getRequests()).hasSize(1);
    assertThat(aggregator.getRequests()).isEmpty();
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.jupiter.api.Test)

Example 93 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class MetricCollectionAggregatorTest method aggregatorWithUniqueMetricsAdded.

private MetricCollectionAggregator aggregatorWithUniqueMetricsAdded(int numMetrics) {
    MetricCollectionAggregator aggregator = defaultAggregator();
    MetricCollector collector = collector();
    for (int i = 0; i < numMetrics; i++) {
        collector.reportMetric(someMetric(), 0);
    }
    aggregator.addCollection(collectToFixedTime(collector));
    return aggregator;
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 94 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class MetricCollectionAggregatorTest method aggregatorWithUniqueValuesAdded.

private MetricCollectionAggregator aggregatorWithUniqueValuesAdded(SdkMetric<Integer> metric, int numValues) {
    MetricCollectionAggregator aggregator = aggregatorWithCustomDetailedMetrics(metric);
    for (int i = 0; i < numValues; i++) {
        MetricCollector collector = collector();
        collector.reportMetric(metric, i);
        aggregator.addCollection(collectToFixedTime(collector));
    }
    return aggregator;
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 95 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class MetricCollectionAggregatorTest method metricsAreAggregatedByDimensionMetricAndTime.

@Test
public void metricsAreAggregatedByDimensionMetricAndTime() {
    MetricCollectionAggregator aggregator = defaultAggregator();
    MetricCollector collector = collector();
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 1);
    aggregator.addCollection(collectToFixedTimeBucket(collector, 0));
    collector = collector();
    collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 2);
    aggregator.addCollection(collectToFixedTimeBucket(collector, 0));
    collector = collector();
    collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
    collector.reportMetric(CoreMetric.OPERATION_NAME, "OperationName");
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 3);
    collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 4);
    aggregator.addCollection(collectToFixedTimeBucket(collector, 0));
    collector = collector();
    collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
    collector.reportMetric(CoreMetric.OPERATION_NAME, "OperationName");
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 5);
    aggregator.addCollection(collectToFixedTimeBucket(collector, 1));
    assertThat(aggregator.getRequests()).hasOnlyOneElementSatisfying(request -> {
        assertThat(request.namespace()).isEqualTo(DEFAULT_NAMESPACE);
        assertThat(request.metricData()).hasSize(5).allSatisfy(data -> {
            assertThat(data.values()).isEmpty();
            assertThat(data.counts()).isEmpty();
            if (data.dimensions().isEmpty()) {
                assertThat(data.metricName()).isEqualTo(HttpMetric.MAX_CONCURRENCY.name());
                assertThat(data.statisticValues().sampleCount()).isEqualTo(1);
                assertThat(data.statisticValues().sum()).isEqualTo(1);
            } else if (data.dimensions().size() == 1) {
                assertThat(data.metricName()).isEqualTo(HttpMetric.MAX_CONCURRENCY.name());
                assertThat(data.statisticValues().sampleCount()).isEqualTo(1);
                assertThat(data.statisticValues().sum()).isEqualTo(2);
            } else {
                assertThat(data.dimensions().size()).isEqualTo(2);
                if (data.timestamp().equals(Instant.EPOCH)) {
                    // Time bucket 0
                    if (data.metricName().equals(HttpMetric.MAX_CONCURRENCY.name())) {
                        assertThat(data.statisticValues().sampleCount()).isEqualTo(1);
                        assertThat(data.statisticValues().sum()).isEqualTo(3);
                    } else {
                        assertThat(data.metricName()).isEqualTo(HttpMetric.AVAILABLE_CONCURRENCY.name());
                        assertThat(data.statisticValues().sampleCount()).isEqualTo(1);
                        assertThat(data.statisticValues().sum()).isEqualTo(4);
                    }
                } else {
                    // Time bucket 1
                    assertThat(data.metricName()).isEqualTo(HttpMetric.MAX_CONCURRENCY.name());
                    assertThat(data.statisticValues().sampleCount()).isEqualTo(1);
                    assertThat(data.statisticValues().sum()).isEqualTo(5);
                }
            }
        });
    });
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.jupiter.api.Test)

Aggregations

MetricCollector (software.amazon.awssdk.metrics.MetricCollector)115 NoOpMetricCollector (software.amazon.awssdk.metrics.NoOpMetricCollector)65 MetricPublisher (software.amazon.awssdk.metrics.MetricPublisher)64 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)59 ClientExecutionParams (software.amazon.awssdk.core.client.handler.ClientExecutionParams)47 CompletableFuture (java.util.concurrent.CompletableFuture)37 JsonOperationMetadata (software.amazon.awssdk.protocols.json.JsonOperationMetadata)35 Collections (java.util.Collections)34 List (java.util.List)34 Logger (org.slf4j.Logger)34 LoggerFactory (org.slf4j.LoggerFactory)34 Generated (software.amazon.awssdk.annotations.Generated)34 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)34 AwsAsyncClientHandler (software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler)34 RequestOverrideConfiguration (software.amazon.awssdk.core.RequestOverrideConfiguration)34 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)34 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)34 AsyncClientHandler (software.amazon.awssdk.core.client.handler.AsyncClientHandler)34 HttpResponseHandler (software.amazon.awssdk.core.http.HttpResponseHandler)34 CoreMetric (software.amazon.awssdk.core.metrics.CoreMetric)34