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());
}
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();
}
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);
}
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();
}
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);
});
});
});
}
Aggregations