Add rest client invocation log tracing. 65/98165/1
authorBrinda Santh <bs2796@att.com>
Fri, 8 Nov 2019 00:06:19 +0000 (19:06 -0500)
committerBrinda Santh <bs2796@att.com>
Fri, 8 Nov 2019 00:06:19 +0000 (19:06 -0500)
Issue-ID: CCSDK-1046
Signed-off-by: Brinda Santh <bs2796@att.com>
Change-Id: Ie44a1b2628132aa44bc923a4d622544db03b46b0

ms/blueprintsprocessor/application/src/main/resources/application-dev.properties
ms/blueprintsprocessor/application/src/main/resources/logback.xml
ms/blueprintsprocessor/application/src/test/resources/logback-test.xml
ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt
ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt

index faabb80..485b0bf 100755 (executable)
@@ -24,8 +24,8 @@
 # Web server config
 server.port=8081
 # Used in Health Check
-endpoints.user.name=ccsdkapps
-endpoints.user.password=ccsdkapps
+security.user.password: {bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu
+security.user.name: ccsdkapps
 
 ### START -Controller Blueprints Properties
 # Load Resource Source Mappings
index 9d2b82f..e1389a6 100644 (file)
     <property name="defaultPattern"
               value="%date{ISO8601,UTC}|%X{RequestID}|%X{InvocationID}|%thread|%X{ServiceName}|%X{ClientIPAddress}|%logger{50}| %msg%n"/>
 
-    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
-        <!-- encoders are assigned the type
-             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
-        <encoder>
-            <pattern>${defaultPattern}</pattern>
-        </encoder>
+    <property name="colorPattern"
+              value="%${color}(%d{HH:mm:ss.SSS}|%X{RequestID}|%thread|%X{ServiceName}|%X{ClientIPAddress}|%logger{50}| %msg%n)"/>
+
+    <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
+        <discriminator class="org.onap.ccsdk.cds.blueprintsprocessor.uat.logging.SmartColorDiscriminator">
+            <defaultValue>white</defaultValue>
+        </discriminator>
+        <sift>
+            <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+                <encoder>
+                    <pattern>${defaultPattern}</pattern>
+                </encoder>
+            </appender>
+        </sift>
     </appender>
 
     <logger name="org.springframework" level="info"/>
@@ -34,7 +42,7 @@
     <logger name="org.onap.ccsdk.cds" level="info"/>
 
     <root level="info">
-        <appender-ref ref="STDOUT"/>
+        <appender-ref ref="SIFT"/>
     </root>
 
 </configuration>
index f635e79..90dfed3 100644 (file)
@@ -23,7 +23,7 @@
         <sift>
             <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
                 <encoder>
-                    <pattern>%${color}(%d{HH:mm:ss.SSS} %-5level %-40.40logger{39} : %msg%n)</pattern>
+                    <pattern>%${color}(%d{HH:mm:ss.SSS}|%X{RequestID}|%X{InvocationID}| %-5level %-40.40logger{39} : %msg%n)</pattern>
                 </encoder>
             </appender>
         </sift>
index 26c8088..3e31bf9 100644 (file)
@@ -97,12 +97,14 @@ interface BlueprintWebClientService {
 
     fun <T> delete(path: String, headers: Array<BasicHeader>, responseType: Class<T>): WebClientResponse<T> {
         val httpDelete = HttpDelete(host(path))
+        RestLoggerService.httpInvoking(headers)
         httpDelete.setHeaders(headers)
         return performCallAndExtractTypedWebClientResponse(httpDelete, responseType)
     }
 
     fun <T> get(path: String, headers: Array<BasicHeader>, responseType: Class<T>): WebClientResponse<T> {
         val httpGet = HttpGet(host(path))
+        RestLoggerService.httpInvoking(headers)
         httpGet.setHeaders(headers)
         return performCallAndExtractTypedWebClientResponse(httpGet, responseType)
     }
@@ -111,6 +113,7 @@ interface BlueprintWebClientService {
         val httpPost = HttpPost(host(path))
         val entity = StringEntity(strRequest(request))
         httpPost.entity = entity
+        RestLoggerService.httpInvoking(headers)
         httpPost.setHeaders(headers)
         return performCallAndExtractTypedWebClientResponse(httpPost, responseType)
     }
@@ -119,6 +122,7 @@ interface BlueprintWebClientService {
         val httpPut = HttpPut(host(path))
         val entity = StringEntity(strRequest(request))
         httpPut.entity = entity
+        RestLoggerService.httpInvoking(headers)
         httpPut.setHeaders(headers)
         return performCallAndExtractTypedWebClientResponse(httpPut, responseType)
     }
@@ -127,6 +131,7 @@ interface BlueprintWebClientService {
         val httpPatch = HttpPatch(host(path))
         val entity = StringEntity(strRequest(request))
         httpPatch.entity = entity
+        RestLoggerService.httpInvoking(headers)
         httpPatch.setHeaders(headers)
         return performCallAndExtractTypedWebClientResponse(httpPatch, responseType)
     }
index cec11ae..969de83 100644 (file)
@@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest.service
 import kotlinx.coroutines.*
 import kotlinx.coroutines.reactor.ReactorContext
 import kotlinx.coroutines.reactor.asCoroutineContext
+import org.apache.http.message.BasicHeader
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_INVOCATION_ID
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_PARTNER_NAME
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_REQUEST_ID
@@ -36,12 +37,24 @@ import java.net.InetAddress
 import java.time.ZoneOffset
 import java.time.ZonedDateTime
 import java.time.format.DateTimeFormatter
+import java.util.*
 import kotlin.coroutines.CoroutineContext
 import kotlin.coroutines.EmptyCoroutineContext
 
 class RestLoggerService {
     private val log = logger(RestLoggerService::class)
 
+    companion object {
+        /** Used before invoking any REST outbound request, Inbound Invocation ID is used as request Id
+         * for outbound Request, If invocation Id is missing then default Request Id will be generated.
+         */
+        fun httpInvoking(headers: Array<BasicHeader>) {
+            headers.plusElement(BasicHeader(ONAP_REQUEST_ID, MDC.get("InvocationID").defaultToUUID()))
+            headers.plusElement(BasicHeader(ONAP_INVOCATION_ID, UUID.randomUUID().toString()))
+            val partnerName = System.getProperty("APPNAME") ?: "BlueprintsProcessor"
+            headers.plusElement(BasicHeader(ONAP_PARTNER_NAME, partnerName))
+        }
+    }
 
     fun entering(request: ServerHttpRequest) {
         val localhost = InetAddress.getLocalHost()
@@ -54,7 +67,7 @@ class RestLoggerService {
         MDC.put("InvocationID", invocationID)
         MDC.put("PartnerName", partnerName)
         MDC.put("ClientIPAddress", request.remoteAddress?.address?.hostAddress.defaultToEmpty())
-        MDC.put("ServerFQDN",localhost.hostName.defaultToEmpty())
+        MDC.put("ServerFQDN", localhost.hostName.defaultToEmpty())
         if (MDC.get("ServiceName") == null || MDC.get("ServiceName").equals("", ignoreCase = true)) {
             MDC.put("ServiceName", request.uri.path)
         }