2016-08-20 02:08:53 +00:00
|
|
|
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/MetricsSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/MetricsSystem.java
|
2022-10-07 14:58:51 +00:00
|
|
|
index fef8c4b7e4b..8d2b9339706 100644
|
2016-08-20 02:08:53 +00:00
|
|
|
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/MetricsSystem.java
|
|
|
|
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/MetricsSystem.java
|
2020-10-29 01:49:36 +00:00
|
|
|
@@ -42,18 +42,6 @@
|
|
|
|
@InterfaceAudience.Private
|
2016-08-20 02:08:53 +00:00
|
|
|
public abstract MetricsSystem init(String prefix);
|
|
|
|
|
2020-10-29 01:49:36 +00:00
|
|
|
- /**
|
2016-08-20 02:08:53 +00:00
|
|
|
- * Register a metrics source
|
|
|
|
- * @param <T> the actual type of the source object
|
|
|
|
- * @param source object to register
|
|
|
|
- * @param name of the source. Must be unique or null (then extracted from
|
|
|
|
- * the annotations of the source object.)
|
|
|
|
- * @param desc the description of the source (or null. See above.)
|
|
|
|
- * @return the source object
|
2022-10-07 14:58:51 +00:00
|
|
|
- * @exception MetricsException Metrics Exception.
|
2016-08-20 02:08:53 +00:00
|
|
|
- */
|
|
|
|
- public abstract <T> T register(String name, String desc, T source);
|
|
|
|
-
|
2020-10-29 01:49:36 +00:00
|
|
|
/**
|
2016-08-20 02:08:53 +00:00
|
|
|
* Unregister a metrics source
|
|
|
|
* @param name of the source. This is the name you use to call register()
|
2020-10-29 01:49:36 +00:00
|
|
|
@@ -79,16 +67,16 @@
|
2016-08-20 02:08:53 +00:00
|
|
|
public abstract MetricsSource getSource(String name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
- * Register a metrics sink
|
|
|
|
- * @param <T> the type of the sink
|
|
|
|
- * @param sink to register
|
|
|
|
- * @param name of the sink. Must be unique.
|
|
|
|
- * @param desc the description of the sink
|
|
|
|
- * @return the sink
|
|
|
|
+ * Register a metrics source
|
|
|
|
+ * @param <T> the actual type of the source object
|
|
|
|
+ * @param source object to register
|
|
|
|
+ * @param name of the source. Must be unique or null (then extracted from
|
|
|
|
+ * the annotations of the source object.)
|
|
|
|
+ * @param desc the description of the source (or null. See above.)
|
|
|
|
+ * @return the source object
|
2022-10-07 14:58:51 +00:00
|
|
|
* @exception MetricsException Metrics Exception.
|
2016-08-20 02:08:53 +00:00
|
|
|
*/
|
|
|
|
- public abstract <T extends MetricsSink>
|
|
|
|
- T register(String name, String desc, T sink);
|
|
|
|
+ public abstract <T> T register(String name, String desc, T source);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a callback interface for JMX events
|
|
|
|
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java
|
2020-10-29 01:49:36 +00:00
|
|
|
index a6edf08e5a7..5b87be1ec67 100644
|
2016-08-20 02:08:53 +00:00
|
|
|
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java
|
|
|
|
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java
|
2020-10-29 01:49:36 +00:00
|
|
|
@@ -269,31 +269,6 @@ void registerSource(String name, String desc, MetricsSource source) {
|
2016-08-20 02:08:53 +00:00
|
|
|
LOG.debug("Registered source "+ name);
|
|
|
|
}
|
|
|
|
|
|
|
|
- @Override public synchronized <T extends MetricsSink>
|
|
|
|
- T register(final String name, final String description, final T sink) {
|
|
|
|
- LOG.debug(name +", "+ description);
|
|
|
|
- if (allSinks.containsKey(name)) {
|
2020-10-29 01:49:36 +00:00
|
|
|
- if(sinks.get(name) == null) {
|
|
|
|
- registerSink(name, description, sink);
|
|
|
|
- } else {
|
|
|
|
- LOG.warn("Sink "+ name +" already exists!");
|
|
|
|
- }
|
2016-08-20 02:08:53 +00:00
|
|
|
- return sink;
|
|
|
|
- }
|
|
|
|
- allSinks.put(name, sink);
|
|
|
|
- if (config != null) {
|
|
|
|
- registerSink(name, description, sink);
|
|
|
|
- }
|
|
|
|
- // We want to re-register the sink to pick up new config
|
|
|
|
- // when the metrics system restarts.
|
|
|
|
- register(name, new AbstractCallback() {
|
|
|
|
- @Override public void postStart() {
|
|
|
|
- register(name, description, sink);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- return sink;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
synchronized void registerSink(String name, String desc, MetricsSink sink) {
|
|
|
|
checkNotNull(config, "config");
|
|
|
|
MetricsConfig conf = sinkConfigs.get(name);
|
|
|
|
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java
|
2020-10-29 01:49:36 +00:00
|
|
|
index 7bc772f062a..f012c877d18 100644
|
2016-08-20 02:08:53 +00:00
|
|
|
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java
|
|
|
|
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java
|
2020-10-29 01:49:36 +00:00
|
|
|
@@ -139,8 +139,8 @@ public void testTagsForPrefix() throws Exception {
|
2016-08-20 02:08:53 +00:00
|
|
|
GangliaMetricsTestHelper.setDatagramSocket(gsink31, mockds31);
|
|
|
|
|
|
|
|
// register the sinks
|
|
|
|
- ms.register("gsink30", "gsink30 desc", gsink30);
|
|
|
|
- ms.register("gsink31", "gsink31 desc", gsink31);
|
|
|
|
+ //ms.register("gsink30", "gsink30 desc", gsink30);
|
|
|
|
+ //ms.register("gsink31", "gsink31 desc", gsink31);
|
|
|
|
ms.publishMetricsNow(); // publish the metrics
|
|
|
|
|
|
|
|
ms.stop();
|