This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d7f5e5fe11 [fix][test] Fix pulsar-proxy test flakiness related to 
metrics (#19257)
1d7f5e5fe11 is described below

commit 1d7f5e5fe1116b87be6554f18091207b788ae1c5
Author: Lari Hotari <[email protected]>
AuthorDate: Tue Jan 17 15:41:56 2023 +0200

    [fix][test] Fix pulsar-proxy test flakiness related to metrics (#19257)
---
 .../pulsar/proxy/server/ProxyServiceStarter.java   | 36 ++++++++++++----------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
index 8e7e3abf9c7..beee9f1a4f7 100644
--- 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
+++ 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
@@ -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,23 +209,27 @@ public class ProxyServiceStarter {
 
         proxyService.start();
 
-        // Setup metrics
-        DefaultExports.initialize();
+        if (!metricsInitialized) {
+            // Setup metrics
+            DefaultExports.initialize();
 
-        // Report direct memory from Netty counters
-        Gauge.build("jvm_memory_direct_bytes_used", "-").create().setChild(new 
Child() {
-            @Override
-            public double get() {
-                return getJvmDirectMemoryUsed();
-            }
-        }).register(CollectorRegistry.defaultRegistry);
+            // Report direct memory from Netty counters
+            Gauge.build("jvm_memory_direct_bytes_used", 
"-").create().setChild(new Child() {
+                @Override
+                public double get() {
+                    return getJvmDirectMemoryUsed();
+                }
+            }).register(CollectorRegistry.defaultRegistry);
 
-        Gauge.build("jvm_memory_direct_bytes_max", "-").create().setChild(new 
Child() {
-            @Override
-            public double get() {
-                return DirectMemoryUtils.jvmMaxDirectMemory();
-            }
-        }).register(CollectorRegistry.defaultRegistry);
+            Gauge.build("jvm_memory_direct_bytes_max", 
"-").create().setChild(new Child() {
+                @Override
+                public double get() {
+                    return DirectMemoryUtils.jvmMaxDirectMemory();
+                }
+            }).register(CollectorRegistry.defaultRegistry);
+
+            metricsInitialized = true;
+        }
 
         addWebServerHandlers(server, config, proxyService, 
proxyService.getDiscoveryProvider());
 
@@ -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 {

Reply via email to