use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class AsyncSigningStage method signRequest.
/**
* Sign the request if the signer is provided and credentials are present.
*/
private CompletableFuture<SdkHttpFullRequest> signRequest(SdkHttpFullRequest request, RequestExecutionContext context) {
updateInterceptorContext(request, context.executionContext());
Signer signer = context.signer();
MetricCollector metricCollector = context.attemptMetricCollector();
if (!shouldSign(signer)) {
return CompletableFuture.completedFuture(request);
}
adjustForClockSkew(context.executionAttributes());
AsyncSigner asyncSigner = asAsyncSigner(signer, context);
long signingStart = System.nanoTime();
CompletableFuture<SdkHttpFullRequest> signedRequestFuture = asyncSigner.sign(request, context.requestProvider(), context.executionAttributes());
signedRequestFuture.whenComplete((r, t) -> metricCollector.reportMetric(CoreMetric.SIGNING_DURATION, Duration.ofNanos(System.nanoTime() - signingStart)));
return signedRequestFuture.thenApply(r -> {
updateInterceptorContext(r, context.executionContext());
return r;
});
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class MakeAsyncHttpRequestStage method doExecuteHttpRequest.
private CompletableFuture<Void> doExecuteHttpRequest(RequestExecutionContext context, AsyncExecuteRequest executeRequest) {
MetricCollector metricCollector = context.attemptMetricCollector();
long callStart = System.nanoTime();
CompletableFuture<Void> httpClientFuture = sdkAsyncHttpClient.execute(executeRequest);
CompletableFuture<Void> result = httpClientFuture.whenComplete((r, t) -> {
long duration = System.nanoTime() - callStart;
metricCollector.reportMetric(CoreMetric.SERVICE_CALL_DURATION, Duration.ofNanos(duration));
});
// Make sure failures on the result future are forwarded to the http client future.
CompletableFutureUtils.forwardExceptionTo(result, httpClientFuture);
return result;
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class ApiCallAttemptMetricCollectionStage method execute.
@Override
public Response<OutputT> execute(SdkHttpFullRequest input, RequestExecutionContext context) throws Exception {
MetricCollector apiCallAttemptMetrics = createAttemptMetricsCollector(context);
context.attemptMetricCollector(apiCallAttemptMetrics);
reportBackoffDelay(context);
Response<OutputT> response = wrapped.execute(input, context);
collectHttpMetrics(apiCallAttemptMetrics, response.httpResponse());
return response;
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class ApiCallMetricCollectionStage method execute.
@Override
public Response<OutputT> execute(SdkHttpFullRequest input, RequestExecutionContext context) throws Exception {
MetricCollector metricCollector = context.executionContext().metricCollector();
// Note: at this point, any exception, even a service exception, will
// be thrown from the wrapped pipeline so we can't use
// MetricUtil.measureDuration()
long callStart = System.nanoTime();
try {
return wrapped.execute(input, context);
} finally {
long d = System.nanoTime() - callStart;
metricCollector.reportMetric(CoreMetric.API_CALL_DURATION, Duration.ofNanos(d));
}
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class AsyncApiCallAttemptMetricCollectionStage method execute.
@Override
public CompletableFuture<Response<OutputT>> execute(SdkHttpFullRequest input, RequestExecutionContext context) throws Exception {
MetricCollector apiCallAttemptMetrics = createAttemptMetricsCollector(context);
context.attemptMetricCollector(apiCallAttemptMetrics);
reportBackoffDelay(context);
CompletableFuture<Response<OutputT>> executeFuture = wrapped.execute(input, context);
CompletableFuture<Response<OutputT>> metricsCollectedFuture = executeFuture.whenComplete((r, t) -> {
if (t == null) {
collectHttpMetrics(apiCallAttemptMetrics, r.httpResponse());
}
});
CompletableFutureUtils.forwardExceptionTo(metricsCollectedFuture, executeFuture);
return metricsCollectedFuture;
}
Aggregations