use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class IdleConnectionCountingChannelPoolTest method collectChannelPoolMetrics_failes_futureFailed.
@Test
public void collectChannelPoolMetrics_failes_futureFailed() throws Exception {
MockChannel channel = new MockChannel();
eventLoopGroup.register(channel);
RuntimeException errorToThrow = new RuntimeException("failed!");
MetricCollector mockMetricCollector = mock(MetricCollector.class);
doThrow(errorToThrow).when(mockMetricCollector).reportMetric(any(), any());
CompletableFuture<Void> collectFuture = idleCountingPool.collectChannelPoolMetrics(mockMetricCollector);
assertThatThrownBy(() -> collectFuture.get(1, TimeUnit.SECONDS)).hasCause(errorToThrow);
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class AsyncApiCallMetricCollectionStage method execute.
@Override
public CompletableFuture<OutputT> execute(SdkHttpFullRequest input, RequestExecutionContext context) throws Exception {
MetricCollector metricCollector = context.executionContext().metricCollector();
CompletableFuture<OutputT> future = new CompletableFuture<>();
long callStart = System.nanoTime();
CompletableFuture<OutputT> executeFuture = wrapped.execute(input, context);
executeFuture.whenComplete((r, t) -> {
long duration = System.nanoTime() - callStart;
metricCollector.reportMetric(CoreMetric.API_CALL_DURATION, Duration.ofNanos(duration));
if (t != null) {
future.completeExceptionally(t);
} else {
future.complete(r);
}
});
return CompletableFutureUtils.forwardExceptionTo(future, executeFuture);
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class MakeAsyncHttpRequestStage method executeHttpRequest.
private CompletableFuture<Response<OutputT>> executeHttpRequest(SdkHttpFullRequest request, RequestExecutionContext context) {
CompletableFuture<Response<OutputT>> responseFuture = new CompletableFuture<>();
CompletableFuture<Response<OutputT>> responseHandlerFuture = responseHandler.prepare();
SdkHttpContentPublisher requestProvider = context.requestProvider() == null ? new SimpleHttpContentPublisher(request) : new SdkHttpContentPublisherAdapter(context.requestProvider());
// Set content length if it hasn't been set already.
SdkHttpFullRequest requestWithContentLength = getRequestWithContentLength(request, requestProvider);
MetricCollector httpMetricCollector = MetricUtils.createHttpMetricsCollector(context);
AsyncExecuteRequest.Builder executeRequestBuilder = AsyncExecuteRequest.builder().request(requestWithContentLength).requestContentPublisher(requestProvider).responseHandler(responseHandler).fullDuplex(isFullDuplex(context.executionAttributes())).metricCollector(httpMetricCollector);
if (context.executionAttributes().getAttribute(SDK_HTTP_EXECUTION_ATTRIBUTES) != null) {
executeRequestBuilder.httpExecutionAttributes(context.executionAttributes().getAttribute(SDK_HTTP_EXECUTION_ATTRIBUTES));
}
CompletableFuture<Void> httpClientFuture = doExecuteHttpRequest(context, executeRequestBuilder.build());
TimeoutTracker timeoutTracker = setupAttemptTimer(responseFuture, context);
context.apiCallAttemptTimeoutTracker(timeoutTracker);
// Forward the cancellation
responseFuture.whenComplete((r, t) -> {
if (t != null) {
httpClientFuture.completeExceptionally(t);
}
});
// Offload the completion of the future returned from this stage onto
// the future completion executor
responseHandlerFuture.whenCompleteAsync((r, t) -> {
if (t == null) {
responseFuture.complete(r);
} else {
responseFuture.completeExceptionally(t);
}
}, futureCompletionExecutor);
return responseFuture;
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class SigningStage method signRequest.
/**
* Sign the request if the signer if provided and credentials are present.
*/
private SdkHttpFullRequest signRequest(SdkHttpFullRequest request, RequestExecutionContext context) throws Exception {
updateInterceptorContext(request, context.executionContext());
Signer signer = context.signer();
MetricCollector metricCollector = context.attemptMetricCollector();
if (shouldSign(signer)) {
adjustForClockSkew(context.executionAttributes());
Pair<SdkHttpFullRequest, Duration> measuredSign = MetricUtils.measureDuration(() -> signer.sign(request, context.executionAttributes()));
metricCollector.reportMetric(CoreMetric.SIGNING_DURATION, measuredSign.right());
SdkHttpFullRequest signedRequest = measuredSign.left();
if (signer instanceof AsyncRequestBodySigner) {
// Transform request body provider with signing operator
AsyncRequestBody transformedRequestProvider = ((AsyncRequestBodySigner) signer).signAsyncRequestBody(signedRequest, context.requestProvider(), context.executionAttributes());
context.requestProvider(transformedRequestProvider);
}
updateInterceptorContext(signedRequest, context.executionContext());
return signedRequest;
}
return request;
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class ApacheHttpClient method prepareRequest.
@Override
public ExecutableHttpRequest prepareRequest(HttpExecuteRequest request) {
MetricCollector metricCollector = request.metricCollector().orElseGet(NoOpMetricCollector::create);
metricCollector.reportMetric(HTTP_CLIENT_NAME, clientName());
HttpRequestBase apacheRequest = toApacheRequest(request);
return new ExecutableHttpRequest() {
@Override
public HttpExecuteResponse call() throws IOException {
HttpExecuteResponse executeResponse = execute(apacheRequest, metricCollector);
collectPoolMetric(metricCollector);
return executeResponse;
}
@Override
public void abort() {
apacheRequest.abort();
}
};
}
Aggregations