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);
}
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);
});
}
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());
});
});
}
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();
}
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();
}
Aggregations