aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/logging
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-10-29 15:01:17 +0200
committerEylon Malin <eylon.malin@intl.att.com>2019-10-30 07:47:32 +0200
commitc638391d22999bd61243794a1981d7476bfdbd5f (patch)
treedcaa2e1ff3743f4c8267acee353e7aaf96d06b70 /vid-app-common/src/main/java/org/onap/vid/logging
parenta8ebb74702f07acead84edcdaf083d78a84d00a3 (diff)
use onap logging 1.6.1 with needed workarounds
Issue-ID: VID-253 Onap logging 1.6.1 has some mismatches regards invocationId. This commit fix these mismatches by fixing the MDC when needed. Change-Id: Ic8d35318ae511667dfa6f9c4297d562fd976a717 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/logging')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricInterceptor.java8
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/LoggingFilterHelper.java49
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java46
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/VidMetricLogClientFilter.java38
4 files changed, 141 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricInterceptor.java b/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricInterceptor.java
index 51e684456..6e125b4e6 100644
--- a/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricInterceptor.java
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricInterceptor.java
@@ -25,6 +25,7 @@ import org.apache.http.HttpMessage;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.onap.logging.filter.base.AbstractMetricLogFilter;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
public abstract class ApacheClientMetricInterceptor extends AbstractMetricLogFilter<HttpRequest, HttpResponse, HttpMessage> {
@@ -59,4 +60,11 @@ public abstract class ApacheClientMetricInterceptor extends AbstractMetricLogFil
//fallback to default value that provided by AbstractMetricLogFilter
return null;
}
+
+ @Override
+ protected void additionalPre(HttpRequest request, HttpMessage message) {
+ LoggingFilterHelper.updateInvocationIDInMdcWithHeaderValue(
+ ()->message.getFirstHeader(ONAPLogConstants.Headers.INVOCATION_ID).getValue());
+ }
+
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/LoggingFilterHelper.java b/vid-app-common/src/main/java/org/onap/vid/logging/LoggingFilterHelper.java
new file mode 100644
index 000000000..1447e828c
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/LoggingFilterHelper.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.logging;
+
+import java.util.function.Supplier;
+import org.onap.logging.filter.base.AbstractMetricLogFilter;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+public class LoggingFilterHelper {
+
+ protected static final Logger logger = LoggerFactory.getLogger(AbstractMetricLogFilter.class);
+
+ /**
+ * set invocationId in MDC with actual header value,
+ * due to bug in AbstractMetricLogFilter
+ *
+ * @param headerSupplier - return the InvocationId header value
+ */
+ static void updateInvocationIDInMdcWithHeaderValue(Supplier<String> headerSupplier) {
+ try {
+ String invocationId = headerSupplier.get();
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
+ }
+ catch (Exception e) {
+ logger.debug("Failed to retrieve "+ONAPLogConstants.Headers.INVOCATION_ID+" header", e);
+ }
+ }
+}
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
new file mode 100644
index 000000000..cdeb20737
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.logging;
+
+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.slf4j.MDC;
+import org.springframework.web.servlet.ModelAndView;
+
+public class VidLoggingInterceptor extends LoggingInterceptor {
+
+ static final String INBOUND_INVO_ID = "InboundInvoId";
+
+ @Override
+ protected void additionalPreHandling(HttpServletRequest request) {
+ super.additionalPreHandling(request);
+ MDC.put(INBOUND_INVO_ID, MDC.get(ONAPLogConstants.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));
+ super.postHandle(request, response, handler, modelAndView);
+ }
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/VidMetricLogClientFilter.java b/vid-app-common/src/main/java/org/onap/vid/logging/VidMetricLogClientFilter.java
new file mode 100644
index 000000000..6b9222ef3
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/VidMetricLogClientFilter.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.logging;
+
+import static org.onap.vid.logging.LoggingFilterHelper.updateInvocationIDInMdcWithHeaderValue;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.core.MultivaluedMap;
+import org.onap.logging.filter.base.MetricLogClientFilter;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+
+public class VidMetricLogClientFilter extends MetricLogClientFilter {
+
+ @Override
+ protected void additionalPre(ClientRequestContext clientRequestContext, MultivaluedMap<String, Object> stringObjectMultivaluedMap) {
+ updateInvocationIDInMdcWithHeaderValue(
+ ()->(String)stringObjectMultivaluedMap.getFirst(ONAPLogConstants.Headers.INVOCATION_ID)
+ );
+ }
+}