From b4beb977c8dade82e27b37119992df817ecb67b5 Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Thu, 24 Oct 2019 11:37:34 +0300 Subject: don't add request id to MDC in VidLoggerAspect Issue-ID: VID-253 request id is added to MDC by org.onap.logging.filter.spring.LoggingInterceptor so VidLoggerAspect don't need to add the request id to MDC Signed-off-by: Eylon Malin Change-Id: I8883de54f6775cfc80df6f45b8ec489841b5a97a --- .../src/main/java/org/onap/vid/logging/VidLoggerAspect.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'vid-app-common/src/main') diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java index f87297c37..08aaf09ce 100644 --- a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java +++ b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java @@ -32,7 +32,6 @@ import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; -import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.service.AppService; @@ -40,7 +39,6 @@ import org.onap.portalsdk.core.util.SystemProperties; import org.onap.portalsdk.core.web.support.UserUtils; import org.onap.vid.controller.ControllersUtils; import org.onap.vid.utils.SystemPropertiesWrapper; -import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -92,7 +90,7 @@ public class VidLoggerAspect { HttpServletRequest httpServletRequest = httpServletRequestOrNull(joinPoint); fixSetRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest, joinPoint.getSignature().getDeclaringType().getName()); - addRequestIdToMdcForMetricFilter(httpServletRequest); + fixServerFqdnInMDC(); //Execute the actual method @@ -111,14 +109,6 @@ public class VidLoggerAspect { return result; } - //prepare MDC for org.onap.logging.filter.base.AbstractMetricLogFilter - private void addRequestIdToMdcForMetricFilter(HttpServletRequest httpServletRequest) { - if (httpServletRequest!=null) { - String requestId = UserUtils.getRequestId(httpServletRequest); - MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId); - } - } - // Set the status code into MDC *before* the metrics log is written by advice.after() private void fixStatusCodeInMDC(String restStatus) { EELFLoggerDelegate.mdcPut(SystemProperties.STATUS_CODE, restStatus); @@ -166,7 +156,6 @@ public class VidLoggerAspect { String loginId = controllersUtils.extractUserId(httpServletRequest); logger.setRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest, appName, requestId, loginId); - } } -- cgit 1.2.3-korg From 55f21cee67b36dd6352a775a50ef048a0ff35140 Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Thu, 24 Oct 2019 12:43:12 +0300 Subject: fix ApacheClientMetricInterceptor to return expected ResponseCode Issue-ID: VID-253 Signed-off-by: Eylon Malin Change-Id: I5c90f5bcbf34eee28c192128333ca940558ecb30 --- .../onap/vid/logging/ApacheClientMetricInterceptor.java | 2 +- .../vid/logging/ApacheClientMetricInterceptorTest.java | 2 +- .../test/java/org/onap/vid/more/LoggerFormatTest.java | 17 ++++++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) (limited to 'vid-app-common/src/main') 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 f5b09501e..51e684456 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 @@ -51,7 +51,7 @@ public abstract class ApacheClientMetricInterceptor extends AbstractMetricLogFil @Override protected String getResponseCode(HttpResponse httpResponse) { - return httpResponse.getStatusLine().getReasonPhrase(); + return String.valueOf(httpResponse.getStatusLine().getStatusCode()); } @Override diff --git a/vid-app-common/src/test/java/org/onap/vid/logging/ApacheClientMetricInterceptorTest.java b/vid-app-common/src/test/java/org/onap/vid/logging/ApacheClientMetricInterceptorTest.java index 29f17b2e7..43f986501 100644 --- a/vid-app-common/src/test/java/org/onap/vid/logging/ApacheClientMetricInterceptorTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/logging/ApacheClientMetricInterceptorTest.java @@ -67,7 +67,7 @@ public class ApacheClientMetricInterceptorTest { @Test public void testGetResponseCode() { - assertEquals(interceptor.getResponseCode(response), "ok"); + assertEquals(interceptor.getResponseCode(response), "200"); } @Test diff --git a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java index 6a4bf950f..50c3db861 100644 --- a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java +++ b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java @@ -8,6 +8,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInRelativeOrder; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; import static vid.automation.test.services.SimulatorApi.retrieveRecordedRequests; @@ -27,7 +28,6 @@ import org.onap.vid.api.BaseApiTest; import org.springframework.web.client.RestTemplate; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import vid.automation.test.infra.SkipTestUntil; import vid.automation.test.services.SimulatorApi; import vid.automation.test.services.SimulatorApi.RecordedRequests; @@ -50,7 +50,6 @@ public class LoggerFormatTest extends BaseApiTest { SimulatorApi.registerExpectationFromPreset(new PresetAAIGetSubscribersGet(), SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET); } - @SkipTestUntil("2019-09-24") @Test public void validateAuditLogsFormat() { validateLogsFormat(LogName.audit); @@ -66,12 +65,16 @@ public class LoggerFormatTest extends BaseApiTest { validateLogsFormat(LogName.error); } - @SkipTestUntil("2019-09-24") @Test public void validateMetricsLogsFormat() { validateLogsFormat(LogName.metrics, "metric"); } + @Test + public void validateMetrics2019LogsFormat() { + validateLogsFormat(LogName.metrics2019, "metric-ELS-2019.11"); + } + private void validateLogsFormat(LogName logName) { validateLogsFormat(logName, logName.name()); } @@ -86,12 +89,12 @@ public class LoggerFormatTest extends BaseApiTest { logger.info("logLines are: "+logLines); JsonNode response = getCheckerResults(logType, logLines); logger.info("Response is:" + response.toString()); - double fieldscore = response.path("summary").path("score").path("fieldscore").asDouble(); - double overall = response.path("summary").path("score").path("overallscore").asDouble(); - assertThat(fieldscore, is(greaterThanOrEqualTo(score))); - assertThat(overall, is(greaterThanOrEqualTo(score))); + int total_records = response.path("summary").path("total_records").asInt(); + int valid_records = response.path("summary").path("valid_records").asInt(); + assertThat(total_records, greaterThan(30)); //make sure we have at least 30 total records + assertThat((double)valid_records/total_records, is(greaterThanOrEqualTo(score))); } private String getLogLines(LogName logname) { -- cgit 1.2.3-korg