You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/07/07 12:18:42 UTC

[activemq-artemis] 04/07: ARTEMIS-2828 add addressSize metric

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

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit cb7cd729d7ef4a0bebca8d443300ac38d7a9f873
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Fri Jun 26 14:40:59 2020 -0500

    ARTEMIS-2828 add addressSize metric
    
    Adding this metric required moving the meter registration code from the
    AddressInfo class to the ManagementService in order to get clean access
    to both the AddressInfo and AddressControl classes.
---
 .../api/core/management/AddressControl.java        |  7 +++---
 .../core/management/impl/AddressControlImpl.java   |  5 ++++-
 .../core/postoffice/impl/SimpleAddressManager.java | 14 ++----------
 .../postoffice/impl/WildcardAddressManager.java    |  1 -
 .../artemis/core/server/impl/AddressInfo.java      | 19 ----------------
 .../core/server/management/ManagementService.java  |  3 +++
 .../management/impl/ManagementServiceImpl.java     | 25 ++++++++++++++++++++++
 .../core/server/metrics/AddressMetricNames.java    |  1 +
 .../server/group/impl/ClusteredResetMockTest.java  |  6 ++++++
 .../management/AddressControlUsingCoreTest.java    |  2 +-
 .../integration/plugin/MetricsPluginTest.java      |  7 +++---
 11 files changed, 50 insertions(+), 40 deletions(-)

diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java
index 23817ed..719a877 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java
@@ -25,6 +25,7 @@ import java.util.Map;
 public interface AddressControl {
    String ROUTED_MESSAGE_COUNT_DESCRIPTION = "number of messages routed to one or more bindings";
    String UNROUTED_MESSAGE_COUNT_DESCRIPTION = "number of messages not routed to any bindings";
+   String ADDRESS_SIZE_DESCRIPTION = "the number of estimated bytes being used by all the queue(s) bound to this address; used to control paging and blocking";
 
    /**
     * Returns the managed address.
@@ -60,10 +61,10 @@ public interface AddressControl {
    String getRolesAsJSON() throws Exception;
 
    /**
-    * Returns the number of estimated bytes being used by the queue(s), used to control paging and blocking.
+    * Returns the number of estimated bytes being used by all the queue(s) bound to this address; used to control paging and blocking.
     */
-   @Attribute(desc = "the number of estimated bytes being used by the queue(s), used to control paging and blocking")
-   long getAddressSize() throws Exception;
+   @Attribute(desc = ADDRESS_SIZE_DESCRIPTION)
+   long getAddressSize();
 
    /**
     * Returns the sum of messages on queue(s), including messages in delivery.
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
index 7760849..9da31ab 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
@@ -263,7 +263,7 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
    }
 
    @Override
-   public long getAddressSize() throws Exception {
+   public long getAddressSize() {
       if (AuditLogger.isEnabled()) {
          AuditLogger.getAddressSize(this.addressInfo);
       }
@@ -274,6 +274,9 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
             return 0;
          }
          return pagingStore.getAddressSize();
+      } catch (Exception e) {
+         ActiveMQServerLogger.LOGGER.debug("Failed to get address size", e);
+         return -1;
       } finally {
          blockOnIO();
       }
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java
index 2510a91..35d3e69 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java
@@ -259,11 +259,7 @@ public class SimpleAddressManager implements AddressManager {
 
    @Override
    public boolean reloadAddressInfo(AddressInfo addressInfo) {
-      boolean added = addressInfoMap.putIfAbsent(addressInfo.getName(), addressInfo) == null;
-      if (added) {
-         addressInfo.registerMeters(metricsManager);
-      }
-      return added;
+      return addressInfoMap.putIfAbsent(addressInfo.getName(), addressInfo) == null;
    }
 
    @Override
@@ -355,13 +351,7 @@ public class SimpleAddressManager implements AddressManager {
 
    @Override
    public AddressInfo removeAddressInfo(SimpleString address) throws Exception {
-      final AddressInfo removed = addressInfoMap.remove(CompositeAddress.extractAddressName(address));
-
-      if (removed != null) {
-         removed.unregisterMeters(metricsManager);
-      }
-
-      return removed;
+      return addressInfoMap.remove(CompositeAddress.extractAddressName(address));
    }
 
    @Override
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/WildcardAddressManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/WildcardAddressManager.java
index c688472..6dc1737 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/WildcardAddressManager.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/WildcardAddressManager.java
@@ -160,7 +160,6 @@ public class WildcardAddressManager extends SimpleAddressManager {
          //Remove from mappings so removeAndUpdateAddressMap processes and cleanup
          mappings.remove(address);
          removeAndUpdateAddressMap(new AddressImpl(removed.getName(), wildcardConfiguration));
-         removed.unregisterMeters(metricsManager);
       }
       return removed;
    }
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
index b3ec9cb..8f1a364 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
@@ -22,8 +22,6 @@ import java.util.concurrent.atomic.AtomicLongFieldUpdater;
 
 import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.management.AddressControl;
-import org.apache.activemq.artemis.api.core.management.ResourceNames;
 import org.apache.activemq.artemis.core.persistence.AddressQueueStatus;
 import org.apache.activemq.artemis.core.persistence.StorageManager;
 import org.apache.activemq.artemis.core.postoffice.Binding;
@@ -31,8 +29,6 @@ import org.apache.activemq.artemis.core.postoffice.Bindings;
 import org.apache.activemq.artemis.core.postoffice.PostOffice;
 import org.apache.activemq.artemis.core.postoffice.QueueBinding;
 import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
-import org.apache.activemq.artemis.core.server.metrics.AddressMetricNames;
-import org.apache.activemq.artemis.core.server.metrics.MetricsManager;
 import org.apache.activemq.artemis.core.settings.HierarchicalRepositoryChangeListener;
 import org.apache.activemq.artemis.utils.CompositeAddress;
 import org.apache.activemq.artemis.utils.PrefixUtil;
@@ -340,19 +336,4 @@ public class AddressInfo {
       this.repositoryChangeListener = repositoryChangeListener;
       return this;
    }
-
-   public void registerMeters(MetricsManager metricsManager) {
-      if (metricsManager != null) {
-         metricsManager.registerAddressGauge(name.toString(), builder -> {
-            builder.register(AddressMetricNames.ROUTED_MESSAGE_COUNT, this, metrics -> Double.valueOf(getRoutedMessageCount()), AddressControl.ROUTED_MESSAGE_COUNT_DESCRIPTION);
-            builder.register(AddressMetricNames.UNROUTED_MESSAGE_COUNT, this, metrics -> Double.valueOf(getUnRoutedMessageCount()), AddressControl.UNROUTED_MESSAGE_COUNT_DESCRIPTION);
-         });
-      }
-   }
-
-   public void unregisterMeters(MetricsManager metricsManager) {
-      if (metricsManager != null) {
-         metricsManager.remove(ResourceNames.ADDRESS + name);
-      }
-   }
 }
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementService.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementService.java
index 41eb5c8..716a9fb 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementService.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementService.java
@@ -26,6 +26,7 @@ import org.apache.activemq.artemis.api.core.Message;
 import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
+import org.apache.activemq.artemis.api.core.management.AddressControl;
 import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
 import org.apache.activemq.artemis.core.config.BridgeConfiguration;
 import org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration;
@@ -93,6 +94,8 @@ public interface ManagementService extends NotificationService, ActiveMQComponen
 
    void registerAddress(AddressInfo addressInfo) throws Exception;
 
+   void registerAddressMeters(AddressInfo addressInfo, AddressControl addressControl) throws Exception;
+
    void unregisterAddress(SimpleString address) throws Exception;
 
    void registerQueue(Queue queue, SimpleString address, StorageManager storageManager) throws Exception;
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
index c6b1f67..207a2da 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
@@ -47,6 +47,7 @@ import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
 import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
 import org.apache.activemq.artemis.api.core.management.AcceptorControl;
+import org.apache.activemq.artemis.api.core.management.AddressControl;
 import org.apache.activemq.artemis.api.core.management.BaseBroadcastGroupControl;
 import org.apache.activemq.artemis.api.core.management.BridgeControl;
 import org.apache.activemq.artemis.api.core.management.ClusterConnectionControl;
@@ -93,6 +94,8 @@ import org.apache.activemq.artemis.core.server.impl.CleaningActivateCallback;
 import org.apache.activemq.artemis.core.server.management.ManagementService;
 import org.apache.activemq.artemis.core.server.management.Notification;
 import org.apache.activemq.artemis.core.server.management.NotificationListener;
+import org.apache.activemq.artemis.core.server.metrics.AddressMetricNames;
+import org.apache.activemq.artemis.core.server.metrics.MetricsManager;
 import org.apache.activemq.artemis.core.settings.HierarchicalRepository;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.core.transaction.ResourceManager;
@@ -232,17 +235,32 @@ public class ManagementServiceImpl implements ManagementService {
 
       registerInRegistry(ResourceNames.ADDRESS + addressInfo.getName(), addressControl);
 
+      registerAddressMeters(addressInfo, addressControl);
+
       if (logger.isDebugEnabled()) {
          logger.debug("registered address " + objectName);
       }
    }
 
    @Override
+   public void registerAddressMeters(AddressInfo addressInfo, AddressControl addressControl) {
+      MetricsManager metricsManager = messagingServer.getMetricsManager();
+      if (metricsManager != null) {
+         metricsManager.registerAddressGauge(addressInfo.getName().toString(), builder -> {
+            builder.register(AddressMetricNames.ROUTED_MESSAGE_COUNT, this, metrics -> Double.valueOf(addressInfo.getRoutedMessageCount()), AddressControl.ROUTED_MESSAGE_COUNT_DESCRIPTION);
+            builder.register(AddressMetricNames.UNROUTED_MESSAGE_COUNT, this, metrics -> Double.valueOf(addressInfo.getUnRoutedMessageCount()), AddressControl.UNROUTED_MESSAGE_COUNT_DESCRIPTION);
+            builder.register(AddressMetricNames.ADDRESS_SIZE, this, metrics -> Double.valueOf(addressControl.getAddressSize()), AddressControl.ADDRESS_SIZE_DESCRIPTION);
+         });
+      }
+   }
+
+   @Override
    public synchronized void unregisterAddress(final SimpleString address) throws Exception {
       ObjectName objectName = objectNameBuilder.getAddressObjectName(address);
 
       unregisterFromJMX(objectName);
       unregisterFromRegistry(ResourceNames.ADDRESS + address);
+      unregisterAddressMeters(address.toString());
    }
 
    public synchronized void registerQueue(final Queue queue,
@@ -542,6 +560,13 @@ public class ManagementServiceImpl implements ManagementService {
       }
    }
 
+   public void unregisterAddressMeters(String address) {
+      MetricsManager metricsManager = messagingServer.getMetricsManager();
+      if (metricsManager != null) {
+         metricsManager.remove(ResourceNames.ADDRESS + address);
+      }
+   }
+
    @Override
    public void addNotificationListener(final NotificationListener listener) {
       listeners.add(listener);
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/AddressMetricNames.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/AddressMetricNames.java
index 902c6a0..64522c4 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/AddressMetricNames.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/AddressMetricNames.java
@@ -21,5 +21,6 @@ public class AddressMetricNames {
 
    public static final String ROUTED_MESSAGE_COUNT = "routed.message.count";
    public static final String UNROUTED_MESSAGE_COUNT = "unrouted.message.count";
+   public static final String ADDRESS_SIZE = "address.size";
 
 }
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/group/impl/ClusteredResetMockTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/group/impl/ClusteredResetMockTest.java
index d464c5e..2d2509e 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/group/impl/ClusteredResetMockTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/group/impl/ClusteredResetMockTest.java
@@ -28,6 +28,7 @@ import org.apache.activemq.artemis.api.core.Message;
 import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
+import org.apache.activemq.artemis.api.core.management.AddressControl;
 import org.apache.activemq.artemis.api.core.management.ManagementHelper;
 import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
 import org.apache.activemq.artemis.core.config.BridgeConfiguration;
@@ -252,6 +253,11 @@ public class ClusteredResetMockTest extends ActiveMQTestBase {
       }
 
       @Override
+      public void registerAddressMeters(AddressInfo addressInfo, AddressControl addressControl) throws Exception {
+
+      }
+
+      @Override
       public void unregisterAddress(SimpleString address) throws Exception {
 
       }
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java
index faf41aa..25f3f31 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java
@@ -64,7 +64,7 @@ public class AddressControlUsingCoreTest extends AddressControlTest {
          }
 
          @Override
-         public long getAddressSize() throws Exception {
+         public long getAddressSize() {
             return (long) proxy.retrieveAttributeValue("addressSize");
          }
 
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MetricsPluginTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MetricsPluginTest.java
index 4801dcb..5d30b00 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MetricsPluginTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MetricsPluginTest.java
@@ -40,12 +40,11 @@ import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
 import org.apache.activemq.artemis.api.core.client.ServerLocator;
 import org.apache.activemq.artemis.core.config.MetricsConfiguration;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
-import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
 import org.apache.activemq.artemis.core.server.Queue;
 import org.apache.activemq.artemis.core.server.metrics.plugins.SimpleMetricsPlugin;
 import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
-import org.apache.activemq.artemis.tests.util.Wait;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.tests.util.Wait;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -166,7 +165,9 @@ public class MetricsPluginTest extends ActiveMQTestBase {
               new Metric("artemis.scheduled.persistent.size", "persistent size of scheduled messages in this queue", 0.0),
               new Metric("artemis.total.connection.count", "Number of clients which have connected to this server since it was started", 1.0),
               new Metric("artemis.unrouted.message.count", "number of messages not routed to any bindings", 0.0),
-              new Metric("artemis.unrouted.message.count", "number of messages not routed to any bindings", 2.0)
+              new Metric("artemis.unrouted.message.count", "number of messages not routed to any bindings", 2.0),
+              new Metric("artemis.address.size", "the number of estimated bytes being used by all the queue(s) bound to this address; used to control paging and blocking", 0.0),
+              new Metric("artemis.address.size", "the number of estimated bytes being used by all the queue(s) bound to this address; used to control paging and blocking", 0.0)
       ));
    }