From 54eb2f2680d4f2447a4d48b612b2b83e37d90754 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Thu, 7 Nov 2019 19:06:19 -0500 Subject: Add rest client invocation log tracing. Issue-ID: CCSDK-1046 Signed-off-by: Brinda Santh Change-Id: Ie44a1b2628132aa44bc923a4d622544db03b46b0 --- .../rest/service/BlueprintWebClientService.kt | 5 +++++ .../blueprintsprocessor/rest/service/RestLoggerService.kt | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'ms/blueprintsprocessor/modules') diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt index 26c808874..3e31bf9ec 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt @@ -97,12 +97,14 @@ interface BlueprintWebClientService { fun delete(path: String, headers: Array, responseType: Class): WebClientResponse { val httpDelete = HttpDelete(host(path)) + RestLoggerService.httpInvoking(headers) httpDelete.setHeaders(headers) return performCallAndExtractTypedWebClientResponse(httpDelete, responseType) } fun get(path: String, headers: Array, responseType: Class): WebClientResponse { 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) } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt index cec11ae3c..969de836c 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt @@ -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) { + 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) } -- cgit 1.2.3-korg