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