aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-11-04 08:16:53 +0000
committerGerrit Code Review <gerrit@onap.org>2019-11-04 08:16:53 +0000
commit46d7ba49211c86e9208d6634461afc6ebac70f8d (patch)
tree8cff650bf9d12eb96b67f99930aa3878b7c97566
parent129b3904c875018bea237a3f376a0e1c3ab9a4f9 (diff)
parenta601ad50c15425fb2e2d743493ae1ee96d88ce50 (diff)
Merge "fix SERVER_FQDN MDC for audit log"
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java41
-rw-r--r--vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java2
2 files changed, 39 insertions, 4 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java
index cdeb20737..abc7048da 100644
--- a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java
@@ -20,10 +20,12 @@
package org.onap.vid.logging;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.onap.logging.filter.spring.LoggingInterceptor;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs;
import org.slf4j.MDC;
import org.springframework.web.servlet.ModelAndView;
@@ -31,16 +33,49 @@ public class VidLoggingInterceptor extends LoggingInterceptor {
static final String INBOUND_INVO_ID = "InboundInvoId";
+ private static final String canonicalHostName = getCanonicalName();
+
+ private static String getCanonicalName() {
+ try {
+ return InetAddress.getLocalHost().getCanonicalHostName();
+ } catch (UnknownHostException e) {
+ // YOLO
+ return "";
+ }
+ }
+
@Override
protected void additionalPreHandling(HttpServletRequest request) {
super.additionalPreHandling(request);
- MDC.put(INBOUND_INVO_ID, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID));
+ storeInboundInvocationId();
+ }
+
+ /*
+ * store inbound invocationId for later use in restoreInvocationId
+ */
+ private void storeInboundInvocationId() {
+ MDC.put(INBOUND_INVO_ID, MDC.get(MDCs.INVOCATION_ID));
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, MDC.get(INBOUND_INVO_ID));
+ restoreInvocationId();
+ fixServerFQDN();
super.postHandle(request, response, handler, modelAndView);
}
+ /*
+ * fix SERVER_FQDN, because EELFLoggerDelegate::setGlobalLoggingContext put wrong value
+ */
+ private void fixServerFQDN() {
+ MDC.put(MDCs.SERVER_FQDN, canonicalHostName);
+ }
+
+ /**
+ * restore invocationId that was overwritten by metrics interceptor
+ */
+ private void restoreInvocationId() {
+ MDC.put(MDCs.INVOCATION_ID, MDC.get(INBOUND_INVO_ID));
+ }
+
}
diff --git a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java
index 2f8215a97..6638a0e23 100644
--- a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java
+++ b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java
@@ -55,7 +55,7 @@ public class LoggerFormatTest extends BaseApiTest {
@Test
public void validateAudit2019LogsFormat() {
- validateLogsFormat(LogName.audit2019, "audit-ELS-2019.11", 0.8);
+ validateLogsFormat(LogName.audit2019, "audit-ELS-2019.11");
}
@Test(enabled = false) // no total-score is returned for error-log