Search in sources :

Example 81 with MetricCollector

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

the class MakeHttpRequestStage method executeHttpRequest.

private HttpExecuteResponse executeHttpRequest(SdkHttpFullRequest request, RequestExecutionContext context) throws Exception {
    MetricCollector attemptMetricCollector = context.attemptMetricCollector();
    MetricCollector httpMetricCollector = MetricUtils.createHttpMetricsCollector(context);
    ExecutableHttpRequest requestCallable = sdkHttpClient.prepareRequest(HttpExecuteRequest.builder().request(request).metricCollector(httpMetricCollector).contentStreamProvider(request.contentStreamProvider().orElse(null)).build());
    context.apiCallTimeoutTracker().abortable(requestCallable);
    context.apiCallAttemptTimeoutTracker().abortable(requestCallable);
    Pair<HttpExecuteResponse, Duration> measuredExecute = MetricUtils.measureDurationUnsafe(requestCallable);
    attemptMetricCollector.reportMetric(CoreMetric.SERVICE_CALL_DURATION, measuredExecute.right());
    return measuredExecute.left();
}
Also used : HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Duration(java.time.Duration) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest)

Example 82 with MetricCollector

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

the class HttpOrHttp2ChannelPoolTest method incompleteProtocolFutureDelaysMetricsDelegationAndForwardsSuccessForProtocol.

public void incompleteProtocolFutureDelaysMetricsDelegationAndForwardsSuccessForProtocol(Protocol protocol) throws Exception {
    Promise<Channel> acquirePromise = eventLoopGroup.next().newPromise();
    Promise<Void> releasePromise = eventLoopGroup.next().newPromise();
    when(mockDelegatePool.acquire()).thenReturn(acquirePromise);
    when(mockDelegatePool.release(any(Channel.class))).thenReturn(releasePromise);
    // startConnection
    httpOrHttp2ChannelPool.acquire();
    // query for metrics before the config can complete (we haven't completed acquirePromise yet)
    MetricCollector metricCollector = MetricCollector.create("foo");
    CompletableFuture<Void> metricsFuture = httpOrHttp2ChannelPool.collectChannelPoolMetrics(metricCollector);
    Thread.sleep(500);
    assertThat(metricsFuture.isDone()).isFalse();
    Channel channel = new MockChannel();
    eventLoopGroup.register(channel);
    channel.attr(PROTOCOL_FUTURE).set(CompletableFuture.completedFuture(protocol));
    acquirePromise.setSuccess(channel);
    releasePromise.setSuccess(null);
    metricsFuture.join();
    MetricCollection metrics = metricCollector.collect();
    assertThat(metrics.metricValues(HttpMetric.PENDING_CONCURRENCY_ACQUIRES).get(0)).isEqualTo(0);
    assertThat(metrics.metricValues(HttpMetric.MAX_CONCURRENCY).get(0)).isEqualTo(4);
    assertThat(metrics.metricValues(HttpMetric.AVAILABLE_CONCURRENCY).get(0)).isBetween(0, 1);
    assertThat(metrics.metricValues(HttpMetric.LEASED_CONCURRENCY).get(0)).isBetween(0, 1);
}
Also used : MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 83 with MetricCollector

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

the class CloudWatchMetricPublisherTest method defaultDimensionsIsCorrect.

@Test
public void defaultDimensionsIsCorrect() {
    try (CloudWatchMetricPublisher publisher = CloudWatchMetricPublisher.builder().cloudWatchClient(cloudWatch).build()) {
        MetricCollector collector = newCollector();
        collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
        collector.reportMetric(CoreMetric.OPERATION_NAME, "OperationName");
        collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 5);
        publisher.publish(new FixedTimeMetricCollection(collector.collect()));
    }
    PutMetricDataRequest call = getPutMetricCall();
    assertThat(call.metricData().get(0).dimensions()).containsExactlyInAnyOrder(Dimension.builder().name(CoreMetric.SERVICE_ID.name()).value("ServiceId").build(), Dimension.builder().name(CoreMetric.OPERATION_NAME.name()).value("OperationName").build());
}
Also used : PutMetricDataRequest(software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.Test)

Example 84 with MetricCollector

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

the class CloudWatchMetricPublisherTest method dimensionsSettingIsHonored.

@Test
public void dimensionsSettingIsHonored() {
    try (CloudWatchMetricPublisher publisher = publisherBuilder.dimensions(CoreMetric.SERVICE_ID).build()) {
        MetricCollector collector = newCollector();
        collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
        collector.reportMetric(CoreMetric.OPERATION_NAME, "OperationName");
        collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 5);
        publisher.publish(new FixedTimeMetricCollection(collector.collect()));
    }
    PutMetricDataRequest call = getPutMetricCall();
    assertThat(call.metricData().get(0).dimensions()).containsExactly(Dimension.builder().name(CoreMetric.SERVICE_ID.name()).value("ServiceId").build());
}
Also used : PutMetricDataRequest(software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.Test)

Example 85 with MetricCollector

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

the class CloudWatchMetricPublisherTest method namespaceSettingIsHonored.

@Test
public void namespaceSettingIsHonored() {
    try (CloudWatchMetricPublisher publisher = publisherBuilder.namespace("namespace").build()) {
        MetricCollector collector = newCollector();
        collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 5);
        publisher.publish(new FixedTimeMetricCollection(collector.collect()));
    }
    assertThat(getPutMetricCall().namespace()).isEqualTo("namespace");
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.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