use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class MetricReportingTest method prepareRequest_connectionManagerNotPooling_callableCalled_metricsReported.
@Test
public void prepareRequest_connectionManagerNotPooling_callableCalled_metricsReported() throws IOException {
ApacheHttpClient client = newClient();
when(mockHttpClient.getHttpClientConnectionManager()).thenReturn(mock(HttpClientConnectionManager.class));
MetricCollector collector = MetricCollector.create("test");
HttpExecuteRequest executeRequest = newRequest(collector);
client.prepareRequest(executeRequest).call();
MetricCollection collected = collector.collect();
assertThat(collected.metricValues(HTTP_CLIENT_NAME)).containsExactly("Apache");
assertThat(collected.metricValues(LEASED_CONCURRENCY)).isEmpty();
assertThat(collected.metricValues(PENDING_CONCURRENCY_ACQUIRES)).isEmpty();
assertThat(collected.metricValues(AVAILABLE_CONCURRENCY)).isEmpty();
assertThat(collected.metricValues(MAX_CONCURRENCY)).isEmpty();
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class MetricReportingTest method prepareRequest_callableCalled_metricsReported.
@Test
public void prepareRequest_callableCalled_metricsReported() throws IOException {
ApacheHttpClient client = newClient();
MetricCollector collector = MetricCollector.create("test");
HttpExecuteRequest executeRequest = newRequest(collector);
client.prepareRequest(executeRequest).call();
MetricCollection collected = collector.collect();
assertThat(collected.metricValues(HTTP_CLIENT_NAME)).containsExactly("Apache");
assertThat(collected.metricValues(LEASED_CONCURRENCY)).containsExactly(1);
assertThat(collected.metricValues(PENDING_CONCURRENCY_ACQUIRES)).containsExactly(2);
assertThat(collected.metricValues(AVAILABLE_CONCURRENCY)).containsExactly(3);
assertThat(collected.metricValues(MAX_CONCURRENCY)).containsExactly(4);
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class MakeHttpRequestStageTest method testExecute_contextContainsMetricCollector_addsChildToExecuteRequest.
@Test
public void testExecute_contextContainsMetricCollector_addsChildToExecuteRequest() {
SdkHttpFullRequest sdkRequest = SdkHttpFullRequest.builder().method(SdkHttpMethod.GET).host("mybucket.s3.us-west-2.amazonaws.com").protocol("https").build();
MetricCollector mockCollector = mock(MetricCollector.class);
MetricCollector childCollector = mock(MetricCollector.class);
when(mockCollector.createChild(any(String.class))).thenReturn(childCollector);
ExecutionContext executionContext = ExecutionContext.builder().executionAttributes(new ExecutionAttributes()).build();
RequestExecutionContext context = RequestExecutionContext.builder().originalRequest(ValidSdkObjects.sdkRequest()).executionContext(executionContext).build();
context.attemptMetricCollector(mockCollector);
context.apiCallAttemptTimeoutTracker(mock(TimeoutTracker.class));
context.apiCallTimeoutTracker(mock(TimeoutTracker.class));
try {
stage.execute(sdkRequest, context);
} catch (Exception e) {
// ignored, don't really care about successful execution of the stage in this case
} finally {
ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
verify(mockCollector).createChild(eq("HttpClient"));
verify(mockClient).prepareRequest(httpRequestCaptor.capture());
assertThat(httpRequestCaptor.getValue().metricCollector()).contains(childCollector);
}
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class CloudWatchMetricPublisherTest method metricLevelSettingIsHonored.
@Test
public void metricLevelSettingIsHonored() {
try (CloudWatchMetricPublisher publisher = publisherBuilder.metricLevel(MetricLevel.INFO).build()) {
MetricCollector collector = newCollector();
collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
collector.reportMetric(CoreMetric.API_CALL_SUCCESSFUL, true);
collector.reportMetric(HttpMetric.HTTP_STATUS_CODE, 404);
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(CoreMetric.API_CALL_SUCCESSFUL.name());
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class CloudWatchMetricPublisherTest method closeWaitsForUploadToComplete.
@Test(timeout = 10_000)
public void closeWaitsForUploadToComplete() throws InterruptedException {
CountDownLatch cloudwatchPutCalledLatch = new CountDownLatch(1);
CompletableFuture<PutMetricDataResponse> result = new CompletableFuture<>();
CloudWatchAsyncClient cloudWatch = Mockito.mock(CloudWatchAsyncClient.class);
try (CloudWatchMetricPublisher publisher = CloudWatchMetricPublisher.builder().cloudWatchClient(cloudWatch).uploadFrequency(Duration.ofMinutes(60)).build()) {
MetricCollector collector = newCollector();
collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 5);
publisher.publish(new FixedTimeMetricCollection(collector.collect()));
Mockito.when(cloudWatch.putMetricData(any(PutMetricDataRequest.class))).thenAnswer(x -> {
cloudwatchPutCalledLatch.countDown();
return result;
});
publisher.publish(MetricCollector.create("test").collect());
Thread closeThread = new Thread(publisher::close);
assertThat(publisher.isShutdown()).isFalse();
closeThread.start();
// Wait until cloudwatch is called
cloudwatchPutCalledLatch.await();
// Wait to make sure the close thread seems to be waiting for the cloudwatch call to complete
Thread.sleep(1_000);
assertThat(closeThread.isAlive()).isTrue();
// Complete the cloudwatch call
result.complete(null);
// Make sure the close thread finishes
closeThread.join(5_000);
assertThat(closeThread.isAlive()).isFalse();
}
}
Aggregations