This is an automated email from the ASF dual-hosted git repository.
andor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/master by this push:
new d8e521772 ZOOKEEPER-4972: Fix flaky tests in
PrometheusMetricsProviderConfigTest
d8e521772 is described below
commit d8e5217729bfc7303b15bc36b1a6b7f1ecdd07d4
Author: Kezhu Wang <[email protected]>
AuthorDate: Sat Sep 20 06:43:14 2025 +0800
ZOOKEEPER-4972: Fix flaky tests in PrometheusMetricsProviderConfigTest
Reviewers: anmolnar
Author: kezhuw
Closes #2311 from
kezhuw/ZOOKEEPER-4972-fix-flaky-PrometheusMetricsProviderConfigTest-tests
---
.../zookeeper-prometheus-metrics/pom.xml | 6 ++++
.../prometheus/PrometheusMetricsProvider.java | 35 ++++++++++++++--------
.../PrometheusMetricsProviderConfigTest.java | 8 ++---
3 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/pom.xml
b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/pom.xml
index 2d8e48656..4b13fa6ad 100644
--- a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/pom.xml
+++ b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/pom.xml
@@ -69,6 +69,12 @@
<artifactId>jetty-servlet</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>runtime</scope>
+ <optional>true</optional>
+ </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
diff --git
a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/main/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProvider.java
b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/main/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProvider.java
index 3745a753c..76739787c 100644
---
a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/main/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProvider.java
+++
b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/main/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProvider.java
@@ -23,7 +23,6 @@
import io.prometheus.client.exporter.MetricsServlet;
import io.prometheus.client.hotspot.DefaultExports;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.util.Enumeration;
import java.util.Objects;
import java.util.Optional;
@@ -170,28 +169,32 @@ public void configure(Properties configuration) throws
MetricsProviderLifeCycleE
public void start() throws MetricsProviderLifeCycleException {
this.executorOptional = createExecutor();
try {
- LOG.info("Starting /metrics {} endpoint at HTTP port: {}, HTTPS
port: {}, exportJvmInfo: {}",
- httpPort > 0 ? httpPort : "disabled",
- httpsPort > 0 ? httpsPort : "disabled",
+ LOG.info("Starting /metrics endpoint at HTTP port: {}, HTTPS port:
{}, exportJvmInfo: {}",
+ httpPort >= 0 ? httpPort : "disabled",
+ httpsPort >= 0 ? httpsPort : "disabled",
exportJvmInfo);
if (exportJvmInfo) {
DefaultExports.initialize();
}
- if (httpPort == -1) {
- server = new Server();
- } else {
- server = new Server(new InetSocketAddress(host, httpPort));
+ server = new Server();
+ ServerConnector httpConnector = null;
+ ServerConnector httpsConnector = null;
+ if (httpPort >= 0) {
+ httpConnector = new ServerConnector(server);
+ httpConnector.setHost(host);
+ httpConnector.setPort(httpPort);
+ server.addConnector(httpConnector);
}
- if (httpsPort != -1) {
+ if (httpsPort >= 0) {
SslContextFactory sslServerContextFactory = new
SslContextFactory.Server();
configureSslContextFactory(sslServerContextFactory);
KeyStoreScanner keystoreScanner = new
KeyStoreScanner(sslServerContextFactory);
keystoreScanner.setScanInterval(SCAN_INTERVAL);
server.addBean(keystoreScanner);
- ServerConnector connector = new ServerConnector(server,
sslServerContextFactory);
- connector.setPort(httpsPort);
- connector.setHost(host);
- server.addConnector(connector);
+ httpsConnector = new ServerConnector(server,
sslServerContextFactory);
+ httpsConnector.setHost(host);
+ httpsConnector.setPort(httpsPort);
+ server.addConnector(httpsConnector);
}
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
@@ -199,6 +202,12 @@ public void start() throws
MetricsProviderLifeCycleException {
server.setHandler(context);
context.addServlet(new ServletHolder(servlet), "/metrics");
server.start();
+ if (httpPort == 0) {
+ LOG.info("Bound /metrics endpoint to HTTP port: {}",
httpConnector.getLocalPort());
+ }
+ if (httpsPort == 0) {
+ LOG.info("Bound /metrics endpoint to HTTPS port: {}",
httpsConnector.getLocalPort());
+ }
} catch (Exception err) {
LOG.error("Cannot start /metrics server", err);
if (server != null) {
diff --git
a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderConfigTest.java
b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderConfigTest.java
index 6ff0da5e2..aa9cd2c71 100644
---
a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderConfigTest.java
+++
b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderConfigTest.java
@@ -64,7 +64,7 @@ public void testValidSslConfig() throws
MetricsProviderLifeCycleException {
Properties configuration = new Properties();
String testDataPath = System.getProperty("test.data.dir",
"src/test/resources/data");
configuration.setProperty("httpHost", "127.0.0.1");
- configuration.setProperty("httpsPort", "50511");
+ configuration.setProperty("httpsPort", "0");
configuration.setProperty("ssl.keyStore.location", testDataPath +
"/ssl/server_keystore.jks");
configuration.setProperty("ssl.keyStore.password", "testpass");
configuration.setProperty("ssl.trustStore.location", testDataPath +
"/ssl/server_truststore.jks");
@@ -78,8 +78,8 @@ public void testValidHttpsAndHttpConfig() throws
MetricsProviderLifeCycleExcepti
PrometheusMetricsProvider provider = new PrometheusMetricsProvider();
Properties configuration = new Properties();
String testDataPath = System.getProperty("test.data.dir",
"src/test/resources/data");
- configuration.setProperty("httpPort", "50512");
- configuration.setProperty("httpsPort", "50513");
+ configuration.setProperty("httpPort", "0");
+ configuration.setProperty("httpsPort", "0");
configuration.setProperty("ssl.keyStore.location", testDataPath +
"/ssl/server_keystore.jks");
configuration.setProperty("ssl.keyStore.password", "testpass");
configuration.setProperty("ssl.trustStore.location", testDataPath +
"/ssl/server_truststore.jks");
@@ -95,7 +95,7 @@ public void testInvalidSslConfig() throws
MetricsProviderLifeCycleException {
PrometheusMetricsProvider provider = new
PrometheusMetricsProvider();
Properties configuration = new Properties();
String testDataPath = System.getProperty("test.data.dir",
"src/test/resources/data");
- configuration.setProperty("httpsPort", "50514");
+ configuration.setProperty("httpsPort", "0");
//keystore missing
configuration.setProperty("ssl.keyStore.password", "testpass");
configuration.setProperty("ssl.trustStore.location", testDataPath
+ "/ssl/server_truststore.jks");