Search in sources :

Example 86 with MetricCollector

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

the class CloudWatchMetricPublisherTest method metricCategoriesSettingIsHonored.

@Test
public void metricCategoriesSettingIsHonored() {
    try (CloudWatchMetricPublisher publisher = publisherBuilder.metricCategories(MetricCategory.HTTP_CLIENT).build()) {
        MetricCollector collector = newCollector();
        collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
        collector.reportMetric(CoreMetric.API_CALL_SUCCESSFUL, true);
        collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 5);
        publisher.publish(new FixedTimeMetricCollection(collector.collect()));
    }
    PutMetricDataRequest call = getPutMetricCall();
    MetricDatum metric = call.metricData().get(0);
    assertThat(call.metricData()).hasSize(1);
    assertThat(metric.dimensions()).containsExactly(Dimension.builder().name(CoreMetric.SERVICE_ID.name()).value("ServiceId").build());
    assertThat(metric.metricName()).isEqualTo(HttpMetric.AVAILABLE_CONCURRENCY.name());
}
Also used : PutMetricDataRequest(software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) MetricDatum(software.amazon.awssdk.services.cloudwatch.model.MetricDatum) Test(org.junit.Test)

Example 87 with MetricCollector

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

the class CloudWatchMetricPublisherTest method detailedMetricsSettingIsHonored.

@Test
public void detailedMetricsSettingIsHonored() {
    try (CloudWatchMetricPublisher publisher = publisherBuilder.detailedMetrics(HttpMetric.AVAILABLE_CONCURRENCY).build()) {
        for (int i = 0; i < 10; ++i) {
            MetricCollector collector = newCollector();
            collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 10);
            collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, i);
            publisher.publish(new FixedTimeMetricCollection(collector.collect()));
        }
    }
    PutMetricDataRequest call = getPutMetricCall();
    MetricDatum concurrencyMetric = getDatum(call, HttpMetric.MAX_CONCURRENCY);
    MetricDatum availableConcurrency = getDatum(call, HttpMetric.AVAILABLE_CONCURRENCY);
    assertThat(concurrencyMetric.values()).isEmpty();
    assertThat(concurrencyMetric.counts()).isEmpty();
    assertThat(concurrencyMetric.statisticValues()).isNotNull();
    assertThat(availableConcurrency.values()).isNotEmpty();
    assertThat(availableConcurrency.counts()).isNotEmpty();
    assertThat(availableConcurrency.statisticValues()).isNull();
}
Also used : PutMetricDataRequest(software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) MetricDatum(software.amazon.awssdk.services.cloudwatch.model.MetricDatum) Test(org.junit.Test)

Example 88 with MetricCollector

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

the class BetterFixedChannelPoolTest method assertConnectionsCheckedOutAndPending.

private void assertConnectionsCheckedOutAndPending(int checkedOut, int pending) {
    MetricCollector metricCollector = MetricCollector.create("foo");
    waitForCompletion(channelPool.collectChannelPoolMetrics(metricCollector));
    MetricCollection metrics = metricCollector.collect();
    assertThat(metrics.metricValues(HttpMetric.MAX_CONCURRENCY)).containsExactly(2);
    assertThat(metrics.metricValues(HttpMetric.LEASED_CONCURRENCY)).containsExactly(checkedOut);
    assertThat(metrics.metricValues(HttpMetric.PENDING_CONCURRENCY_ACQUIRES)).containsExactly(pending);
}
Also used : MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 89 with MetricCollector

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

the class MetricCollectionAggregatorTest method metricsFromOtherCategoriesAreIgnored.

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

Example 90 with MetricCollector

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

the class MetricCollectionAggregatorTest method smallValuesAreNormalizedToZeroWithDetailedMetrics.

@Test
public void smallValuesAreNormalizedToZeroWithDetailedMetrics() {
    // 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.
    SdkMetric<Double> metric = someMetric(Double.class);
    MetricCollectionAggregator aggregator = aggregatorWithCustomDetailedMetrics(metric);
    MetricCollector collector = collector();
    collector.reportMetric(metric, -1E-10);
    collector.reportMetric(metric, 1E-10);
    aggregator.addCollection(collectToFixedTime(collector));
    assertThat(aggregator.getRequests()).hasOnlyOneElementSatisfying(request -> {
        assertThat(request.metricData()).hasOnlyOneElementSatisfying(metricData -> {
            assertThat(metricData.values()).hasOnlyOneElementSatisfying(metricValue -> {
                assertThat(metricValue).isEqualTo(0.0);
            });
            assertThat(metricData.counts()).hasOnlyOneElementSatisfying(metricCount -> {
                assertThat(metricCount).isEqualTo(2.0);
            });
        });
    });
}
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