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-xnf-simulator | |
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-xnf-simulator')
4 files changed, 16 insertions, 14 deletions
diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/VesHvClient.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/VesHvClient.kt index 57aaf3db..ca6d169a 100644 --- a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/VesHvClient.kt +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/VesHvClient.kt @@ -61,12 +61,14 @@ class VesHvClient(private val configuration: SimulatorConfiguration) { .handle { _, output -> handler(complete, messages, output) } .connect() .doOnError { - logger.info("Failed to connect to VesHvCollector on " + - "${configuration.vesHost}:${configuration.vesPort}") + logger.info { + "Failed to connect to VesHvCollector on ${configuration.vesHost}:${configuration.vesPort}" + } } .subscribe { - logger.info("Connected to VesHvCollector on " + - "${configuration.vesHost}:${configuration.vesPort}") + logger.info { + "Connected to VesHvCollector on ${configuration.vesHost}:${configuration.vesPort}" + } } return complete.then() } @@ -86,7 +88,7 @@ class VesHvClient(private val configuration: SimulatorConfiguration) { .options { it.flushOnBoundary() } .sendGroups(frames) .then { - logger.info("Messages have been sent") + logger.info { "Messages have been sent" } complete.onComplete() } .then() diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt index 16019384..cfd3a6e9 100644 --- a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt @@ -59,17 +59,17 @@ internal class XnfApiServer( .post("simulator/async", ::startSimulationHandler) .get("simulator/:id", ::simulatorStatusHandler) .get("healthcheck") { ctx -> - logger.info("Checking health") + logger.info { "Checking health" } ctx.response.status(HttpConstants.STATUS_OK).send() } } private fun startSimulationHandler(ctx: Context) { - logger.info("Attempting to start asynchronous scenario") + logger.info { "Attempting to start asynchronous scenario" } ctx.request.body.then { body -> val id = startSimulation(body) when (id) { - is Either.Left -> logger.warn { "Failed to start scenario, ${id.a}"} + is Either.Left -> logger.warn { "Failed to start scenario, ${id.a}" } is Either.Right -> logger.info { "Scenario started, details: ${id.b}" } } ctx.response.sendEitherErrorOrResponse(id) @@ -83,7 +83,7 @@ internal class XnfApiServer( } private fun simulatorStatusHandler(ctx: Context) { - logger.debug("Checking task status") + logger.debug { "Checking task status" } val id = UUID.fromString(ctx.pathTokens["id"]) logger.debug { "Checking status for id: $id" } val status = ongoingSimulations.status(id) diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/simulations.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/simulations.kt index 21748ae8..d7d42d88 100644 --- a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/simulations.kt +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/simulations.kt @@ -43,11 +43,11 @@ class OngoingSimulations(executor: Executor = Executors.newCachedThreadPool()) { simulationIo.continueOn(asyncSimulationContext).unsafeRunAsync { result -> result.fold( { err -> - logger.warn("Error", err) + logger.withWarn { log("Error", err) } simulations[id] = StatusFailure(err) }, { - logger.info("Finished sending messages") + logger.info { "Finished sending messages" } simulations[id] = StatusSuccess } ) diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt index 4512dfbf..91070d35 100644 --- a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt @@ -42,7 +42,7 @@ const val PROGRAM_NAME = "java $PACKAGE_NAME.MainKt" fun main(args: Array<String>) = ArgXnfSimulatorConfiguration().parse(args) .mapLeft(handleWrongArgumentErrorCurried(PROGRAM_NAME)) .map { config -> - logger.info("Using configuration: $config") + logger.info { "Using configuration: $config" } val xnfSimulator = XnfSimulator( VesHvClient(config), MessageGeneratorFactory.create(config.maxPayloadSizeBytes)) @@ -52,10 +52,10 @@ fun main(args: Array<String>) = ArgXnfSimulatorConfiguration().parse(args) } .unsafeRunEitherSync( { ex -> - logger.error("Failed to start a server", ex) + logger.withError { log("Failed to start a server", ex) } ExitFailure(1) }, { - logger.info("Started xNF Simulator API server") + logger.info { "Started xNF Simulator API server" } } ) |