use of reactor.netty.Metrics.URI in project reactor-netty by reactor.
the class HttpMetricsHandlerTests method testContextAwareRecorderOnServer.
@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testContextAwareRecorderOnServer(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
ServerContextAwareRecorder recorder = ServerContextAwareRecorder.INSTANCE;
disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).metrics(true, () -> recorder).mapHandle((mono, conn) -> mono.contextWrite(Context.of("testContextAwareRecorder", "OK"))).bindNow();
CountDownLatch latch = new CountDownLatch(1);
httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols);
httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch.countDown())).post().uri("/1").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(recorder.onDataReceivedContextView).isTrue();
assertThat(recorder.onDataSentContextView).isTrue();
}
use of reactor.netty.Metrics.URI in project reactor-netty by reactor.
the class HttpMetricsHandlerTests method testUriTagValueFunctionNotSharedForClient.
/**
* https://github.com/reactor/reactor-netty/issues/1559
*/
@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testUriTagValueFunctionNotSharedForClient(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).metrics(true, s -> {
if ("/1".equals(s)) {
return "testUriTagValueFunctionNotShared_1";
} else {
return "testUriTagValueFunctionNotShared_2";
}
}).bindNow();
AtomicReference<SocketAddress> serverAddress = new AtomicReference<>();
httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols).doAfterRequest((req, conn) -> serverAddress.set(conn.channel().remoteAddress()));
CountDownLatch latch1 = new CountDownLatch(1);
httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch1.countDown())).metrics(true, s -> "testUriTagValueFunctionNotShared_1").post().uri("/1").send(body).responseContent().aggregate().asString().as(StepVerifier::create).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("testUriTagValueFunctionNotShared_1", sa.getHostString() + ":" + sa.getPort(), 1, serverCtx != null);
CountDownLatch latch2 = new CountDownLatch(1);
httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch2.countDown())).metrics(true, s -> "testUriTagValueFunctionNotShared_2").post().uri("/2").send(body).responseContent().aggregate().asString().as(StepVerifier::create).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch1.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
sa = (InetSocketAddress) serverAddress.get();
Thread.sleep(1000);
checkExpectationsExisting("testUriTagValueFunctionNotShared_2", sa.getHostString() + ":" + sa.getPort(), 2, serverCtx != null);
}
use of reactor.netty.Metrics.URI in project reactor-netty by reactor.
the class HttpMetricsHandlerTests method testNonExistingEndpoint.
@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testNonExistingEndpoint(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())).headers(h -> h.add("Connection", "close")).get().uri("/3").responseContent().aggregate().asString()).expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch1.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
InetSocketAddress sa = (InetSocketAddress) serverAddress.get();
Thread.sleep(1000);
checkExpectationsNonExisting(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())).headers(h -> h.add("Connection", "close")).get().uri("/3").responseContent().aggregate().asString()).expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch2.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
sa = (InetSocketAddress) serverAddress.get();
Thread.sleep(1000);
checkExpectationsNonExisting(sa.getHostString() + ":" + sa.getPort(), 2, serverCtx != null);
}
use of reactor.netty.Metrics.URI 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