Search in sources :

Example 1 with URI

use of reactor.netty.Metrics.URI in project reactor-netty by reactor.

the class HttpMetricsHandlerTests method testServerConnectionsRecorder.

@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testServerConnectionsRecorder(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
    disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).metrics(true, () -> ServerRecorder.INSTANCE, Function.identity()).bindNow();
    String address = formatSocketAddress(disposableServer.address());
    CountDownLatch latch = new CountDownLatch(1);
    httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols);
    httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch.countDown())).metrics(true, Function.identity()).post().uri("/5").send(body).responseContent().aggregate().asString().as(StepVerifier::create).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
    assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    assertThat(ServerRecorder.INSTANCE.done.await(30, TimeUnit.SECONDS)).as("recorder latch await").isTrue();
    assertThat(ServerRecorder.INSTANCE.onServerConnectionsAmount.get()).isEqualTo(0);
    assertThat(ServerRecorder.INSTANCE.onActiveConnectionsAmount.get()).isEqualTo(0);
    assertThat(ServerRecorder.INSTANCE.onActiveConnectionsLocalAddr.get()).isEqualTo(address);
    assertThat(ServerRecorder.INSTANCE.onInactiveConnectionsLocalAddr.get()).isEqualTo(address);
    disposableServer.disposeNow();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) SocketAddress(java.net.SocketAddress) ContextView(reactor.util.context.ContextView) ContextAwareHttpServerMetricsRecorder(reactor.netty.http.server.ContextAwareHttpServerMetricsRecorder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BaseHttpTest(reactor.netty.BaseHttpTest) DATA_SENT_TIME(reactor.netty.Metrics.DATA_SENT_TIME) Counter(io.micrometer.api.instrument.Counter) Tags(io.micrometer.api.instrument.Tags) ProtocolSslContextSpec(reactor.netty.tcp.SslProvider.ProtocolSslContextSpec) BeforeAll(org.junit.jupiter.api.BeforeAll) ByteBufFlux(reactor.netty.ByteBufFlux) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) MethodSource(org.junit.jupiter.params.provider.MethodSource) Timer(io.micrometer.api.instrument.Timer) ERRORS(reactor.netty.Metrics.ERRORS) RESPONSE_TIME(reactor.netty.Metrics.RESPONSE_TIME) Context(reactor.util.context.Context) TLS_HANDSHAKE_TIME(reactor.netty.Metrics.TLS_HANDSHAKE_TIME) MeterRegistryAssert(io.micrometer.core.tck.MeterRegistryAssert) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) DistributionSummary(io.micrometer.api.instrument.DistributionSummary) HTTP_CLIENT_PREFIX(reactor.netty.Metrics.HTTP_CLIENT_PREFIX) Test(org.junit.jupiter.api.Test) STATUS(reactor.netty.Metrics.STATUS) ContextAwareHttpClientMetricsRecorder(reactor.netty.http.client.ContextAwareHttpClientMetricsRecorder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpServer(reactor.netty.http.server.HttpServer) Stream(java.util.stream.Stream) Named(org.junit.jupiter.api.Named) CONNECT_TIME(reactor.netty.Metrics.CONNECT_TIME) Gauge(io.micrometer.api.instrument.Gauge) HttpClient(reactor.netty.http.client.HttpClient) SimpleMeterRegistry(io.micrometer.api.instrument.simple.SimpleMeterRegistry) REMOTE_ADDRESS(reactor.netty.Metrics.REMOTE_ADDRESS) HTTP_SERVER_PREFIX(reactor.netty.Metrics.HTTP_SERVER_PREFIX) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Nullable(reactor.util.annotation.Nullable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ByteBuf(io.netty.buffer.ByteBuf) DATA_SENT(reactor.netty.Metrics.DATA_SENT) METHOD(reactor.netty.Metrics.METHOD) DATA_RECEIVED_TIME(reactor.netty.Metrics.DATA_RECEIVED_TIME) Metrics.formatSocketAddress(reactor.netty.Metrics.formatSocketAddress) CONNECTIONS_ACTIVE(reactor.netty.Metrics.CONNECTIONS_ACTIVE) CONNECTIONS_TOTAL(reactor.netty.Metrics.CONNECTIONS_TOTAL) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) HttpServerMetricsRecorder(reactor.netty.http.server.HttpServerMetricsRecorder) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) LOCAL_ADDRESS(reactor.netty.Metrics.LOCAL_ADDRESS) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SslProvider(io.netty.handler.ssl.SslProvider) MeterRegistry(io.micrometer.api.instrument.MeterRegistry) Metrics(io.micrometer.api.instrument.Metrics) DATA_RECEIVED(reactor.netty.Metrics.DATA_RECEIVED) ConnectionProvider(reactor.netty.resources.ConnectionProvider) URI(reactor.netty.Metrics.URI) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with URI

use of reactor.netty.Metrics.URI in project reactor-netty by reactor.

the class HttpMetricsHandlerTests method testIssue896.

@Test
void testIssue896() throws Exception {
    disposableServer = httpServer.noSSL().bindNow();
    CountDownLatch latch = new CountDownLatch(1);
    httpClient.observe((conn, state) -> conn.channel().closeFuture().addListener(f -> latch.countDown())).secure(spec -> spec.sslContext(clientCtx11)).post().uri("/1").send(ByteBufFlux.fromString(Mono.just("hello"))).responseContent().subscribe();
    assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    Thread.sleep(1000);
    InetSocketAddress sa = (InetSocketAddress) disposableServer.channel().localAddress();
    String serverAddress = sa.getHostString() + ":" + sa.getPort();
    String[] summaryTags = new String[] { REMOTE_ADDRESS, serverAddress, URI, "unknown" };
    checkCounter(CLIENT_ERRORS, summaryTags, true, 2);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) SocketAddress(java.net.SocketAddress) ContextView(reactor.util.context.ContextView) ContextAwareHttpServerMetricsRecorder(reactor.netty.http.server.ContextAwareHttpServerMetricsRecorder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BaseHttpTest(reactor.netty.BaseHttpTest) DATA_SENT_TIME(reactor.netty.Metrics.DATA_SENT_TIME) Counter(io.micrometer.api.instrument.Counter) Tags(io.micrometer.api.instrument.Tags) ProtocolSslContextSpec(reactor.netty.tcp.SslProvider.ProtocolSslContextSpec) BeforeAll(org.junit.jupiter.api.BeforeAll) ByteBufFlux(reactor.netty.ByteBufFlux) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) MethodSource(org.junit.jupiter.params.provider.MethodSource) Timer(io.micrometer.api.instrument.Timer) ERRORS(reactor.netty.Metrics.ERRORS) RESPONSE_TIME(reactor.netty.Metrics.RESPONSE_TIME) Context(reactor.util.context.Context) TLS_HANDSHAKE_TIME(reactor.netty.Metrics.TLS_HANDSHAKE_TIME) MeterRegistryAssert(io.micrometer.core.tck.MeterRegistryAssert) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) DistributionSummary(io.micrometer.api.instrument.DistributionSummary) HTTP_CLIENT_PREFIX(reactor.netty.Metrics.HTTP_CLIENT_PREFIX) Test(org.junit.jupiter.api.Test) STATUS(reactor.netty.Metrics.STATUS) ContextAwareHttpClientMetricsRecorder(reactor.netty.http.client.ContextAwareHttpClientMetricsRecorder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpServer(reactor.netty.http.server.HttpServer) Stream(java.util.stream.Stream) Named(org.junit.jupiter.api.Named) CONNECT_TIME(reactor.netty.Metrics.CONNECT_TIME) Gauge(io.micrometer.api.instrument.Gauge) HttpClient(reactor.netty.http.client.HttpClient) SimpleMeterRegistry(io.micrometer.api.instrument.simple.SimpleMeterRegistry) REMOTE_ADDRESS(reactor.netty.Metrics.REMOTE_ADDRESS) HTTP_SERVER_PREFIX(reactor.netty.Metrics.HTTP_SERVER_PREFIX) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Nullable(reactor.util.annotation.Nullable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ByteBuf(io.netty.buffer.ByteBuf) DATA_SENT(reactor.netty.Metrics.DATA_SENT) METHOD(reactor.netty.Metrics.METHOD) DATA_RECEIVED_TIME(reactor.netty.Metrics.DATA_RECEIVED_TIME) Metrics.formatSocketAddress(reactor.netty.Metrics.formatSocketAddress) CONNECTIONS_ACTIVE(reactor.netty.Metrics.CONNECTIONS_ACTIVE) CONNECTIONS_TOTAL(reactor.netty.Metrics.CONNECTIONS_TOTAL) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) HttpServerMetricsRecorder(reactor.netty.http.server.HttpServerMetricsRecorder) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) LOCAL_ADDRESS(reactor.netty.Metrics.LOCAL_ADDRESS) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SslProvider(io.netty.handler.ssl.SslProvider) MeterRegistry(io.micrometer.api.instrument.MeterRegistry) Metrics(io.micrometer.api.instrument.Metrics) DATA_RECEIVED(reactor.netty.Metrics.DATA_RECEIVED) ConnectionProvider(reactor.netty.resources.ConnectionProvider) URI(reactor.netty.Metrics.URI) InetSocketAddress(java.net.InetSocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) BaseHttpTest(reactor.netty.BaseHttpTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with URI

use of reactor.netty.Metrics.URI in project reactor-netty by reactor.

the class HttpMetricsHandlerTests method testUriTagValueFunction.

@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testUriTagValueFunction(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
    disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).metrics(true, s -> "testUriTagValueResolver").bindNow();
    AtomicReference<SocketAddress> serverAddress = new AtomicReference<>();
    httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols).doAfterRequest((req, conn) -> serverAddress.set(conn.channel().remoteAddress()));
    CountDownLatch latch1 = new CountDownLatch(1);
    StepVerifier.create(httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch1.countDown())).metrics(true, s -> "testUriTagValueResolver").post().uri("/1").send(body).responseContent().aggregate().asString()).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
    assertThat(latch1.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    InetSocketAddress sa = (InetSocketAddress) serverAddress.get();
    Thread.sleep(1000);
    checkExpectationsExisting("testUriTagValueResolver", sa.getHostString() + ":" + sa.getPort(), 1, serverCtx != null);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) SocketAddress(java.net.SocketAddress) ContextView(reactor.util.context.ContextView) ContextAwareHttpServerMetricsRecorder(reactor.netty.http.server.ContextAwareHttpServerMetricsRecorder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BaseHttpTest(reactor.netty.BaseHttpTest) DATA_SENT_TIME(reactor.netty.Metrics.DATA_SENT_TIME) Counter(io.micrometer.api.instrument.Counter) Tags(io.micrometer.api.instrument.Tags) ProtocolSslContextSpec(reactor.netty.tcp.SslProvider.ProtocolSslContextSpec) BeforeAll(org.junit.jupiter.api.BeforeAll) ByteBufFlux(reactor.netty.ByteBufFlux) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) MethodSource(org.junit.jupiter.params.provider.MethodSource) Timer(io.micrometer.api.instrument.Timer) ERRORS(reactor.netty.Metrics.ERRORS) RESPONSE_TIME(reactor.netty.Metrics.RESPONSE_TIME) Context(reactor.util.context.Context) TLS_HANDSHAKE_TIME(reactor.netty.Metrics.TLS_HANDSHAKE_TIME) MeterRegistryAssert(io.micrometer.core.tck.MeterRegistryAssert) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) DistributionSummary(io.micrometer.api.instrument.DistributionSummary) HTTP_CLIENT_PREFIX(reactor.netty.Metrics.HTTP_CLIENT_PREFIX) Test(org.junit.jupiter.api.Test) STATUS(reactor.netty.Metrics.STATUS) ContextAwareHttpClientMetricsRecorder(reactor.netty.http.client.ContextAwareHttpClientMetricsRecorder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpServer(reactor.netty.http.server.HttpServer) Stream(java.util.stream.Stream) Named(org.junit.jupiter.api.Named) CONNECT_TIME(reactor.netty.Metrics.CONNECT_TIME) Gauge(io.micrometer.api.instrument.Gauge) HttpClient(reactor.netty.http.client.HttpClient) SimpleMeterRegistry(io.micrometer.api.instrument.simple.SimpleMeterRegistry) REMOTE_ADDRESS(reactor.netty.Metrics.REMOTE_ADDRESS) HTTP_SERVER_PREFIX(reactor.netty.Metrics.HTTP_SERVER_PREFIX) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Nullable(reactor.util.annotation.Nullable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ByteBuf(io.netty.buffer.ByteBuf) DATA_SENT(reactor.netty.Metrics.DATA_SENT) METHOD(reactor.netty.Metrics.METHOD) DATA_RECEIVED_TIME(reactor.netty.Metrics.DATA_RECEIVED_TIME) Metrics.formatSocketAddress(reactor.netty.Metrics.formatSocketAddress) CONNECTIONS_ACTIVE(reactor.netty.Metrics.CONNECTIONS_ACTIVE) CONNECTIONS_TOTAL(reactor.netty.Metrics.CONNECTIONS_TOTAL) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) HttpServerMetricsRecorder(reactor.netty.http.server.HttpServerMetricsRecorder) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) LOCAL_ADDRESS(reactor.netty.Metrics.LOCAL_ADDRESS) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SslProvider(io.netty.handler.ssl.SslProvider) MeterRegistry(io.micrometer.api.instrument.MeterRegistry) Metrics(io.micrometer.api.instrument.Metrics) DATA_RECEIVED(reactor.netty.Metrics.DATA_RECEIVED) ConnectionProvider(reactor.netty.resources.ConnectionProvider) URI(reactor.netty.Metrics.URI) InetSocketAddress(java.net.InetSocketAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Metrics.formatSocketAddress(reactor.netty.Metrics.formatSocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with URI

use of reactor.netty.Metrics.URI in project reactor-netty by reactor.

the class HttpMetricsHandlerTests method testExistingEndpoint.

@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testExistingEndpoint(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
    disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).bindNow();
    AtomicReference<SocketAddress> serverAddress = new AtomicReference<>();
    httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols).doAfterRequest((req, conn) -> serverAddress.set(conn.channel().remoteAddress()));
    CountDownLatch latch1 = new CountDownLatch(1);
    StepVerifier.create(httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch1.countDown())).post().uri("/1").send(body).responseContent().aggregate().asString()).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
    assertThat(latch1.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    InetSocketAddress sa = (InetSocketAddress) serverAddress.get();
    Thread.sleep(1000);
    checkExpectationsExisting("/1", sa.getHostString() + ":" + sa.getPort(), 1, serverCtx != null);
    CountDownLatch latch2 = new CountDownLatch(1);
    StepVerifier.create(httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch2.countDown())).post().uri("/2?i=1&j=2").send(body).responseContent().aggregate().asString()).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
    assertThat(latch2.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    sa = (InetSocketAddress) serverAddress.get();
    Thread.sleep(1000);
    checkExpectationsExisting("/2", sa.getHostString() + ":" + sa.getPort(), 2, serverCtx != null);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) SocketAddress(java.net.SocketAddress) ContextView(reactor.util.context.ContextView) ContextAwareHttpServerMetricsRecorder(reactor.netty.http.server.ContextAwareHttpServerMetricsRecorder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BaseHttpTest(reactor.netty.BaseHttpTest) DATA_SENT_TIME(reactor.netty.Metrics.DATA_SENT_TIME) Counter(io.micrometer.api.instrument.Counter) Tags(io.micrometer.api.instrument.Tags) ProtocolSslContextSpec(reactor.netty.tcp.SslProvider.ProtocolSslContextSpec) BeforeAll(org.junit.jupiter.api.BeforeAll) ByteBufFlux(reactor.netty.ByteBufFlux) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) MethodSource(org.junit.jupiter.params.provider.MethodSource) Timer(io.micrometer.api.instrument.Timer) ERRORS(reactor.netty.Metrics.ERRORS) RESPONSE_TIME(reactor.netty.Metrics.RESPONSE_TIME) Context(reactor.util.context.Context) TLS_HANDSHAKE_TIME(reactor.netty.Metrics.TLS_HANDSHAKE_TIME) MeterRegistryAssert(io.micrometer.core.tck.MeterRegistryAssert) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) DistributionSummary(io.micrometer.api.instrument.DistributionSummary) HTTP_CLIENT_PREFIX(reactor.netty.Metrics.HTTP_CLIENT_PREFIX) Test(org.junit.jupiter.api.Test) STATUS(reactor.netty.Metrics.STATUS) ContextAwareHttpClientMetricsRecorder(reactor.netty.http.client.ContextAwareHttpClientMetricsRecorder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpServer(reactor.netty.http.server.HttpServer) Stream(java.util.stream.Stream) Named(org.junit.jupiter.api.Named) CONNECT_TIME(reactor.netty.Metrics.CONNECT_TIME) Gauge(io.micrometer.api.instrument.Gauge) HttpClient(reactor.netty.http.client.HttpClient) SimpleMeterRegistry(io.micrometer.api.instrument.simple.SimpleMeterRegistry) REMOTE_ADDRESS(reactor.netty.Metrics.REMOTE_ADDRESS) HTTP_SERVER_PREFIX(reactor.netty.Metrics.HTTP_SERVER_PREFIX) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Nullable(reactor.util.annotation.Nullable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ByteBuf(io.netty.buffer.ByteBuf) DATA_SENT(reactor.netty.Metrics.DATA_SENT) METHOD(reactor.netty.Metrics.METHOD) DATA_RECEIVED_TIME(reactor.netty.Metrics.DATA_RECEIVED_TIME) Metrics.formatSocketAddress(reactor.netty.Metrics.formatSocketAddress) CONNECTIONS_ACTIVE(reactor.netty.Metrics.CONNECTIONS_ACTIVE) CONNECTIONS_TOTAL(reactor.netty.Metrics.CONNECTIONS_TOTAL) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) HttpServerMetricsRecorder(reactor.netty.http.server.HttpServerMetricsRecorder) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) LOCAL_ADDRESS(reactor.netty.Metrics.LOCAL_ADDRESS) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SslProvider(io.netty.handler.ssl.SslProvider) MeterRegistry(io.micrometer.api.instrument.MeterRegistry) Metrics(io.micrometer.api.instrument.Metrics) DATA_RECEIVED(reactor.netty.Metrics.DATA_RECEIVED) ConnectionProvider(reactor.netty.resources.ConnectionProvider) URI(reactor.netty.Metrics.URI) InetSocketAddress(java.net.InetSocketAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Metrics.formatSocketAddress(reactor.netty.Metrics.formatSocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with URI

use of reactor.netty.Metrics.URI in project reactor-netty by reactor.

the class HttpMetricsHandlerTests method testContextAwareRecorderOnClient.

@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testContextAwareRecorderOnClient(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
    disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).bindNow();
    ClientContextAwareRecorder recorder = ClientContextAwareRecorder.INSTANCE;
    CountDownLatch latch = new CountDownLatch(1);
    httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols);
    httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch.countDown())).metrics(true, () -> recorder).post().uri("/1").send(body).responseContent().aggregate().asString().contextWrite(Context.of("testContextAwareRecorder", "OK")).as(StepVerifier::create).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
    assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    assertThat(recorder.onDataReceivedContextView).isTrue();
    assertThat(recorder.onDataSentContextView).isTrue();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) SocketAddress(java.net.SocketAddress) ContextView(reactor.util.context.ContextView) ContextAwareHttpServerMetricsRecorder(reactor.netty.http.server.ContextAwareHttpServerMetricsRecorder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BaseHttpTest(reactor.netty.BaseHttpTest) DATA_SENT_TIME(reactor.netty.Metrics.DATA_SENT_TIME) Counter(io.micrometer.api.instrument.Counter) Tags(io.micrometer.api.instrument.Tags) ProtocolSslContextSpec(reactor.netty.tcp.SslProvider.ProtocolSslContextSpec) BeforeAll(org.junit.jupiter.api.BeforeAll) ByteBufFlux(reactor.netty.ByteBufFlux) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) MethodSource(org.junit.jupiter.params.provider.MethodSource) Timer(io.micrometer.api.instrument.Timer) ERRORS(reactor.netty.Metrics.ERRORS) RESPONSE_TIME(reactor.netty.Metrics.RESPONSE_TIME) Context(reactor.util.context.Context) TLS_HANDSHAKE_TIME(reactor.netty.Metrics.TLS_HANDSHAKE_TIME) MeterRegistryAssert(io.micrometer.core.tck.MeterRegistryAssert) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) DistributionSummary(io.micrometer.api.instrument.DistributionSummary) HTTP_CLIENT_PREFIX(reactor.netty.Metrics.HTTP_CLIENT_PREFIX) Test(org.junit.jupiter.api.Test) STATUS(reactor.netty.Metrics.STATUS) ContextAwareHttpClientMetricsRecorder(reactor.netty.http.client.ContextAwareHttpClientMetricsRecorder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpServer(reactor.netty.http.server.HttpServer) Stream(java.util.stream.Stream) Named(org.junit.jupiter.api.Named) CONNECT_TIME(reactor.netty.Metrics.CONNECT_TIME) Gauge(io.micrometer.api.instrument.Gauge) HttpClient(reactor.netty.http.client.HttpClient) SimpleMeterRegistry(io.micrometer.api.instrument.simple.SimpleMeterRegistry) REMOTE_ADDRESS(reactor.netty.Metrics.REMOTE_ADDRESS) HTTP_SERVER_PREFIX(reactor.netty.Metrics.HTTP_SERVER_PREFIX) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Nullable(reactor.util.annotation.Nullable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ByteBuf(io.netty.buffer.ByteBuf) DATA_SENT(reactor.netty.Metrics.DATA_SENT) METHOD(reactor.netty.Metrics.METHOD) DATA_RECEIVED_TIME(reactor.netty.Metrics.DATA_RECEIVED_TIME) Metrics.formatSocketAddress(reactor.netty.Metrics.formatSocketAddress) CONNECTIONS_ACTIVE(reactor.netty.Metrics.CONNECTIONS_ACTIVE) CONNECTIONS_TOTAL(reactor.netty.Metrics.CONNECTIONS_TOTAL) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) HttpServerMetricsRecorder(reactor.netty.http.server.HttpServerMetricsRecorder) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) LOCAL_ADDRESS(reactor.netty.Metrics.LOCAL_ADDRESS) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SslProvider(io.netty.handler.ssl.SslProvider) MeterRegistry(io.micrometer.api.instrument.MeterRegistry) Metrics(io.micrometer.api.instrument.Metrics) DATA_RECEIVED(reactor.netty.Metrics.DATA_RECEIVED) ConnectionProvider(reactor.netty.resources.ConnectionProvider) URI(reactor.netty.Metrics.URI) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Counter (io.micrometer.api.instrument.Counter)9 DistributionSummary (io.micrometer.api.instrument.DistributionSummary)9 Gauge (io.micrometer.api.instrument.Gauge)9 MeterRegistry (io.micrometer.api.instrument.MeterRegistry)9 Metrics (io.micrometer.api.instrument.Metrics)9 Tags (io.micrometer.api.instrument.Tags)9 Timer (io.micrometer.api.instrument.Timer)9 SimpleMeterRegistry (io.micrometer.api.instrument.simple.SimpleMeterRegistry)9 MeterRegistryAssert (io.micrometer.core.tck.MeterRegistryAssert)9 ByteBuf (io.netty.buffer.ByteBuf)9 SslProvider (io.netty.handler.ssl.SslProvider)9 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)9 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)9 InetSocketAddress (java.net.InetSocketAddress)9 SocketAddress (java.net.SocketAddress)9 CertificateException (java.security.cert.CertificateException)9 Duration (java.time.Duration)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 TimeUnit (java.util.concurrent.TimeUnit)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9