Search in sources :

Example 51 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class MetricCollectionAggregatorTest method transformMetricValueUsingAggregator.

private <T> Double transformMetricValueUsingAggregator(SdkMetric<T> metric, T input) {
    MetricCollectionAggregator aggregator = aggregatorWithCustomDetailedMetrics(metric);
    MetricCollector collector = collector();
    collector.reportMetric(metric, input);
    aggregator.addCollection(collectToFixedTime(collector));
    return aggregator.getRequests().get(0).metricData().get(0).values().get(0);
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 52 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class MetricCollectionAggregatorTest method dimensionOrderInCollectionDoesNotMatter.

@Test
public void dimensionOrderInCollectionDoesNotMatter() {
    MetricCollectionAggregator aggregator = defaultAggregator();
    MetricCollector collector = collector();
    collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
    collector.reportMetric(CoreMetric.OPERATION_NAME, "OperationName");
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 1);
    aggregator.addCollection(collectToFixedTime(collector));
    collector = collector();
    collector.reportMetric(CoreMetric.OPERATION_NAME, "OperationName");
    collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 2);
    aggregator.addCollection(collectToFixedTime(collector));
    assertThat(aggregator.getRequests()).hasOnlyOneElementSatisfying(request -> {
        assertThat(request.metricData()).hasSize(1);
    });
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.jupiter.api.Test)

Example 53 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class MetricCollectionAggregatorTest method metricSummariesAreCorrectWithValuesInSameCollector.

@Test
public void metricSummariesAreCorrectWithValuesInSameCollector() {
    MetricCollectionAggregator aggregator = defaultAggregator();
    MetricCollector collector = collector();
    collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 2);
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 1);
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 4);
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 4);
    collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 3);
    aggregator.addCollection(collectToFixedTime(collector));
    assertThat(aggregator.getRequests()).hasOnlyOneElementSatisfying(request -> {
        assertThat(request.namespace()).isEqualTo(DEFAULT_NAMESPACE);
        assertThat(request.metricData()).hasOnlyOneElementSatisfying(metricData -> {
            assertThat(metricData.dimensions()).hasOnlyOneElementSatisfying(dimension -> {
                assertThat(dimension.name()).isEqualTo(CoreMetric.SERVICE_ID.name());
                assertThat(dimension.value()).isEqualTo("ServiceId");
            });
            assertThat(metricData.values()).isEmpty();
            assertThat(metricData.counts()).isEmpty();
            assertThat(metricData.statisticValues()).isEqualTo(StatisticSet.builder().minimum(1.0).maximum(4.0).sum(14.0).sampleCount(5.0).build());
        });
    });
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.jupiter.api.Test)

Example 54 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class AwsExecutionContextBuilder method invokeInterceptorsAndCreateExecutionContext.

/**
 * Used by both sync and async clients to create the execution context, and run initial interceptors.
 */
public static <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionContext invokeInterceptorsAndCreateExecutionContext(ClientExecutionParams<InputT, OutputT> executionParams, SdkClientConfiguration clientConfig) {
    // Note: This is currently copied to DefaultS3Presigner and other presigners.
    // Don't edit this without considering those
    SdkRequest originalRequest = executionParams.getInput();
    MetricCollector metricCollector = resolveMetricCollector(executionParams);
    ExecutionAttributes executionAttributes = mergeExecutionAttributeOverrides(executionParams.executionAttributes(), clientConfig.option(SdkClientOption.EXECUTION_ATTRIBUTES), originalRequest.overrideConfiguration().map(c -> c.executionAttributes()).orElse(null));
    executionAttributes.putAttribute(InternalCoreExecutionAttribute.EXECUTION_ATTEMPT, 1).putAttribute(AwsSignerExecutionAttribute.SERVICE_CONFIG, clientConfig.option(SdkClientOption.SERVICE_CONFIGURATION)).putAttribute(AwsSignerExecutionAttribute.SERVICE_SIGNING_NAME, clientConfig.option(AwsClientOption.SERVICE_SIGNING_NAME)).putAttribute(AwsExecutionAttribute.AWS_REGION, clientConfig.option(AwsClientOption.AWS_REGION)).putAttribute(AwsExecutionAttribute.ENDPOINT_PREFIX, clientConfig.option(AwsClientOption.ENDPOINT_PREFIX)).putAttribute(AwsSignerExecutionAttribute.SIGNING_REGION, clientConfig.option(AwsClientOption.SIGNING_REGION)).putAttribute(SdkInternalExecutionAttribute.IS_FULL_DUPLEX, executionParams.isFullDuplex()).putAttribute(SdkInternalExecutionAttribute.HAS_INITIAL_REQUEST_EVENT, executionParams.hasInitialRequestEvent()).putAttribute(SdkExecutionAttribute.CLIENT_TYPE, clientConfig.option(SdkClientOption.CLIENT_TYPE)).putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfig.option(SdkClientOption.SERVICE_NAME)).putAttribute(SdkExecutionAttribute.PROFILE_FILE, clientConfig.option(SdkClientOption.PROFILE_FILE)).putAttribute(SdkExecutionAttribute.PROFILE_NAME, clientConfig.option(SdkClientOption.PROFILE_NAME)).putAttribute(AwsExecutionAttribute.DUALSTACK_ENDPOINT_ENABLED, clientConfig.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)).putAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED, clientConfig.option(AwsClientOption.FIPS_ENDPOINT_ENABLED)).putAttribute(SdkExecutionAttribute.OPERATION_NAME, executionParams.getOperationName()).putAttribute(SdkExecutionAttribute.CLIENT_ENDPOINT, clientConfig.option(SdkClientOption.ENDPOINT)).putAttribute(SdkExecutionAttribute.ENDPOINT_OVERRIDDEN, clientConfig.option(SdkClientOption.ENDPOINT_OVERRIDDEN)).putAttribute(SdkInternalExecutionAttribute.DISABLE_HOST_PREFIX_INJECTION, clientConfig.option(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION)).putAttribute(SdkExecutionAttribute.SIGNER_OVERRIDDEN, clientConfig.option(SdkClientOption.SIGNER_OVERRIDDEN)).putAttribute(RESOLVED_CHECKSUM_SPECS, HttpChecksumResolver.getResolvedChecksumSpecs(executionAttributes));
    ExecutionInterceptorChain executionInterceptorChain = new ExecutionInterceptorChain(clientConfig.option(SdkClientOption.EXECUTION_INTERCEPTORS));
    InterceptorContext interceptorContext = InterceptorContext.builder().request(originalRequest).asyncRequestBody(executionParams.getAsyncRequestBody()).requestBody(executionParams.getRequestBody()).build();
    interceptorContext = runInitialInterceptors(interceptorContext, executionAttributes, executionInterceptorChain);
    Signer signer = resolveSigner(interceptorContext.request(), clientConfig.option(SdkAdvancedClientOption.SIGNER));
    // beforeExecution and modifyRequest interceptors should avoid dependency on credentials,
    // since they should be resolved after the interceptors run
    AwsCredentials credentials = resolveCredentials(clientConfig.option(AwsClientOption.CREDENTIALS_PROVIDER), originalRequest, metricCollector);
    executionAttributes.putAttribute(AwsSignerExecutionAttribute.AWS_CREDENTIALS, credentials);
    executionAttributes.putAttribute(HttpChecksumConstant.SIGNING_METHOD, resolveSigningMethodUsed(signer, executionAttributes, credentials));
    return ExecutionContext.builder().interceptorChain(executionInterceptorChain).interceptorContext(interceptorContext).executionAttributes(executionAttributes).signer(signer).metricCollector(metricCollector).build();
}
Also used : Signer(software.amazon.awssdk.core.signer.Signer) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkRequest(software.amazon.awssdk.core.SdkRequest) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 55 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class BaseClientHandler method invokeInterceptorsAndCreateExecutionContext.

// This method is only called from tests, since the subclasses in aws-core override it.
protected <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionContext invokeInterceptorsAndCreateExecutionContext(ClientExecutionParams<InputT, OutputT> params) {
    SdkRequest originalRequest = params.getInput();
    ExecutionAttributes executionAttributes = params.executionAttributes();
    executionAttributes.putAttribute(InternalCoreExecutionAttribute.EXECUTION_ATTEMPT, 1).putAttribute(SdkExecutionAttribute.SERVICE_CONFIG, clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION)).putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfiguration.option(SdkClientOption.SERVICE_NAME)).putAttribute(SdkExecutionAttribute.PROFILE_FILE, clientConfiguration.option(SdkClientOption.PROFILE_FILE)).putAttribute(SdkExecutionAttribute.PROFILE_NAME, clientConfiguration.option(SdkClientOption.PROFILE_NAME));
    ExecutionInterceptorChain interceptorChain = new ExecutionInterceptorChain(clientConfiguration.option(SdkClientOption.EXECUTION_INTERCEPTORS));
    InterceptorContext interceptorContext = InterceptorContext.builder().request(originalRequest).build();
    interceptorChain.beforeExecution(interceptorContext, executionAttributes);
    interceptorContext = interceptorChain.modifyRequest(interceptorContext, executionAttributes);
    MetricCollector metricCollector = resolveMetricCollector(params);
    return ExecutionContext.builder().interceptorChain(interceptorChain).interceptorContext(interceptorContext).executionAttributes(executionAttributes).signer(clientConfiguration.option(SdkAdvancedClientOption.SIGNER)).metricCollector(metricCollector).build();
}
Also used : ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkRequest(software.amazon.awssdk.core.SdkRequest) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) 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