From ade7ef267161cb22cc2834e44dc6bde0597884f5 Mon Sep 17 00:00:00 2001 From: "Brittany Plummer (bp896r)" Date: Wed, 4 Dec 2019 15:02:50 -0500 Subject: Set InvocationID value from server and client invocationIds Issue-ID: LOG-1189 Change-Id: I471b3f415546d8950f17b91b8d6ac4d415fed076 Signed-off-by: Brittany Plummer (bp896r) --- .../main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java | 1 + .../main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java | 1 + .../src/main/java/org/onap/logging/filter/base/MDCSetup.java | 1 + .../src/test/java/org/onap/logging/filter/base/MDCSetupTest.java | 2 ++ .../java/org/onap/logging/filter/base/MetricLogClientFilterTest.java | 1 + .../java/org/onap/logging/filter/spring/SpringClientFilterTest.java | 2 ++ 6 files changed, 8 insertions(+) diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java index ce2f448..00285b6 100644 --- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java +++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java @@ -52,6 +52,7 @@ public abstract class AbstractAuditLogFilter ex protected void post(GenericResponse response) { try { + MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, MDC.get(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID)); int responseCode = getResponseCode(response); setResponseStatusCode(responseCode); MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(responseCode)); diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java index fabe8d2..16efdea 100644 --- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java +++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java @@ -81,6 +81,7 @@ public abstract class AbstractMetricLogFilter protected String setInvocationId() { String invocationId = UUID.randomUUID().toString(); MDC.put(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID, invocationId); + MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId); return invocationId; } diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java index 70cb46d..d600a2c 100644 --- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java +++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java @@ -114,6 +114,7 @@ public class MDCSetup { if (invocationId == null || invocationId.isEmpty()) invocationId = UUID.randomUUID().toString(); MDC.put(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID, invocationId); + MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId); } public void setMDCPartnerName(SimpleMap headers) { diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java index 68b977d..6340ef1 100644 --- a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java +++ b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java @@ -117,6 +117,7 @@ public class MDCSetupTest extends MDCSetup { headers.put(ONAPLogConstants.Headers.INVOCATION_ID, invocationId); setInvocationId(new SimpleHashMap(headers)); assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID)); + assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); } @Test @@ -124,6 +125,7 @@ public class MDCSetupTest extends MDCSetup { HashMap headers = new HashMap<>(); setInvocationId(new SimpleHashMap(headers)); assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID)); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); } @Test diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java index 48da3fa..a0e1a2b 100644 --- a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java +++ b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java @@ -76,6 +76,7 @@ public class MetricLogClientFilterTest { String invocationId = metricLogClientFilter.setInvocationId(); assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID)); + assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); } @Test diff --git a/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java b/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java index 4346fc1..042e6f1 100644 --- a/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java +++ b/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java @@ -131,6 +131,8 @@ public class SpringClientFilterTest extends SpringClientFilter { assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(Constants.HttpHeaders.TRANSACTION_ID)); assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(Constants.HttpHeaders.ECOMP_REQUEST_ID)); assertNotNull(headers.getFirst(ONAPLogConstants.Headers.INVOCATION_ID)); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID)); assertEquals("UNKNOWN", headers.getFirst(ONAPLogConstants.Headers.PARTNER_NAME)); } -- cgit 1.2.3-korg