From 969d2d7c2caed78d297ccf8e0ebc9120831c18b0 Mon Sep 17 00:00:00 2001 From: nrpandya Date: Sun, 11 Oct 2020 21:24:18 -0500 Subject: Add InvocationID to p_mdc field in audit logs Add InvocationID in SLF4JLoggerWrapper for audit entry and exit Issue-ID: SDC-3312 Change-Id: Id19dd3cfff75a23f14d0a1d22520a2e967e46289 Signed-off-by: nrpandya --- .../src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java | 3 ++- .../java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java | 2 ++ .../org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src') diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java index c4e780fa8f..c08952a84d 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java @@ -32,7 +32,8 @@ enum AuditField implements MDCField { STATUS_CODE(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE), RESPONSE_CODE(ONAPLogConstants.MDCs.RESPONSE_CODE), RESPONSE_DESCRIPTION(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION), - CLIENT_IP_ADDRESS(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS); + CLIENT_IP_ADDRESS(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS), + INVOCATION_ID(ONAPLogConstants.MDCs.INVOCATION_ID); private final String key; diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java index f85a6bbe95..54026098c1 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java @@ -17,6 +17,7 @@ package org.openecomp.sdc.logging.slf4j; import java.text.SimpleDateFormat; +import java.util.UUID; import org.openecomp.sdc.logging.api.AuditData; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.MetricsData; @@ -157,6 +158,7 @@ class SLF4JLoggerWrapper implements Logger { safePutOnMdc(AuditField.RESPONSE_CODE, audit.getResponseCode()); safePutOnMdc(AuditField.RESPONSE_DESCRIPTION, audit.getResponseDescription()); safePutOnMdc(AuditField.CLIENT_IP_ADDRESS, audit.getClientIpAddress()); + unsafePutOnMdc(AuditField.INVOCATION_ID, UUID.randomUUID().toString()); if (audit.getStatusCode() != null) { unsafePutOnMdc(AuditField.STATUS_CODE, audit.getStatusCode().name()); diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java index 2b98fc898f..6785c15355 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java @@ -220,6 +220,13 @@ public class SLF4JLoggerWrapperTest { assertNull(spy.mdc().get(MetricsField.CLIENT_IP_ADDRESS.asKey())); } + @Test + public void auditInvocationIdAvailable() { + SpyLogger spy = createSpy(); + new SLF4JLoggerWrapper(spy).auditExit(AuditData.builder().build()); + assertNotNull(spy.mdc().get(AuditField.INVOCATION_ID.asKey())); + } + @Test public void metricsTargetEntityAvailableWhenPassed() { final String targetEntity = "MetricsTargetEntity"; -- cgit 1.2.3-korg