use of io.micrometer.api.instrument.Metrics 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();
}
use of io.micrometer.api.instrument.Metrics in project reactor-netty by reactor.
the class AddressResolverGroupMetricsTest method test.
@Test
void test() throws Exception {
disposableServer = createServer().host("localhost").handle((req, res) -> res.header("Connection", "close").sendString(Mono.just("test"))).bindNow();
CountDownLatch latch = new CountDownLatch(1);
HttpClient.create().doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch.countDown())).metrics(true, Function.identity()).get().uri("http://localhost:" + disposableServer.port()).responseContent().aggregate().asString().block(Duration.ofSeconds(30));
assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(getTimerValue("localhost:" + disposableServer.port())).isGreaterThan(0);
}
use of io.micrometer.api.instrument.Metrics in project reactor-netty by reactor.
the class ByteBufAllocatorMetricsTest method test.
@Test
void test() throws Exception {
disposableServer = createServer().handle((req, res) -> res.header("Connection", "close").sendString(Mono.just("test"))).bindNow();
CountDownLatch latch = new CountDownLatch(1);
PooledByteBufAllocator alloc = new PooledByteBufAllocator(true);
createClient(disposableServer.port()).option(ChannelOption.ALLOCATOR, alloc).doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch.countDown())).metrics(true, Function.identity()).get().uri("/").responseContent().aggregate().asString().block(Duration.ofSeconds(30));
assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
String id = alloc.metric().hashCode() + "";
String[] tags = new String[] { ID, id, TYPE, "pooled" };
checkExpectations(BYTE_BUF_ALLOCATOR_PREFIX, tags);
// Verify ACTIVE_HEAP_MEMORY and ACTIVE_DIRECT_MEMORY meters
List<ByteBuf> buffers = new ArrayList<>();
boolean releaseBufList = true;
try {
double currentActiveHeap = getGaugeValue(BYTE_BUF_ALLOCATOR_PREFIX + ACTIVE_HEAP_MEMORY, tags);
double currentActiveDirect = getGaugeValue(BYTE_BUF_ALLOCATOR_PREFIX + ACTIVE_DIRECT_MEMORY, tags);
IntStream.range(0, 10).mapToObj(i -> alloc.heapBuffer(102400)).forEach(buffers::add);
IntStream.range(0, 10).mapToObj(i -> alloc.directBuffer(102400)).forEach(buffers::add);
assertThat(getGaugeValue(BYTE_BUF_ALLOCATOR_PREFIX + ACTIVE_HEAP_MEMORY, tags)).isGreaterThan(currentActiveHeap);
assertThat(getGaugeValue(BYTE_BUF_ALLOCATOR_PREFIX + ACTIVE_DIRECT_MEMORY, tags)).isGreaterThan(currentActiveDirect);
currentActiveHeap = getGaugeValue(BYTE_BUF_ALLOCATOR_PREFIX + ACTIVE_HEAP_MEMORY, tags);
currentActiveDirect = getGaugeValue(BYTE_BUF_ALLOCATOR_PREFIX + ACTIVE_DIRECT_MEMORY, tags);
buffers.forEach(ByteBuf::release);
releaseBufList = false;
assertThat(getGaugeValue(BYTE_BUF_ALLOCATOR_PREFIX + ACTIVE_HEAP_MEMORY, tags)).isLessThan(currentActiveHeap);
assertThat(getGaugeValue(BYTE_BUF_ALLOCATOR_PREFIX + ACTIVE_DIRECT_MEMORY, tags)).isLessThan(currentActiveDirect);
} finally {
if (releaseBufList) {
buffers.forEach(ByteBuf::release);
}
}
}
Aggregations