use of reactor.netty.Metrics.LOCAL_ADDRESS in project reactor-netty by reactor.
the class HttpMetricsHandlerTests method testServerConnectionsMicrometer.
@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testServerConnectionsMicrometer(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).metrics(true, Function.identity()).bindNow();
AtomicReference<SocketAddress> clientAddress = new AtomicReference<>();
httpClient = httpClient.doAfterRequest((req, conn) -> clientAddress.set(conn.channel().localAddress()));
String uri = "/4";
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(uri).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();
// ensure that the server counters have been updated. For the moment, wait 1 sec.
Thread.sleep(1000);
// now check the server counters
checkGauge(SERVER_CONNECTIONS_TOTAL, true, 0, URI, HTTP, LOCAL_ADDRESS, address);
checkGauge(SERVER_CONNECTIONS_ACTIVE, true, 0, URI, HTTP, LOCAL_ADDRESS, address);
// These metrics are meant only for the servers,
// connections metrics for the clients are available from the connection pool
address = formatSocketAddress(clientAddress.get());
checkGauge(CLIENT_CONNECTIONS_TOTAL, false, 0, URI, HTTP, LOCAL_ADDRESS, address);
checkGauge(CLIENT_CONNECTIONS_ACTIVE, false, 0, URI, HTTP, LOCAL_ADDRESS, address);
disposableServer.disposeNow();
}
Aggregations