metric log updates and util fix
[logging-analytics.git] / reference / logging-filter / logging-filter-base / src / main / java / org / onap / logging / filter / base / MDCSetup.java
index d0caa46..03dc055 100644 (file)
@@ -54,7 +54,7 @@ public class MDCSetup {
             serverFQDN = addr.getCanonicalHostName();
             MDC.put(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS, addr.getHostAddress());
         } catch (UnknownHostException e) {
-            logger.warn("Cannot Resolve Host Name");
+            logger.trace("Cannot Resolve Host Name");
             serverFQDN = "";
         }
         MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN);
@@ -113,13 +113,7 @@ public class MDCSetup {
         String invocationId = headers.get(ONAPLogConstants.Headers.INVOCATION_ID);
         if (invocationId == null || invocationId.isEmpty())
             invocationId = UUID.randomUUID().toString();
-        MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
-    }
-
-    public void setInvocationIdFromMDC() {
-        String invocationId = MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID);
-        if (invocationId == null || invocationId.isEmpty())
-            invocationId = UUID.randomUUID().toString();
+        MDC.put(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID, invocationId);
         MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
     }
 
@@ -149,12 +143,6 @@ public class MDCSetup {
             return partnerName;
         }
 
-        logger.trace(checkHeaderLogPattern, Constants.HttpHeaders.CLIENT_ID, ONAPLogConstants.MDCs.PARTNER_NAME);
-        partnerName = headers.get(Constants.HttpHeaders.CLIENT_ID);
-        if (partnerName != null && !partnerName.isEmpty()) {
-            return partnerName;
-        }
-
         logger.trace("{} value could not be determined, defaulting partnerName to {}.",
                 ONAPLogConstants.MDCs.PARTNER_NAME, Constants.DefaultValues.UNKNOWN);
         return Constants.DefaultValues.UNKNOWN;
@@ -176,7 +164,7 @@ public class MDCSetup {
             MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
                     Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
         } catch (Exception e) {
-            logger.warn("Unable to calculate elapsed time due to error: {}", e.getMessage());
+            logger.trace("Unable to calculate elapsed time due to error: {}", e.getMessage());
         }
     }
 
@@ -191,7 +179,7 @@ public class MDCSetup {
             MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
                     Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
         } catch (Exception e) {
-            logger.warn("Unable to calculate elapsed time due to error: {}", e.getMessage());
+            logger.trace("Unable to calculate elapsed time due to error: {}", e.getMessage());
         }
     }
 
@@ -212,7 +200,7 @@ public class MDCSetup {
     }
 
     public void clearClientMDCs() {
-        MDC.remove(ONAPLogConstants.MDCs.INVOCATION_ID);
+        MDC.remove(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID);
         MDC.remove(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION);
         MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
         MDC.remove(ONAPLogConstants.MDCs.RESPONSE_CODE);
@@ -248,7 +236,7 @@ public class MDCSetup {
 
     protected String getBasicAuthUserName(SimpleMap headers) {
         String encodedAuthorizationValue = headers.get(HttpHeaders.AUTHORIZATION);
-        if (encodedAuthorizationValue != null) {
+        if (encodedAuthorizationValue != null && encodedAuthorizationValue.startsWith("Basic")) {
             try {
                 // This will strip the word Basic and single space
                 encodedAuthorizationValue = encodedAuthorizationValue.substring(6);