You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "gaoran10 (via GitHub)" <gi...@apache.org> on 2023/02/07 03:55:50 UTC

[GitHub] [pulsar] gaoran10 commented on a diff in pull request #19440: [improve][broker] Implemented ExtensibleLoadManagerWrapper.getLoadBalancingMetrics()

gaoran10 commented on code in PR #19440:
URL: https://github.com/apache/pulsar/pull/19440#discussion_r1098119602


##########
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:
   Does this field need the final modifier?



##########
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:
   Maybe we can use the exact type here, it's a little hard to know the type at first eye.



##########
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:
   Normally, every metric will have a label to indicate the broker IP, do we need to add the label `broker`?



##########
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:
   Maybe all split reasons can succeed, skip, or fail?



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org