use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class DefaultQueryClient method aPostOperation.
/**
* <p>
* Performs a post operation to the query service and has no output
* </p>
*
* @param aPostOperationRequest
* @return Result of the APostOperation operation returned by the service.
* @throws InvalidInputException
* The request was rejected because an invalid or out-of-range value was supplied for an input parameter.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws QueryException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample QueryClient.APostOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/query-service-2010-05-08/APostOperation" target="_top">AWS
* API Documentation</a>
*/
@Override
public APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException, AwsServiceException, SdkClientException, QueryException {
HttpResponseHandler<APostOperationResponse> responseHandler = protocolFactory.createResponseHandler(APostOperationResponse::builder);
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation");
String hostPrefix = "foo-";
String resolvedHostExpression = "foo-";
return clientHandler.execute(new ClientExecutionParams<APostOperationRequest, APostOperationResponse>().withOperationName("APostOperation").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).hostPrefixExpression(resolvedHostExpression).withInput(aPostOperationRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new APostOperationRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class DefaultQueryClient method getOperationWithChecksum.
/**
* Invokes the GetOperationWithChecksum operation.
*
* @param getOperationWithChecksumRequest
* @return Result of the GetOperationWithChecksum operation returned by the service.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws QueryException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample QueryClient.GetOperationWithChecksum
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/query-service-2010-05-08/GetOperationWithChecksum"
* target="_top">AWS API Documentation</a>
*/
@Override
public GetOperationWithChecksumResponse getOperationWithChecksum(GetOperationWithChecksumRequest getOperationWithChecksumRequest) throws AwsServiceException, SdkClientException, QueryException {
HttpResponseHandler<GetOperationWithChecksumResponse> responseHandler = protocolFactory.createResponseHandler(GetOperationWithChecksumResponse::builder);
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, getOperationWithChecksumRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetOperationWithChecksum");
return clientHandler.execute(new ClientExecutionParams<GetOperationWithChecksumRequest, GetOperationWithChecksumResponse>().withOperationName("GetOperationWithChecksum").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(getOperationWithChecksumRequest).withMetricCollector(apiCallMetricCollector).putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM, HttpChecksum.builder().requestChecksumRequired(true).requestAlgorithm(getOperationWithChecksumRequest.checksumAlgorithmAsString()).isRequestStreaming(false).build()).withMarshaller(new GetOperationWithChecksumRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class DefaultQueryClient method streamingOutputOperation.
/**
* Some operation with a streaming output
*
* @param streamingOutputOperationRequest
* @param responseTransformer
* Functional interface for processing the streamed response content. The unmarshalled
* StreamingOutputOperationResponse and an InputStream to the response content are provided as parameters to
* the callback. The callback may return a transformed type which will be the return value of this method.
* See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing this
* interface and for links to pre-canned implementations for common scenarios like downloading to a file. The
* service documentation for the response content is as follows 'This be a stream'.
* @return The transformed result of the ResponseTransformer.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws QueryException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample QueryClient.StreamingOutputOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/query-service-2010-05-08/StreamingOutputOperation"
* target="_top">AWS API Documentation</a>
*/
@Override
public <ReturnT> ReturnT streamingOutputOperation(StreamingOutputOperationRequest streamingOutputOperationRequest, ResponseTransformer<StreamingOutputOperationResponse, ReturnT> responseTransformer) throws AwsServiceException, SdkClientException, QueryException {
HttpResponseHandler<StreamingOutputOperationResponse> responseHandler = protocolFactory.createResponseHandler(StreamingOutputOperationResponse::builder);
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation");
return clientHandler.execute(new ClientExecutionParams<StreamingOutputOperationRequest, StreamingOutputOperationResponse>().withOperationName("StreamingOutputOperation").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(streamingOutputOperationRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)), responseTransformer);
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class MetricCollectionAggregatorTest method metricSummariesAreCorrectWithValuesInDifferentCollector.
@Test
public void metricSummariesAreCorrectWithValuesInDifferentCollector() {
MetricCollectionAggregator aggregator = defaultAggregator();
MetricCollector collector = collector();
collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 2);
aggregator.addCollection(collectToFixedTime(collector));
collector = collector();
collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 1);
aggregator.addCollection(collectToFixedTime(collector));
collector = collector();
collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 4);
aggregator.addCollection(collectToFixedTime(collector));
collector = collector();
collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
collector.reportMetric(HttpMetric.MAX_CONCURRENCY, 4);
aggregator.addCollection(collectToFixedTime(collector));
collector = collector();
collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
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 MetricCollectionAggregatorTest method detailedMetricsAreCorrect.
@Test
public void detailedMetricsAreCorrect() {
MetricCollectionAggregator aggregator = aggregatorWithCustomDetailedMetrics(HttpMetric.MAX_CONCURRENCY);
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()).hasSize(4);
assertThat(metricData.statisticValues()).isNull();
for (int i = 0; i < metricData.values().size(); i++) {
Double value = metricData.values().get(i);
Double count = metricData.counts().get(i);
switch(value.toString()) {
case "1.0":
case "2.0":
case "3.0":
assertThat(count).isEqualTo(1.0);
break;
case "4.0":
assertThat(count).isEqualTo(2.0);
break;
default:
fail();
}
}
});
});
}
Aggregations