Search in sources :

Example 1 with MetricCollector

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

the class DefaultMetricCollectorTest method testCreateChild_returnsChildWithCorrectName.

@Test
public void testCreateChild_returnsChildWithCorrectName() {
    MetricCollector parent = MetricCollector.create("parent");
    MetricCollector child = parent.createChild("child");
    assertThat(child.name()).isEqualTo("child");
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.Test)

Example 2 with MetricCollector

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

the class MetricUtilsTest method testCollectHttpMetrics_collectsAllExpectedMetrics.

@Test
public void testCollectHttpMetrics_collectsAllExpectedMetrics() {
    MetricCollector mockCollector = mock(MetricCollector.class);
    int statusCode = 200;
    String requestId = "request-id";
    String amznRequestId = "amzn-request-id";
    String requestId2 = "request-id-2";
    SdkHttpFullResponse response = SdkHttpFullResponse.builder().statusCode(statusCode).putHeader("x-amz-request-id", requestId).putHeader(HttpResponseHandler.X_AMZN_REQUEST_ID_HEADER, amznRequestId).putHeader(HttpResponseHandler.X_AMZ_ID_2_HEADER, requestId2).build();
    MetricUtils.collectHttpMetrics(mockCollector, response);
    verify(mockCollector).reportMetric(HttpMetric.HTTP_STATUS_CODE, statusCode);
    verify(mockCollector).reportMetric(CoreMetric.AWS_REQUEST_ID, requestId);
    verify(mockCollector).reportMetric(CoreMetric.AWS_REQUEST_ID, amznRequestId);
    verify(mockCollector).reportMetric(CoreMetric.AWS_EXTENDED_REQUEST_ID, requestId2);
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.Test)

Example 3 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector 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 4 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector 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 5 with MetricCollector

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

the class IdleConnectionCountingChannelPoolTest method getIdleConnectionCount.

private int getIdleConnectionCount() {
    MetricCollector metricCollector = MetricCollector.create("test");
    idleCountingPool.collectChannelPoolMetrics(metricCollector).join();
    return metricCollector.collect().metricValues(HttpMetric.AVAILABLE_CONCURRENCY).get(0);
}
Also used : MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

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