[fix][test] Fix pulsar-proxy test flakiness related to metrics
@@ -104,6 +104,7 @@ public class ProxyServiceStarter {
private ProxyService proxyService;
private WebServer server;
+ private static boolean metricsInitialized;
public ProxyServiceStarter(String[] args) throws Exception {
try {
@@ -208,6 +209,7 @@ public class ProxyServiceStarter {
proxyService.start();
+ if (!metricsInitialized) {
// Setup metrics
DefaultExports.initialize();
@@ -226,6 +228,9 @@ public class ProxyServiceStarter {
}
}).register(CollectorRegistry.defaultRegistry);
+ metricsInitialized = true;
+ }
+
addWebServerHandlers(server, config, proxyService, proxyService.getDiscoveryProvider());
// start web-service
@@ -240,7 +245,6 @@ public class ProxyServiceStarter {
if (server != null) {
server.stop();
}
- CollectorRegistry.defaultRegistry.clear();
} catch (Exception e) {
log.warn("server couldn't stop gracefully {}", e.getMessage(), e);
} finally {
