heesung-sn commented on code in PR #19440:
URL: https://github.com/apache/pulsar/pull/19440#discussion_r1098170508


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/ExtensibleLoadManagerImpl.java:
##########
@@ -86,6 +93,17 @@ public class ExtensibleLoadManagerImpl implements 
ExtensibleLoadManager {
 
     private boolean started = false;
 
+    private final AssignCounter assignCounter = new AssignCounter();
+    private final UnloadCounter unloadCounter = new UnloadCounter();
+    private final SplitCounter splitCounter = new SplitCounter();
+
+    // record load metrics
+    private AtomicReference<List<Metrics>> brokerLoadMetrics = new 
AtomicReference<>();

Review Comment:
   Thanks. Updated.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/models/SplitCounter.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.loadbalance.extensions.models;
+
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Label.Failure;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Label.Skip;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Label.Success;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Admin;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Balanced;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Bandwidth;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.MsgRate;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Sessions;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Topics;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Unknown;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.mutable.MutableLong;
+import org.apache.pulsar.common.stats.Metrics;
+
+/**
+ * Defines the information required for a service unit split(e.g. bundle 
split).
+ */
+public class SplitCounter {
+
+    long splitCount = 0;
+
+    final Map<SplitDecision.Label, Map<SplitDecision.Reason, MutableLong>> 
breakdownCounters;
+
+    public SplitCounter() {
+        breakdownCounters = Map.of(
+                Success, Map.of(
+                        Topics, new MutableLong(),

Review Comment:
   No. It is designed to emit reasons for Success, Skip and Failure separately.
   
   For now, we don't want to emit a failure reason metric(expecting the 
operator to check logs anyway if alarmed on failure).



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/data/BrokerLoadData.java:
##########
@@ -187,4 +191,35 @@ public String toString(ServiceConfiguration conf) {
         );
     }
 
+    public List<Metrics> toMetrics(String advertisedBrokerAddress) {
+        var metrics = new ArrayList<Metrics>();
+        var dimensions = new HashMap<String, String>();
+        dimensions.put("metric", "loadBalancing");
+        dimensions.put("broker", advertisedBrokerAddress);

Review Comment:
   This is for the backward compatibility as the existing resource usage 
metrics have the `broker` dimension. Operators can find the broker-id from the 
pod name too. For now, I don't see a particular reason we have to emit 
brokerUrl for all metrics.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/models/SplitCounter.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.loadbalance.extensions.models;
+
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Label.Failure;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Label.Skip;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Label.Success;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Admin;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Balanced;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Bandwidth;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.MsgRate;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Sessions;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Topics;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.models.SplitDecision.Reason.Unknown;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.mutable.MutableLong;
+import org.apache.pulsar.common.stats.Metrics;
+
+/**
+ * Defines the information required for a service unit split(e.g. bundle 
split).
+ */
+public class SplitCounter {
+
+    long splitCount = 0;
+
+    final Map<SplitDecision.Label, Map<SplitDecision.Reason, MutableLong>> 
breakdownCounters;
+
+    public SplitCounter() {
+        breakdownCounters = Map.of(
+                Success, Map.of(
+                        Topics, new MutableLong(),
+                        Sessions, new MutableLong(),
+                        MsgRate, new MutableLong(),
+                        Bandwidth, new MutableLong(),
+                        Admin, new MutableLong()),
+                Skip, Map.of(
+                        Balanced, new MutableLong()
+                        ),
+                Failure, Map.of(
+                        Unknown, new MutableLong())
+        );
+    }
+
+    public void update(SplitDecision decision) {
+        if (decision.label == Success) {
+            splitCount++;
+        }
+        
breakdownCounters.get(decision.getLabel()).get(decision.getReason()).increment();
+    }
+
+    public List<Metrics> toMetrics() {
+        List<Metrics> metrics = new ArrayList<>();
+        Map<String, String> dimensions = new HashMap<>();
+
+        dimensions.put("metric", "bundlesSplit");
+
+        Metrics m = Metrics.create(dimensions);
+        m.put("brk_lb_bundles_split_total", splitCount);
+        metrics.add(m);
+
+        for (var etr : breakdownCounters.entrySet()) {
+            var result = etr.getKey();

Review Comment:
   Updated.



-- 
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