Update metric logger 77/97277/2
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Thu, 17 Oct 2019 18:16:10 +0000 (18:16 +0000)
committerKevin Smokowski <kevin.smokowski@att.com>
Thu, 17 Oct 2019 19:25:30 +0000 (19:25 +0000)
set status during invoke and escape certain characters

Issue-ID: CCSDK-1845
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Change-Id: I3928364f480545ccdcce0af67e198d93152cfbd8

sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java
sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java

index c2670ec..518316d 100755 (executable)
@@ -92,6 +92,8 @@ public class MetricLogger {
             MDC.put(ONAPLogConstants.MDCs.TARGET_ELEMENT, targetElement);
         }
         this.lastMsg = msg;
+        //During invoke status will always be INPROGRESS
+        MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
         METRIC.info(INVOKE, "Invoke");
     }
     
@@ -119,6 +121,8 @@ public class MetricLogger {
         if (str != null) {
             str = str.replaceAll("\\R", ""); // this will strip all new line characters
             str = str.replaceAll("\\|", "%7C"); // log records should not contain a pipe, encode the pipe character
+            str = str.replaceAll("\t", " "); // tabs are not allowed, replace with spaces
+            str = str.replace(",", "\\,"); // comma must be escaped
         }
         return str;
     }
index ec3a31e..4b371cf 100755 (executable)
@@ -42,6 +42,9 @@ public class TestMetricLogger {
         assertEquals("%7C",output);
         output = logger.formatString(null);
         assertEquals(null,output);
+        output = logger.formatString("\t");
+        assertEquals(" ", output);
+        output = logger.formatString("one,two,three,");
+        assertEquals("one\\,two\\,three\\,", output);
     }
-
 }