diff options
author | Kishore Reddy Dwaram <kishore.reddy.dwaram@att.com> | 2020-09-17 11:22:40 -0400 |
---|---|---|
committer | Kishore Reddy Dwaram <kishore.reddy.dwaram@att.com> | 2020-09-17 17:00:15 -0400 |
commit | 43c4a6ba0fe15350346457d9e8ac2cb4df656b33 (patch) | |
tree | a5dda518526f2dacddb38438709784ce595d9fc3 /ecomp-sdk/epsdk-core | |
parent | 882777cfc554e1eca05d7ba583bc311fd753708b (diff) |
changes in metrics logs
Issue-ID: PORTAL-1008
Change-Id: I007420af6bf5f89862b55b7625f0f2a76d73802f
Signed-off-by: Kishore Reddy Dwaram <kishore.reddy.dwaram@att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-core')
5 files changed, 72 insertions, 66 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java index 55a27837..6a5fe469 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java @@ -37,14 +37,24 @@ */ package org.onap.portalsdk.core.logging.aspect; +import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID; +import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN; +import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS; +import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME; + +import java.net.InetAddress; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.UUID; import javax.servlet.http.HttpServletRequest; import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.exception.SessionExpiredException; +import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; import org.onap.portalsdk.core.logging.format.AuditLogFormatter; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.logging.logic.LoggerProperties; import org.onap.portalsdk.core.service.AppService; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum; @@ -94,21 +104,39 @@ public class EELFLoggerAdvice { methodName = passOnArgs[1].toString(); } - String appName = appService.getDefaultAppName(); + String appName =""; if (appName == null || appName == "") { appName = SystemProperties.SDK_NAME; } - - EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className); + else { + appName = appService.getDefaultAppName(); + } // Initialize Request defaults only for controller methods. + MDC.put(MDC_SERVICE_NAME, SystemProperties.getProperty(SystemProperties.APPLICATION_NAME)); + MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName()); + MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress()); + MDC.put(MDC_INSTANCE_UUID, LoggerProperties.getProperty(LoggerProperties.INSTANCE_UUID)); MDC.put(className + methodName + SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC()); + MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC()); + MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC()); MDC.put(SystemProperties.TARGET_ENTITY, appName + "_BE"); MDC.put(SystemProperties.TARGET_SERVICE_NAME, methodName); + MDC.put(SystemProperties.STATUS_CODE, "INPROGRESS"); + if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){ + String requestId = UUID.randomUUID().toString(); + MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); + } + MDC.put(SystemProperties.PARTNER_NAME, "Unknown"); + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className); + if (securityEventType != null) { MDC.put(className + methodName + SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC()); + MDC.put(SystemProperties.CUSTOM_FIELD1, "ENTRY"); + HttpServletRequest req = null; if (args[0] != null && args[0] instanceof HttpServletRequest) { - HttpServletRequest req = (HttpServletRequest) args[0]; + req = (HttpServletRequest) args[0]; String requestId = UserUtils.getRequestId(req); String loginId = ""; User user = UserUtils.getUserSession(req); @@ -117,7 +145,17 @@ public class EELFLoggerAdvice { } logger.setRequestBasedDefaultsIntoGlobalLoggingContext(req, appName, requestId, loginId); } + MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC()); + this.calculateDateTimeDifference(MDC.get(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP), + MDC.get(SystemProperties.AUDITLOG_END_TIMESTAMP)); + + }else { + MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, getCurrentDateTimeUTC()); + this.calculateDateTimeDifference(MDC.get(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP),MDC.get(SystemProperties.METRICSLOG_END_TIMESTAMP)); + MDC.put(SystemProperties.CUSTOM_FIELD1, "INVOKE"); } + MDC.put(SystemProperties.CUSTOM_FIELD2, " InvocationID="+MDC.get(Configuration.MDC_KEY_REQUEST_ID)); + logger.info(EELFLoggerDelegate.metricsLogger, methodName + " operation is started."); logger.debug(EELFLoggerDelegate.debugLogger, "{} was invoked.", methodName); } catch (Exception e) { adviceLogger.error(EELFLoggerDelegate.errorLogger, "before failed", e); @@ -147,8 +185,6 @@ public class EELFLoggerAdvice { methodName = passOnArgs[1].toString(); } - EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className); - String appName = appService.getDefaultAppName(); if (appName == null || appName == "") { appName = SystemProperties.SDK_NAME; @@ -163,6 +199,15 @@ public class EELFLoggerAdvice { MDC.put(SystemProperties.TARGET_ENTITY, appName + "_BE"); } + if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){ + String requestId = UUID.randomUUID().toString(); + MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); + } + + if (MDC.get(SystemProperties.PARTNER_NAME) == null|| MDC.get(SystemProperties.PARTNER_NAME).isEmpty()){ + MDC.put(SystemProperties.PARTNER_NAME, "Unknown"); + } + MDC.put(MDC_SERVICE_NAME, SystemProperties.getProperty(SystemProperties.APPLICATION_NAME)); MDC.put(SystemProperties.STATUS_CODE, result); @@ -172,9 +217,8 @@ public class EELFLoggerAdvice { this.calculateDateTimeDifference(MDC.get(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP), MDC.get(SystemProperties.METRICSLOG_END_TIMESTAMP)); - - logger.info(EELFLoggerDelegate.metricsLogger, methodName + " operation is completed."); - logger.debug(EELFLoggerDelegate.debugLogger, "Finished executing " + methodName + "."); + MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC()); + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className); if (securityEventType != null) { @@ -183,7 +227,8 @@ public class EELFLoggerAdvice { MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC()); this.calculateDateTimeDifference(MDC.get(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP), MDC.get(SystemProperties.AUDITLOG_END_TIMESTAMP)); - + MDC.put(SystemProperties.CUSTOM_FIELD1, "EXIT"); + this.logSecurityMessage(logger, securityEventType, result, methodName); // clear when finishes audit logging @@ -199,8 +244,12 @@ public class EELFLoggerAdvice { MDC.remove(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP); MDC.remove(SystemProperties.AUDITLOG_END_TIMESTAMP); }else{ - MDC.put(SystemProperties.STATUS_CODE, "COMPLETE"); + MDC.put(SystemProperties.CUSTOM_FIELD1, "INVOKE-RETURN"); } + MDC.put(SystemProperties.STATUS_CODE, "COMPLETE"); + MDC.put(SystemProperties.CUSTOM_FIELD2, " InvocationID="+MDC.get(Configuration.MDC_KEY_REQUEST_ID)); + logger.info(EELFLoggerDelegate.metricsLogger, methodName + " operation is completed."); + logger.debug(EELFLoggerDelegate.debugLogger, "Finished executing " + methodName + "."); MDC.remove(className + methodName + SystemProperties.METRICSLOG_BEGIN_TIMESTAMP); MDC.remove(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP); @@ -209,6 +258,9 @@ public class EELFLoggerAdvice { MDC.remove(SystemProperties.TARGET_ENTITY); MDC.remove(SystemProperties.TARGET_SERVICE_NAME); MDC.remove(SystemProperties.STATUS_CODE); + MDC.remove(MDC_SERVICE_NAME); + MDC.remove(SystemProperties.CUSTOM_FIELD1); + MDC.remove(SystemProperties.CUSTOM_FIELD2); } catch (Exception e) { adviceLogger.error(EELFLoggerDelegate.errorLogger, "after failed", e); diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspect.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspect.java index 0963ef01..b0a2e099 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspect.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspect.java @@ -69,24 +69,6 @@ public class EELFLoggerAspect { return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE); } - /* - * Point cut expression to capture metrics logging - */ - @Pointcut("execution(public * *(..))") - public void publicMethod() { - // By default do nothing - } - - @Around("publicMethod() && @within(metricsLog)") - public Object logMetricsClassAround(ProceedingJoinPoint joinPoint, MetricsLog metricsLog) throws Throwable { - return this.logAroundMethod(joinPoint, null); - } - - @Around("publicMethod() && @annotation(metricsLog)") - public Object logMetricsMethodAround(ProceedingJoinPoint joinPoint, MetricsLog metricsLog) throws Throwable { - return this.logAroundMethod(joinPoint, null); - } - private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType) throws Throwable { // Before diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/SystemProperties.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/SystemProperties.java index ad2e7b89..0ce15b77 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/SystemProperties.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/SystemProperties.java @@ -229,11 +229,14 @@ public class SystemProperties { public static final String CLIENT_IP_ADDRESS = "ClientIPAddress"; public static final String STATUS_CODE = "StatusCode"; public static final String RESPONSE_CODE = "ResponseCode"; + public static final String CUSTOM_FIELD1 = "CustomField1"; + public static final String CUSTOM_FIELD2 = "CustomField2"; + public static final String EXTERNAL_API_RESPONSE_CODE = "External_API_ResponseCode"; // Component or sub component name public static final String TARGET_ENTITY = "TargetEntity"; // API or operation name public static final String TARGET_SERVICE_NAME = "TargetServiceName"; - + public static final String SERVICE_NAME = "ServiceName"; // Logging Compliance public static final String DOUBLE_WHITESPACE_SEPARATOR = " "; public static final String SINGLE_WHITESPACE_SEPARATOR = " "; @@ -251,6 +254,8 @@ public class SystemProperties { public static final String ADDITIONAL_INFO = "ADDITIONAL_INFO"; public static final String INTERFACE_NAME = "INTERFACE_NAME"; public static final String USERAGENT_NAME = "user-agent"; + public static final String AUTHORIZATION = "Authorization"; + public static final String USERNAME = "username"; // Protocols public static final String HTTP = "HTTP"; @@ -342,7 +347,7 @@ public class SystemProperties { * * @return Application name */ - public String getApplicationName() { + public static String getApplicationName() { return getProperty(APPLICATION_NAME); } diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspectTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspectTest.java index fb3dc079..a81de613 100644 --- a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspectTest.java +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspectTest.java @@ -93,40 +93,6 @@ public class EELFLoggerAspectTest { } @Test - public void publicMethodTst(){ - eelFLoggerAspect.publicMethod(); - Assert.assertTrue(true); - } - - @Test - public void logMetricsClassAroundTest() throws Throwable { - ProceedingJoinPoint joinPoint = Mockito.mock(ProceedingJoinPoint.class); - MetricsLog mockLog = Mockito.mock(MetricsLog.class); - Signature sign = Mockito.mock(Signature.class); - - Mockito.when(joinPoint.getSignature()).thenReturn(sign); - Mockito.when(sign.getDeclaringType()).thenReturn(getClass()); - Mockito.when(sign.getName()).thenReturn("MethodName"); - - eelFLoggerAspect.logMetricsClassAround(joinPoint, mockLog); - Assert.assertTrue(true); - } - - @Test - public void logMetricsMethodAroundTest() throws Throwable { - ProceedingJoinPoint joinPoint = Mockito.mock(ProceedingJoinPoint.class); - MetricsLog mockLog = Mockito.mock(MetricsLog.class); - Signature sign = Mockito.mock(Signature.class); - - Mockito.when(joinPoint.getSignature()).thenReturn(sign); - Mockito.when(sign.getDeclaringType()).thenReturn(getClass()); - Mockito.when(sign.getName()).thenReturn("MethodName"); - - eelFLoggerAspect.logMetricsMethodAround(joinPoint, mockLog); - Assert.assertTrue(true); - } - - @Test public void performMetricsLoggingTest() { eelFLoggerAspect.performMetricsLogging(); Assert.assertTrue(true); diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegateTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegateTest.java index 322e3c6b..2d1187f9 100644 --- a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegateTest.java +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegateTest.java @@ -241,7 +241,8 @@ public class EELFLoggerDelegateTest { @Test public void initTest(){ EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); - eelFLoggerDelegate.init(SystemProperties.getProperty(SystemProperties.APPLICATION_NAME)); + String appName = "PortalSDK"; + eelFLoggerDelegate.init(appName); Assert.assertTrue(true); } |