From f44aefdeb5fe48e68c04997f10db2f0a725d921a Mon Sep 17 00:00:00 2001 From: Philip Liew Date: Thu, 20 Jun 2019 18:36:03 -0700 Subject: [PATCH] Kill unused classes GaugeExporter, CounterMetricJMXExporter, GaugeMXBean, MutableGauge (#491) --- .../dva/argus/entity/GaugeMXBean.java | 59 --------- .../dva/argus/entity/MutableGauge.java | 77 ------------ .../monitor/CounterMetricJMXExporter.java | 113 ------------------ .../monitor/DefaultMonitorService.java | 4 +- .../argus/service/monitor/GaugeExporter.java | 52 -------- .../dva/argus/system/SystemInitializer.java | 3 - 6 files changed, 1 insertion(+), 307 deletions(-) delete mode 100644 ArgusCore/src/main/java/com/salesforce/dva/argus/entity/GaugeMXBean.java delete mode 100644 ArgusCore/src/main/java/com/salesforce/dva/argus/entity/MutableGauge.java delete mode 100644 ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/CounterMetricJMXExporter.java delete mode 100644 ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/GaugeExporter.java diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/GaugeMXBean.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/GaugeMXBean.java deleted file mode 100644 index 2d366e797..000000000 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/GaugeMXBean.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018, Salesforce.com, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of Salesforce.com nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -package com.salesforce.dva.argus.entity; - -/** - * This is a standard MXBean interface. It will be used to build MXBean - * to export internal metrix to JMX. - * - * This one provides read-only interface as I want to prevent any one - * to change the metric through JMX interface - * - * @author taozhang - * - */ -public interface GaugeMXBean { - - /** - * This is expected to return the object name of the bean. It will - * be used as a key to the JMX-exported internal metric - * @return - */ - String getObjectName(); - - /** - * This should return gauge value of the internal metrics - * @return - */ - Double getValue(); - -} diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/MutableGauge.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/MutableGauge.java deleted file mode 100644 index b0e6ae4b5..000000000 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/MutableGauge.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2018, Salesforce.com, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of Salesforce.com nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -package com.salesforce.dva.argus.entity; - -/** - * This the implementation the JMX-exported internal metric object, a standard - * MXBean. It is called MutableGauge because it need to read internal data - * and set its value. The JMX-facing interface is read-only to prevent others - * manipulate the value after the fact - * - * @author taozhang - * - */ -public class MutableGauge implements GaugeMXBean { - - /* - * object name of the gauge, also the key to the object - */ - private String _objName; - - /** - * value of the gauge - */ - private Double _val; - - public MutableGauge(String objName) { - _objName = objName; - _val = 0.0; - } - - @Override - public String getObjectName() { - return _objName; - } - - @Override - public Double getValue() { - return _val; - } - - /** - * set value to gauge - * @param val the value for the gauge - */ - public void setValue(Double val) { - _val = val; - } -} diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/CounterMetricJMXExporter.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/CounterMetricJMXExporter.java deleted file mode 100644 index 8609d62bf..000000000 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/CounterMetricJMXExporter.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2018, Salesforce.com, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of Salesforce.com nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package com.salesforce.dva.argus.service.monitor; - -import java.lang.management.ManagementFactory; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import javax.management.InstanceAlreadyExistsException; -import javax.management.MBeanRegistrationException; -import javax.management.MBeanServer; -import javax.management.MalformedObjectNameException; -import javax.management.NotCompliantMBeanException; -import javax.management.ObjectName; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.salesforce.dva.argus.entity.Metric; -import com.salesforce.dva.argus.entity.MutableGauge; - -/** - * This is the implementation for @GaugeExporter to export metrics to JMX. It - * transform incoming metric object into @MutableGauge object, register it with - * JMX if it is new, and set its value. The MBeanServer will take care of - * making it available through JMX port. - * - * @author taozhang - * - */ -@Singleton -public class CounterMetricJMXExporter implements GaugeExporter { - - private final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); - private final Logger _logger = LoggerFactory.getLogger(CounterMetricJMXExporter.class); - - private final Map _exportedMetrics = new ConcurrentHashMap(); - - private String _createObjectNameForMetric(Metric metric) { - String objName = "ArgusMetrics:type=Counter,scope=" + metric.getScope() + ",metric=" + metric.getMetric(); - if (null != metric.getTags()) { - for (String key : metric.getTags().keySet()) { - objName = objName + "," + (key.equalsIgnoreCase("type") || key.equalsIgnoreCase("scope") - || key.equalsIgnoreCase("metric") ? "_" + key : key) + "=" + metric.getTags().get(key); - } - } - return objName; - } - - @Inject - public CounterMetricJMXExporter() { - _logger.info("CounterMetricJMXExporter created. {}", this.hashCode()); - } - - @Override - public void exportGauge(Metric metric, Double value) { - String objectName = this._createObjectNameForMetric(metric); - - synchronized (_exportedMetrics) { - _logger.debug("exportGauge(): +++ set {} to {}", objectName, value); - if (!_exportedMetrics.containsKey(objectName)) { - MutableGauge gauge = new MutableGauge(objectName); - gauge.setValue(value); - _exportedMetrics.put(objectName, gauge); - try { - _logger.debug("exportGauge(): !!!!!! come to register {} to JMX", objectName); - mbeanServer.registerMBean(gauge, new ObjectName(objectName)); - } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException - | MalformedObjectNameException e) { - if (e.getClass() == InstanceAlreadyExistsException.class) { - _logger.debug("exportGauge()({}): failed to register internal counter {} to JMX {}", this.hashCode(), objectName, e); - } else { - _logger.error("exportGauge()({}): failed to register internal counter {} to JMX {}", this.hashCode(), objectName, e); - - } - } - } else { - _exportedMetrics.get(objectName).setValue(value); - } - } - } - -} diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/DefaultMonitorService.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/DefaultMonitorService.java index 4461638b9..e8f7e31c0 100644 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/DefaultMonitorService.java +++ b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/DefaultMonitorService.java @@ -117,7 +117,6 @@ public class DefaultMonitorService extends DefaultJPAService implements MonitorS private final DashboardService _dashboardService; private final MetricService _metricService; private final MailService _mailService; - private final GaugeExporter _gaugeExporter; private final Map _metrics; private final Map _registeredMetrics; private final PrincipalUser _adminUser; @@ -144,7 +143,7 @@ public class DefaultMonitorService extends DefaultJPAService implements MonitorS @Inject public DefaultMonitorService(TSDBService tsdbService, UserService userService, AlertService alertService, ServiceManagementService serviceManagementService, DashboardService dashboardService, MetricService metricService, MailService mailService, - GaugeExporter gaugeExporter, SystemConfiguration sysConfig) { + SystemConfiguration sysConfig) { super(null, sysConfig); requireArgument(tsdbService != null, "TSDB service cannot be null."); requireArgument(userService != null, "User service cannot be null."); @@ -160,7 +159,6 @@ public DefaultMonitorService(TSDBService tsdbService, UserService userService, A _metricService = metricService; _mailService = mailService; _adminUser = _userService.findAdminUser(); - _gaugeExporter = gaugeExporter; _mbeanServer = ManagementFactory.getPlatformMBeanServer(); _metrics = new ConcurrentHashMap<>(); _registeredMetrics = new ConcurrentHashMap<>(); diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/GaugeExporter.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/GaugeExporter.java deleted file mode 100644 index 475fa1c78..000000000 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/monitor/GaugeExporter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2018, Salesforce.com, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of Salesforce.com nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package com.salesforce.dva.argus.service.monitor; - -import com.salesforce.dva.argus.entity.Metric; - -/** - * This interface allow program to export internal counter metrics to - * external metric collecting / reporting system - * - * @author taozhang - * - */ -public interface GaugeExporter { - /** - * export internal metric and its latest value through GaugeExporter. System - * need the metric counter object to create corresponding object name - * for the exporter - * @param metric The internal metric that will be exported - * @param value The latest value of the metric. - */ - void exportGauge(Metric metric, Double value); - -} diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/system/SystemInitializer.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/system/SystemInitializer.java index 21cfcee54..0f3be7f4c 100644 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/system/SystemInitializer.java +++ b/ArgusCore/src/main/java/com/salesforce/dva/argus/system/SystemInitializer.java @@ -54,9 +54,7 @@ import com.salesforce.dva.argus.service.jpa.DefaultServiceManagementService; import com.salesforce.dva.argus.service.management.DefaultManagementService; import com.salesforce.dva.argus.service.metric.AsyncMetricService; -import com.salesforce.dva.argus.service.monitor.CounterMetricJMXExporter; import com.salesforce.dva.argus.service.monitor.DefaultMonitorService; -import com.salesforce.dva.argus.service.monitor.GaugeExporter; import com.salesforce.dva.argus.service.oauth.DefaultOAuthAuthorizationCodeService; import com.salesforce.dva.argus.service.schema.DefaultDiscoveryService; import com.salesforce.dva.argus.service.tsdb.CachedTSDBService; @@ -229,7 +227,6 @@ private void configureLogging() { } private void configureServices() { - bindConcreteClass(CounterMetricJMXExporter.class, GaugeExporter.class); bindConcreteClass(Property.CACHE_SERVICE_IMPL_CLASS, CacheService.class); bindConcreteClass(Property.MQ_SERVICE_IMPL_CLASS, MQService.class); bindConcreteClass(Property.ALERT_SERVICE_IMPL_CLASS, AlertService.class);