Search in sources :

Example 1 with MetricCollection

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

the class NettyNioAsyncHttpClientWireMockTest method metricsAreCollectedForClosedClientCalls.

@Test
public void metricsAreCollectedForClosedClientCalls() throws Exception {
    SdkAsyncHttpClient customClient = NettyNioAsyncHttpClient.builder().maxConcurrency(10).build();
    customClient.close();
    RecordingResponseHandler handler = makeSimpleRequestAndReturnResponseHandler(customClient);
    try {
        handler.executionFuture.get(10, TimeUnit.SECONDS);
    } catch (Exception e) {
    // Expected
    }
    MetricCollection metrics = handler.collector.collect();
    assertThat(metrics.metricValues(HttpMetric.HTTP_CLIENT_NAME)).containsExactly("NettyNio");
    assertThat(metrics.metricValues(HttpMetric.MAX_CONCURRENCY)).containsExactly(10);
    assertThat(metrics.metricValues(HttpMetric.PENDING_CONCURRENCY_ACQUIRES)).containsExactly(0);
    assertThat(metrics.metricValues(HttpMetric.LEASED_CONCURRENCY)).containsExactly(0);
    assertThat(metrics.metricValues(HttpMetric.AVAILABLE_CONCURRENCY).get(0)).isBetween(0, 1);
}
Also used : MetricCollection(software.amazon.awssdk.metrics.MetricCollection) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with MetricCollection

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

the class Http2MetricsTest method maxClientStreamsHigherThanServerMaxStreamsReportServerMaxStreams.

@Test
public void maxClientStreamsHigherThanServerMaxStreamsReportServerMaxStreams() {
    try (SdkAsyncHttpClient client = NettyNioAsyncHttpClient.builder().protocol(Protocol.HTTP2).maxConcurrency(10).http2Configuration(c -> c.maxStreams(3L).initialWindowSize(65535 * 3)).build()) {
        MetricCollector metricCollector = MetricCollector.create("test");
        client.execute(createExecuteRequest(metricCollector)).join();
        MetricCollection metrics = metricCollector.collect();
        assertThat(metrics.metricValues(HttpMetric.HTTP_CLIENT_NAME)).containsExactly("NettyNio");
        assertThat(metrics.metricValues(HttpMetric.MAX_CONCURRENCY)).containsExactly(10);
        assertThat(metrics.metricValues(HttpMetric.LEASED_CONCURRENCY).get(0)).isBetween(0, 1);
        assertThat(metrics.metricValues(HttpMetric.PENDING_CONCURRENCY_ACQUIRES).get(0)).isBetween(0, 1);
        assertThat(metrics.metricValues(HttpMetric.AVAILABLE_CONCURRENCY).get(0)).isIn(0, 2, 3);
        assertThat(metrics.metricValues(HttpMetric.CONCURRENCY_ACQUIRE_DURATION).get(0)).isPositive();
        // The stream window doesn't get initialized with the connection
        // initial setting and the update appears to be asynchronous so
        // this may be the default window size just based on when the
        // stream window was queried or if this is the first time the
        // stream is used (i.e. not previously pooled)
        assertThat(metrics.metricValues(Http2Metric.LOCAL_STREAM_WINDOW_SIZE_IN_BYTES).get(0)).isIn(H2_DEFAULT_WINDOW_SIZE, 65535 * 3);
        assertThat(metrics.metricValues(Http2Metric.REMOTE_STREAM_WINDOW_SIZE_IN_BYTES)).containsExactly(SERVER_INITIAL_WINDOW_SIZE);
    }
}
Also used : Http2Metric(software.amazon.awssdk.http.Http2Metric) ChannelOption(io.netty.channel.ChannelOption) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Protocol(software.amazon.awssdk.http.Protocol) Http2StreamFrame(io.netty.handler.codec.http2.Http2StreamFrame) Http2FrameCodecBuilder(io.netty.handler.codec.http2.Http2FrameCodecBuilder) Http2Frame(io.netty.handler.codec.http2.Http2Frame) ServerSocketChannel(io.netty.channel.socket.ServerSocketChannel) AfterAll(org.junit.jupiter.api.AfterAll) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) BeforeAll(org.junit.jupiter.api.BeforeAll) Http2DataFrame(io.netty.handler.codec.http2.Http2DataFrame) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) URI(java.net.URI) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) EmptyPublisher(software.amazon.awssdk.http.EmptyPublisher) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) SocketChannel(io.netty.channel.socket.SocketChannel) ChannelInitializer(io.netty.channel.ChannelInitializer) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) DefaultHttp2HeadersFrame(io.netty.handler.codec.http2.DefaultHttp2HeadersFrame) HttpMetric(software.amazon.awssdk.http.HttpMetric) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Http2FrameCodec(io.netty.handler.codec.http2.Http2FrameCodec) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Http2HeadersFrame(io.netty.handler.codec.http2.Http2HeadersFrame) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) Http2Settings(io.netty.handler.codec.http2.Http2Settings) Test(org.junit.jupiter.api.Test) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Test(org.junit.jupiter.api.Test)

Example 3 with MetricCollection

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

the class Http2MetricsTest method maxClientStreamsLowerThanServerMaxStreamsReportClientMaxStreams.

@Test
public void maxClientStreamsLowerThanServerMaxStreamsReportClientMaxStreams() {
    try (SdkAsyncHttpClient client = NettyNioAsyncHttpClient.builder().protocol(Protocol.HTTP2).maxConcurrency(10).http2Configuration(c -> c.maxStreams(1L).initialWindowSize(65535 * 3)).build()) {
        MetricCollector metricCollector = MetricCollector.create("test");
        client.execute(createExecuteRequest(metricCollector)).join();
        MetricCollection metrics = metricCollector.collect();
        assertThat(metrics.metricValues(HttpMetric.HTTP_CLIENT_NAME)).containsExactly("NettyNio");
        assertThat(metrics.metricValues(HttpMetric.MAX_CONCURRENCY)).containsExactly(10);
        assertThat(metrics.metricValues(HttpMetric.LEASED_CONCURRENCY).get(0)).isBetween(0, 1);
        assertThat(metrics.metricValues(HttpMetric.PENDING_CONCURRENCY_ACQUIRES).get(0)).isBetween(0, 1);
        assertThat(metrics.metricValues(HttpMetric.AVAILABLE_CONCURRENCY)).containsExactly(0);
        assertThat(metrics.metricValues(HttpMetric.CONCURRENCY_ACQUIRE_DURATION).get(0)).isPositive();
        // The stream window doesn't get initialized with the connection
        // initial setting and the update appears to be asynchronous so
        // this may be the default window size just based on when the
        // stream window was queried or if this is the first time the
        // stream is used (i.e. not previously pooled)
        assertThat(metrics.metricValues(Http2Metric.LOCAL_STREAM_WINDOW_SIZE_IN_BYTES).get(0)).isIn(H2_DEFAULT_WINDOW_SIZE, 65535 * 3);
        assertThat(metrics.metricValues(Http2Metric.REMOTE_STREAM_WINDOW_SIZE_IN_BYTES)).containsExactly(SERVER_INITIAL_WINDOW_SIZE);
    }
}
Also used : Http2Metric(software.amazon.awssdk.http.Http2Metric) ChannelOption(io.netty.channel.ChannelOption) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Protocol(software.amazon.awssdk.http.Protocol) Http2StreamFrame(io.netty.handler.codec.http2.Http2StreamFrame) Http2FrameCodecBuilder(io.netty.handler.codec.http2.Http2FrameCodecBuilder) Http2Frame(io.netty.handler.codec.http2.Http2Frame) ServerSocketChannel(io.netty.channel.socket.ServerSocketChannel) AfterAll(org.junit.jupiter.api.AfterAll) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) BeforeAll(org.junit.jupiter.api.BeforeAll) Http2DataFrame(io.netty.handler.codec.http2.Http2DataFrame) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) URI(java.net.URI) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) EmptyPublisher(software.amazon.awssdk.http.EmptyPublisher) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) SocketChannel(io.netty.channel.socket.SocketChannel) ChannelInitializer(io.netty.channel.ChannelInitializer) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) DefaultHttp2HeadersFrame(io.netty.handler.codec.http2.DefaultHttp2HeadersFrame) HttpMetric(software.amazon.awssdk.http.HttpMetric) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Http2FrameCodec(io.netty.handler.codec.http2.Http2FrameCodec) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Http2HeadersFrame(io.netty.handler.codec.http2.Http2HeadersFrame) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) Http2Settings(io.netty.handler.codec.http2.Http2Settings) Test(org.junit.jupiter.api.Test) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Test(org.junit.jupiter.api.Test)

Example 4 with MetricCollection

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

the class BaseAsyncCoreMetricsTest method apiCall_operationSuccessful_addsMetrics.

@Test
public void apiCall_operationSuccessful_addsMetrics() {
    stubSuccessfulResponse();
    callable().get().join();
    addDelayIfNeeded();
    ArgumentCaptor<MetricCollection> collectionCaptor = ArgumentCaptor.forClass(MetricCollection.class);
    verify(publisher()).publish(collectionCaptor.capture());
    MetricCollection capturedCollection = collectionCaptor.getValue();
    verifySuccessfulApiCallCollection(capturedCollection);
    assertThat(capturedCollection.children()).hasSize(1);
    MetricCollection attemptCollection = capturedCollection.children().get(0);
    assertThat(attemptCollection.name()).isEqualTo("ApiCallAttempt");
    verifySuccessfulApiCallAttemptCollection(attemptCollection);
    assertThat(attemptCollection.metricValues(CoreMetric.SERVICE_CALL_DURATION).get(0)).isGreaterThanOrEqualTo(FIXED_DELAY);
}
Also used : MetricCollection(software.amazon.awssdk.metrics.MetricCollection) Test(org.junit.Test)

Example 5 with MetricCollection

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

the class BaseAsyncCoreMetricsTest method apiCall_allRetryAttemptsFailedOf500.

@Test
public void apiCall_allRetryAttemptsFailedOf500() {
    stubErrorResponse();
    assertThatThrownBy(() -> callable().get().join()).hasCauseInstanceOf(EmptyModeledException.class);
    addDelayIfNeeded();
    ArgumentCaptor<MetricCollection> collectionCaptor = ArgumentCaptor.forClass(MetricCollection.class);
    verify(publisher()).publish(collectionCaptor.capture());
    MetricCollection capturedCollection = collectionCaptor.getValue();
    verifyFailedApiCallCollection(capturedCollection);
    assertThat(capturedCollection.children()).hasSize(MAX_RETRIES + 1);
    capturedCollection.children().forEach(this::verifyFailedApiCallAttemptCollection);
}
Also used : MetricCollection(software.amazon.awssdk.metrics.MetricCollection) Test(org.junit.Test)

Aggregations

MetricCollection (software.amazon.awssdk.metrics.MetricCollection)22 Test (org.junit.Test)16 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)9 SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)6 SocketChannel (io.netty.channel.socket.SocketChannel)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2 Channel (io.netty.channel.Channel)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)2 ChannelInitializer (io.netty.channel.ChannelInitializer)2 ChannelOption (io.netty.channel.ChannelOption)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 ServerSocketChannel (io.netty.channel.socket.ServerSocketChannel)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)2 DefaultHttp2HeadersFrame (io.netty.handler.codec.http2.DefaultHttp2HeadersFrame)2