Selaa lähdekoodia

AMBARI-20190. LogSearch Integration logs repeated WARN message that should be at DEBUG level. (rnettleton)

Bob Nettleton 8 vuotta sitten
vanhempi
commit
7cffc49cb8

+ 8 - 2
ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java

@@ -131,8 +131,14 @@ public class LoggingSearchPropertyProvider implements PropertyProvider {
           // add the logging metadata for this host component
           resource.setProperty("logging", loggingInfo);
         } else {
-          Utils.logErrorMessageWithCounter(LOG, errorLogCounterForLogSearchConnectionExceptions,
-            "Error occurred while making request to LogSearch service, unable to populate logging properties on this resource");
+          if (LOG.isDebugEnabled()) {
+            String debugMessage =
+              String.format("Error occurred while making request to LogSearch service, unable to populate logging properties on this resource, component = %s, host = %s",
+                            componentName, hostName);
+
+            Utils.logDebugMessageWithCounter(LOG, errorLogCounterForLogSearchConnectionExceptions,
+                                             debugMessage);
+          }
         }
       }
 

+ 14 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/logging/Utils.java

@@ -62,4 +62,18 @@ public class Utils {
       atomicInteger.compareAndSet(maxCount, 0);
     }
   }
+
+  static void logDebugMessageWithCounter(Logger logger, AtomicInteger atomicInteger, String errorMessage) {
+    logDebugMessageWithCounter(logger, atomicInteger, errorMessage, WAIT_COUNT_MAX);
+  }
+
+  static void logDebugMessageWithCounter(Logger logger, AtomicInteger atomicInteger, String debugMessage, int maxCount) {
+    if (atomicInteger.getAndIncrement() == 0) {
+      // only log the message once every maxCount attempts
+      logger.debug(debugMessage);
+    } else {
+      // if we've hit maxCount attempts, reset the counter
+      atomicInteger.compareAndSet(maxCount, 0);
+    }
+  }
 }