Search in sources :

Example 76 with MetricCollector

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;
    });
}
Also used : AsyncSigner(software.amazon.awssdk.core.signer.AsyncSigner) AsyncRequestBodySigner(software.amazon.awssdk.core.signer.AsyncRequestBodySigner) Signer(software.amazon.awssdk.core.signer.Signer) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) AsyncSigner(software.amazon.awssdk.core.signer.AsyncSigner)

Example 77 with MetricCollector

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;
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 78 with MetricCollector

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;
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 79 with MetricCollector

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));
    }
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 80 with MetricCollector

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;
}
Also used : Response(software.amazon.awssdk.core.Response) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Aggregations

MetricCollector (software.amazon.awssdk.metrics.MetricCollector)115 NoOpMetricCollector (software.amazon.awssdk.metrics.NoOpMetricCollector)65 MetricPublisher (software.amazon.awssdk.metrics.MetricPublisher)64 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)59 ClientExecutionParams (software.amazon.awssdk.core.client.handler.ClientExecutionParams)47 CompletableFuture (java.util.concurrent.CompletableFuture)37 JsonOperationMetadata (software.amazon.awssdk.protocols.json.JsonOperationMetadata)35 Collections (java.util.Collections)34 List (java.util.List)34 Logger (org.slf4j.Logger)34 LoggerFactory (org.slf4j.LoggerFactory)34 Generated (software.amazon.awssdk.annotations.Generated)34 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)34 AwsAsyncClientHandler (software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler)34 RequestOverrideConfiguration (software.amazon.awssdk.core.RequestOverrideConfiguration)34 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)34 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)34 AsyncClientHandler (software.amazon.awssdk.core.client.handler.AsyncClientHandler)34 HttpResponseHandler (software.amazon.awssdk.core.http.HttpResponseHandler)34 CoreMetric (software.amazon.awssdk.core.metrics.CoreMetric)34