Skip to content

Commit

Permalink
Merge #3521 into 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Nov 27, 2024
2 parents ed97e56 + efdc0cd commit 2c6c082
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public final Mono<? extends Connection> acquire(
boolean metricsEnabled = poolFactory.metricsEnabled || config.metricsRecorder() != null;
String id = metricsEnabled ? poolKey.hashCode() + "" : null;

InstrumentedPool<T> newPool = metricsEnabled && Metrics.isMicrometerAvailable() ?
InstrumentedPool<T> newPool = metricsEnabled && poolFactory.registrar == null && Metrics.isMicrometerAvailable() ?
createPool(id, config, poolFactory, remoteAddress, resolverGroup) :
createPool(config, poolFactory, remoteAddress, resolverGroup);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -30,10 +32,12 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.netty.BaseHttpTest;
import reactor.netty.channel.ChannelMetricsRecorder;
import reactor.netty.http.Http2SslContextSpec;
import reactor.netty.http.HttpProtocol;
import reactor.netty.http.client.HttpClient;
import reactor.netty.http.server.HttpServer;
import reactor.test.StepVerifier;

import java.security.cert.CertificateException;
import java.time.Duration;
Expand All @@ -46,6 +50,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.mock;
import static reactor.netty.Metrics.ACTIVE_CONNECTIONS;
import static reactor.netty.Metrics.ACTIVE_STREAMS;
import static reactor.netty.Metrics.ERROR;
Expand All @@ -56,6 +61,7 @@
import static reactor.netty.Metrics.MAX_PENDING_CONNECTIONS;
import static reactor.netty.Metrics.NAME;
import static reactor.netty.Metrics.PENDING_STREAMS;
import static reactor.netty.Metrics.REGISTRY;
import static reactor.netty.Metrics.STATUS;
import static reactor.netty.Metrics.TOTAL_CONNECTIONS;
import static reactor.netty.http.client.HttpClientState.STREAM_CONFIGURED;
Expand Down Expand Up @@ -379,6 +385,52 @@ private void testIssue3060(ConnectionProvider provider) throws Exception {
}
}

/* https://github.com/reactor/reactor-netty/issues/3519 */
@Test
public void testConnectionProviderDisableAllBuiltInMetrics() throws Exception {
disposableServer =
createServer()
.handle((req, res) -> res.sendString(Mono.just("testConnectionProviderDisableAllBuiltInMetrics")))
.bindNow();

ConnectionProvider provider =
ConnectionProvider.builder("testConnectionProviderDisableAllBuiltInMetrics")
.metrics(true, () -> mock(ConnectionProvider.MeterRegistrar.class))
.build();

try {
CountDownLatch latch = new CountDownLatch(1);
createClient(provider, disposableServer.port())
.metrics(true, () -> mock(ChannelMetricsRecorder.class))
.headers(h -> h.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE))
.doOnRequest((req, conn) -> conn.channel().closeFuture().addListener(f -> latch.countDown()))
.get()
.uri("/")
.responseContent()
.aggregate()
.asString()
.as(StepVerifier::create)
.expectNext("testConnectionProviderDisableAllBuiltInMetrics")
.expectComplete()
.verify(Duration.ofSeconds(5));

assertThat(latch.await(5, TimeUnit.SECONDS)).as("latch await").isTrue();

AtomicInteger count = new AtomicInteger();
REGISTRY.forEachMeter(meter -> {
if (meter.getId().getName().startsWith("reactor.netty.connection")) {
count.incrementAndGet();
}
});

assertThat(count).hasValue(0);
}
finally {
provider.disposeLater()
.block(Duration.ofSeconds(5));
}
}

private double getGaugeValue(String gaugeName, String poolName) {
Gauge gauge = registry.find(gaugeName).tag(NAME, poolName).gauge();
double result = -1;
Expand Down

0 comments on commit 2c6c082

Please sign in to comment.