From 9179638017439ce08c4de8414361304628eb64f4 Mon Sep 17 00:00:00 2001 From: Viraj Jasani Date: Thu, 15 Apr 2021 14:34:46 +0530 Subject: [PATCH] HADOOP-17524. Remove EventCounter and Log counters from JVM Metrics (#2909) Reviewed-by: Duo Zhang Signed-off-by: Akira Ajisaka --- .../org/apache/hadoop/log/EventCounter.java | 34 ------ .../hadoop/log/metrics/EventCounter.java | 100 ------------------ .../hadoop/metrics2/source/JvmMetrics.java | 8 -- .../metrics2/source/TestJvmMetrics.java | 5 - 4 files changed, 147 deletions(-) delete mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/EventCounter.java delete mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/metrics/EventCounter.java diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/EventCounter.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/EventCounter.java deleted file mode 100644 index 3192d06807..0000000000 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/EventCounter.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.hadoop.log; - -/** - * A log4J Appender that simply counts logging events in three levels: - * fatal, error and warn. The class name is used in log4j.properties - * @deprecated use {@link org.apache.hadoop.log.metrics.EventCounter} instead - */ -@Deprecated -public class EventCounter extends org.apache.hadoop.log.metrics.EventCounter { - static { - // The logging system is not started yet. - System.err.println("WARNING: "+ EventCounter.class.getName() + - " is deprecated. Please use "+ - org.apache.hadoop.log.metrics.EventCounter.class.getName() + - " in all the log4j.properties files."); - } -} diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/metrics/EventCounter.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/metrics/EventCounter.java deleted file mode 100644 index 95b9cfc540..0000000000 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/metrics/EventCounter.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * 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.hadoop.log.metrics; - -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.classification.InterfaceStability; - -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.Level; -import org.apache.log4j.spi.LoggingEvent; - -/** - * A log4J Appender that simply counts logging events in three levels: - * fatal, error and warn. The class name is used in log4j.properties - */ -@InterfaceAudience.Public -@InterfaceStability.Stable -public class EventCounter extends AppenderSkeleton { - private static final int FATAL = 0; - private static final int ERROR = 1; - private static final int WARN = 2; - private static final int INFO = 3; - - private static class EventCounts { - private final long[] counts = {0, 0, 0, 0}; - - private synchronized void incr(int i) { - ++counts[i]; - } - - private synchronized long get(int i) { - return counts[i]; - } - } - - private static EventCounts counts = new EventCounts(); - - @InterfaceAudience.Private - public static long getFatal() { - return counts.get(FATAL); - } - - @InterfaceAudience.Private - public static long getError() { - return counts.get(ERROR); - } - - @InterfaceAudience.Private - public static long getWarn() { - return counts.get(WARN); - } - - @InterfaceAudience.Private - public static long getInfo() { - return counts.get(INFO); - } - - @Override - public void append(LoggingEvent event) { - Level level = event.getLevel(); - // depends on the api, == might not work - // see HADOOP-7055 for details - if (level.equals(Level.INFO)) { - counts.incr(INFO); - } - else if (level.equals(Level.WARN)) { - counts.incr(WARN); - } - else if (level.equals(Level.ERROR)) { - counts.incr(ERROR); - } - else if (level.equals(Level.FATAL)) { - counts.incr(FATAL); - } - } - - @Override - public void close() { - } - - @Override - public boolean requiresLayout() { - return false; - } -} diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/source/JvmMetrics.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/source/JvmMetrics.java index 816940b109..9e5a78fd90 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/source/JvmMetrics.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/source/JvmMetrics.java @@ -33,7 +33,6 @@ import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeys; -import org.apache.hadoop.log.metrics.EventCounter; import org.apache.hadoop.metrics2.MetricsCollector; import org.apache.hadoop.metrics2.MetricsInfo; import org.apache.hadoop.metrics2.MetricsRecordBuilder; @@ -154,7 +153,6 @@ public void getMetrics(MetricsCollector collector, boolean all) { } else { getThreadUsageFromGroup(rb); } - getEventCounters(rb); } private void getMemoryUsage(MetricsRecordBuilder rb) { @@ -284,10 +282,4 @@ private void getThreadUsageFromGroup(MetricsRecordBuilder rb) { .addGauge(ThreadsTerminated, threadsTerminated); } - private void getEventCounters(MetricsRecordBuilder rb) { - rb.addCounter(LogFatal, EventCounter.getFatal()) - .addCounter(LogError, EventCounter.getError()) - .addCounter(LogWarn, EventCounter.getWarn()) - .addCounter(LogInfo, EventCounter.getInfo()); - } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/source/TestJvmMetrics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/source/TestJvmMetrics.java index 6fdd64dca7..ea86fc14c7 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/source/TestJvmMetrics.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/source/TestJvmMetrics.java @@ -78,13 +78,8 @@ public void testJvmPauseMonitorPresence() { for (JvmMetricsInfo info : JvmMetricsInfo.values()) { if (info.name().startsWith("Mem")) { verify(rb).addGauge(eq(info), anyFloat()); - } else if (info.name().startsWith("Gc") && - !info.name().equals("GcTimePercentage")) { - verify(rb).addCounter(eq(info), anyLong()); } else if (info.name().startsWith("Threads")) { verify(rb).addGauge(eq(info), anyInt()); - } else if (info.name().startsWith("Log")) { - verify(rb).addCounter(eq(info), anyLong()); } } }