Search in sources :

Example 46 with MetricCollector

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()));
    }
}
Also used : APostOperationResponse(software.amazon.awssdk.services.query.model.APostOperationResponse) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) APostOperationRequestMarshaller(software.amazon.awssdk.services.query.transform.APostOperationRequestMarshaller)

Example 47 with MetricCollector

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()));
    }
}
Also used : ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) GetOperationWithChecksumResponse(software.amazon.awssdk.services.query.model.GetOperationWithChecksumResponse) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) GetOperationWithChecksumRequestMarshaller(software.amazon.awssdk.services.query.transform.GetOperationWithChecksumRequestMarshaller)

Example 48 with MetricCollector

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()));
    }
}
Also used : StreamingOutputOperationRequestMarshaller(software.amazon.awssdk.services.query.transform.StreamingOutputOperationRequestMarshaller) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) StreamingOutputOperationRequest(software.amazon.awssdk.services.query.model.StreamingOutputOperationRequest) StreamingOutputOperationResponse(software.amazon.awssdk.services.query.model.StreamingOutputOperationResponse) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 49 with MetricCollector

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

Example 50 with MetricCollector

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

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