aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-11-03 08:09:32 +0200
committerEylon Malin <eylon.malin@intl.att.com>2019-11-04 05:52:43 +0000
commita601ad50c15425fb2e2d743493ae1ee96d88ce50 (patch)
tree25c97d455b2825cd3be01e1ccbe890a3b9f839fd /vid-app-common/src
parent3a6149664092cacfdf76c0ab985a250ec9131439 (diff)
fix SERVER_FQDN MDC for audit log
Issue-ID: VID-253 Change-Id: I6f4b273d800a6eba735744fbd7bc3e741c1a5e83 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common/src')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java41
1 files changed, 38 insertions, 3 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));
+ }
+
}