diff options
author | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-12-07 14:41:39 +0100 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-12-10 14:46:23 +0100 |
commit | 8b8c37c296e55644063e0332fd455437168e78da (patch) | |
tree | 36e9d96217346dd4296677cfd8af584c69a0ad05 /sources/hv-collector-dcae-app-simulator/src | |
parent | 73293332b2244b66083dc5d3910801c1b1058105 (diff) |
Add log diagnostic context
As it's not trivial to use MDC directly from logging framework in
reactive application, we need to do some work manually. The approach
proposed is an explicit MDC handling, which means that context is
kept as an object created after establishing client connection. Next,
new instance of HvVesCollector (and its dependencies) is created. Every
object is propagated with ClientContext so it can use it when calling
logger methods.
In the future ClientContext might be used to support other use-cases,
ie. per-topic access control.
As a by-product I had to refactor our Logger wrapper, too. It already
had too many functions and after adding MDC number would be doubled.
Change-Id: I9c5d3f5e1d1be1db66d28d292eb0e1c38d8d0ffe
Issue-ID: DCAEGEN2-671
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'sources/hv-collector-dcae-app-simulator/src')
4 files changed, 10 insertions, 10 deletions
diff --git a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt index 417183fb..f7d94de5 100644 --- a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt +++ b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt @@ -46,7 +46,7 @@ class DcaeAppSimulator(private val consumerFactory: ConsumerFactory, throw IllegalArgumentException(message) } - logger.info("Received new configuration. Creating consumer for topics: $topics") + logger.info { "Received new configuration. Creating consumer for topics: $topics" } consumerState.set(consumerFactory.createConsumerForTopics(topics).bind()) }.fix() diff --git a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt index 20c0f592..36f30e66 100644 --- a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt +++ b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt @@ -61,13 +61,13 @@ class MessageStreamValidation( return messageParams.fold( { logger.warn { "Error while parsing message parameters: ${it::class.qualifiedName} : ${it.message}" } - logger.debug { "Detailed stack trace: ${it}" } + logger.debug { "Detailed stack trace: $it" } throw IllegalArgumentException("Parsing error: " + it.message) }, { if (it.isEmpty()) { val message = "Message param list cannot be empty" - logger.warn(message) + logger.warn { message } throw IllegalArgumentException(message) } it diff --git a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt index a6ee1122..e54eb359 100644 --- a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt +++ b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt @@ -71,15 +71,15 @@ class DcaeAppApiServer(private val simulator: DcaeAppSimulator) { } .delete("messages") { ctx -> ctx.response.contentType(CONTENT_TEXT) - logger.info("Resetting simulator state") + logger.info { "Resetting simulator state" } ctx.response.sendOrError(simulator.resetState()) } .get("messages/all/count") { ctx -> - logger.info("Processing request for count of received messages") + logger.info { "Processing request for count of received messages" } simulator.state().fold( { ctx.response.status(HttpConstants.STATUS_NOT_FOUND) - logger.warn("Error - number of messages could not be specified") + logger.warn { "Error - number of messages could not be specified" } }, { logger.info { "Returned number of received messages: ${it.messagesCount}" } @@ -90,7 +90,7 @@ class DcaeAppApiServer(private val simulator: DcaeAppSimulator) { } .post("messages/all/validate") { ctx -> ctx.request.body.then { body -> - logger.info("Processing request for message validation") + logger.info { "Processing request for message validation" } val response = simulator.validate(body.inputStream) .map { isValid -> if (isValid) { diff --git a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/main.kt b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/main.kt index 06ff4d59..5856f044 100644 --- a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/main.kt +++ b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/main.kt @@ -43,17 +43,17 @@ fun main(args: Array<String>) = .map(::startApp) .unsafeRunEitherSync( { ex -> - logger.error("Failed to start a server", ex) + logger.withError { log("Failed to start a server", ex) } ExitFailure(1) }, { - logger.info("Started DCAE-APP Simulator API server") + logger.info { "Started DCAE-APP Simulator API server" } } ) private fun startApp(config: DcaeAppSimConfiguration): IO<Unit> { - logger.info("Using configuration: $config") + logger.info { "Using configuration: $config" } val consumerFactory = ConsumerFactory(config.kafkaBootstrapServers) val messageStreamValidation = MessageStreamValidation(MessageGeneratorFactory.create(config.maxPayloadSizeBytes)) return DcaeAppApiServer(DcaeAppSimulator(consumerFactory, messageStreamValidation)) |