asafm commented on code in PR #18116:
URL: https://github.com/apache/pulsar/pull/18116#discussion_r1002683262


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/NamespaceStatsAggregator.java:
##########
@@ -70,7 +71,19 @@ public static void generate(PulsarService pulsar, boolean 
includeTopicMetrics, b
         LongAdder topicsCount = new LongAdder();
         Map<String, Long> localNamespaceTopicCount = new HashMap<>();
 
-        printDefaultBrokerStats(stream, cluster);
+        LongAdder brokerTopicsCount = new LongAdder();

Review Comment:
   I suggest following the same convention as aggregating topic level stats to 
namespace level stats to reduce clutter: Create `AggregatedBrokerStats` and 
follow same design as `AggregatedNamespaceStats`
   
   Before
   ```java
   if (includeTopicMetrics) {
                       topicsCount.add(1);
                       TopicStats.printTopicStats(stream, topicStats, 
compactorMXBean, cluster, namespace, name,
                               splitTopicAndPartitionIndexLabel);
                   } else {
                       namespaceStats.updateStats(topicStats);
                   }
   ```
   add `brokerLevelStats.updateStats(topicStats)`
   
   and before
   ```java
    if (includeTopicMetrics) {
               printTopicsCountStats(stream, localNamespaceTopicCount, cluster);
           }
   ```
   add `printBrokerLevelMetrics(brokerLevelStats)`
   
   This way you don't need LongAdder or DoubleAdder since you won't have any 
thread race condition.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to