From 3d97f873d014bd39dc743dd4d5b76c998123b65f Mon Sep 17 00:00:00 2001 From: Julien Fontaine Date: Tue, 27 Oct 2020 17:45:39 -0400 Subject: Blueprints Processor Metrics Add counter and timer for Blueprints Processor process to get success/failure and execution time for each blueprint execution using blueprint name, version and action. Issue-ID: CCSDK-2950 Change-Id: I38e8997de26effe69ec2ee9e2b6ed0da14de4a43 Signed-off-by: Julien Fontaine Signed-off-by: Jozsef Csongvai --- .../modules/inbounds/health-api-common/pom.xml | 7 +++ .../modules/inbounds/selfservice-api/pom.xml | 5 ++ .../selfservice/api/ExecutionServiceHandler.kt | 15 +++++- .../selfservice/api/SelfServiceMetricConstants.kt | 21 +++++++++ .../selfservice/api/utils/Utils.kt | 24 ++++++++++ .../api/BluePrintProcessingGRPCHandlerTest.kt | 5 ++ .../api/BluePrintProcessingKafkaConsumerTest.kt | 5 ++ .../api/ExecutionServiceControllerTest.kt | 4 +- .../selfservice/api/ExecutionServiceHandlerTest.kt | 11 ++++- .../selfservice/api/utils/UtilsTest.kt | 54 ++++++++++++++++++++++ 10 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/SelfServiceMetricConstants.kt (limited to 'ms/blueprintsprocessor') diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/pom.xml b/ms/blueprintsprocessor/modules/inbounds/health-api-common/pom.xml index 93c9d18a5..2bfcbe38a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/pom.xml @@ -36,6 +36,13 @@ org.onap.ccsdk.cds.blueprintsprocessor.modules rest-lib + + + + io.micrometer + micrometer-registry-prometheus + + org.springframework.boot spring-boot-starter-actuator diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml index f136af379..706dd458a 100755 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml @@ -81,5 +81,10 @@ + + + io.micrometer + micrometer-core + diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt index 4a7171ceb..89a963727 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt @@ -18,6 +18,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api import io.grpc.stub.StreamObserver +import io.micrometer.core.instrument.MeterRegistry +import io.micrometer.core.instrument.Timer import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -27,6 +29,9 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInpu import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.toProto +import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.SelfServiceMetricConstants.COUNTER_PROCESS +import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.SelfServiceMetricConstants.TIMER_PROCESS +import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.cbaMetricTags import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractServiceFunction import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants @@ -45,7 +50,8 @@ class ExecutionServiceHandler( private val blueprintsProcessorCatalogService: BluePrintCatalogService, private val bluePrintWorkflowExecutionService: BluePrintWorkflowExecutionService, - private val publishAuditService: PublishAuditService + private val publishAuditService: PublishAuditService, + private val meterRegistry: MeterRegistry ) { private val log = LoggerFactory.getLogger(ExecutionServiceHandler::class.toString()) @@ -75,6 +81,7 @@ class ExecutionServiceHandler( "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", true ) + meterRegistry.counter(COUNTER_PROCESS, cbaMetricTags(executionServiceOutput)).increment() publishAuditService.publishExecutionOutput(executionServiceInput.correlationUUID, executionServiceOutput) responseObserver.onNext( executionServiceOutput.toProto() @@ -93,8 +100,10 @@ class ExecutionServiceHandler( log.info("processing request id $requestId") + // Audit input publishAuditService.publishExecutionInput(executionServiceInput) + val sample = Timer.start() try { /** Check Blueprint is needed for this request */ if (checkServiceFunction(executionServiceInput)) { @@ -120,7 +129,11 @@ class ExecutionServiceHandler( log.error("fail processing request id $requestId", e) executionServiceOutput = response(executionServiceInput, e.localizedMessage ?: e.message ?: e.toString(), true) } + // Update process metrics + sample.stop(meterRegistry.timer(TIMER_PROCESS, cbaMetricTags(executionServiceInput))) + meterRegistry.counter(COUNTER_PROCESS, cbaMetricTags(executionServiceOutput)).increment() + // Audit output publishAuditService.publishExecutionOutput(executionServiceInput.correlationUUID, executionServiceOutput) return executionServiceOutput } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/SelfServiceMetricConstants.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/SelfServiceMetricConstants.kt new file mode 100644 index 000000000..97c73243d --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/SelfServiceMetricConstants.kt @@ -0,0 +1,21 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api + +object SelfServiceMetricConstants { + + private const val METRICS_PREFIX = "cds.cba" + + private const val PROCESS_PREFIX = "$METRICS_PREFIX.process" + + // TAGS + const val TAG_BP_NAME = "blueprint_name" + const val TAG_BP_VERSION = "blueprint_version" + const val TAG_BP_ACTION = "blueprint_action" + const val TAG_BP_STATUS = "status" + const val TAG_BP_OUTCOME = "outcome" + + // COUNTERS + const val COUNTER_PROCESS = "$PROCESS_PREFIX.counter" + + // TIMERS + const val TIMER_PROCESS = "$PROCESS_PREFIX.timer" +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt index 66cdbef3e..08cae09b3 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt @@ -15,6 +15,10 @@ */ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils +import io.micrometer.core.instrument.Tag +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.SelfServiceMetricConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.springframework.http.HttpStatus import org.springframework.http.codec.multipart.FilePart @@ -60,3 +64,23 @@ fun determineHttpStatusCode(statusCode: Int): HttpStatus { return HttpStatus.valueOf(INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE) } } + +fun cbaMetricTags(executionServiceInput: ExecutionServiceInput): MutableList = + executionServiceInput.actionIdentifiers.let { + mutableListOf( + Tag.of(SelfServiceMetricConstants.TAG_BP_NAME, it.blueprintName), + Tag.of(SelfServiceMetricConstants.TAG_BP_VERSION, it.blueprintVersion), + Tag.of(SelfServiceMetricConstants.TAG_BP_ACTION, it.actionName) + ) + } + +fun cbaMetricTags(executionServiceOutput: ExecutionServiceOutput): MutableList = + executionServiceOutput.let { + mutableListOf( + Tag.of(SelfServiceMetricConstants.TAG_BP_NAME, it.actionIdentifiers.blueprintName), + Tag.of(SelfServiceMetricConstants.TAG_BP_VERSION, it.actionIdentifiers.blueprintVersion), + Tag.of(SelfServiceMetricConstants.TAG_BP_ACTION, it.actionIdentifiers.actionName), + Tag.of(SelfServiceMetricConstants.TAG_BP_STATUS, it.status.code.toString()), + Tag.of(SelfServiceMetricConstants.TAG_BP_OUTCOME, it.status.message) + ) + } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt index 8cfd562d1..0d79368ad 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt @@ -21,6 +21,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api import com.google.protobuf.util.JsonFormat import io.grpc.stub.StreamObserver import io.grpc.testing.GrpcServerRule +import io.micrometer.core.instrument.MeterRegistry import org.junit.Assert import org.junit.Rule import org.junit.Test @@ -33,6 +34,7 @@ import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceIn import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.test.annotation.DirtiesContext import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource @@ -52,6 +54,9 @@ class BluePrintProcessingGRPCHandlerTest { private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java) + @MockBean + lateinit var meterRegistry: MeterRegistry + @get:Rule val grpcServerRule = GrpcServerRule().directExecutor() diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumerTest.kt index 4a11aeebd..7f82ec001 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumerTest.kt @@ -16,6 +16,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api +import io.micrometer.core.instrument.MeterRegistry import io.mockk.coEvery import io.mockk.mockk import kotlinx.coroutines.delay @@ -27,6 +28,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguratio import org.onap.ccsdk.cds.blueprintsprocessor.message.BluePrintMessageLibConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BluePrintMessageLibPropertyService import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner @@ -43,6 +45,9 @@ import kotlin.test.assertNotNull @TestPropertySource(locations = ["classpath:application-test.properties"]) class BluePrintProcessingKafkaConsumerTest { + @MockBean + lateinit var meterRegistry: MeterRegistry + @Autowired lateinit var bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt index ce78aab0e..d7d7aaa2a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt @@ -17,6 +17,7 @@ */ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api +import io.micrometer.core.instrument.simple.SimpleMeterRegistry import kotlinx.coroutines.runBlocking import org.junit.Test import org.junit.runner.RunWith @@ -45,7 +46,8 @@ import kotlin.test.assertTrue @ContextConfiguration( classes = [ ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, - BluePrintCatalogService::class, SelfServiceApiTestConfiguration::class, ErrorCatalogTestConfiguration::class + BluePrintCatalogService::class, SelfServiceApiTestConfiguration::class, + ErrorCatalogTestConfiguration::class, SimpleMeterRegistry::class ] ) @TestPropertySource(locations = ["classpath:application-test.properties"]) diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt index 86ed0eab6..0a89c5782 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt @@ -16,6 +16,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api +import io.micrometer.core.instrument.MeterRegistry +import io.mockk.coVerify import io.mockk.Runs import io.mockk.coEvery import io.mockk.coVerify @@ -32,6 +34,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractService import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service import org.springframework.test.context.ContextConfiguration @@ -51,6 +54,9 @@ import kotlin.test.assertTrue @TestPropertySource(locations = ["classpath:application-test.properties"]) class ExecutionServiceHandlerTest { + @MockBean + lateinit var meterRegistry: MeterRegistry + @Autowired lateinit var applicationContext: ApplicationContext @@ -74,7 +80,7 @@ class ExecutionServiceHandlerTest { } } runBlocking { - val executionServiceHandler = ExecutionServiceHandler(mockk(), mockk(), mockk(), mockk()) + val executionServiceHandler = ExecutionServiceHandler(mockk(), mockk(), mockk(), mockk(), mockk(relaxed = true)) val isServiceFunction = executionServiceHandler.checkServiceFunction(executionServiceInput) assertTrue(isServiceFunction, "failed to checkServiceFunction") val executionServiceOutput = executionServiceHandler.executeServiceFunction(executionServiceInput) @@ -102,7 +108,8 @@ class ExecutionServiceHandlerTest { mockk(), mockk(), mockk(), - publishAuditService + publishAuditService, + mockk(relaxed = true) ) coEvery { publishAuditService.publishExecutionInput(ExecutionServiceInput()) } just Runs diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/UtilsTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/UtilsTest.kt index db2791101..223896885 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/UtilsTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/UtilsTest.kt @@ -1,8 +1,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils +import io.micrometer.core.instrument.Tag import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status +import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.SelfServiceMetricConstants import org.springframework.http.HttpStatus import org.springframework.test.context.junit4.SpringRunner @@ -23,4 +29,52 @@ class UtilsTest { val nonExistentHttpStatusCode = determineHttpStatusCode(999999) assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, nonExistentHttpStatusCode) } + + @Test + fun testCbaMetricExecutionInputTags() { + val executionServiceInput = ExecutionServiceInput().apply { + actionIdentifiers = ActionIdentifiers().apply { + blueprintName = "bpName" + blueprintVersion = "1.0.0" + actionName = "bpAction" + } + } + + val expectedTags = mutableListOf( + Tag.of(SelfServiceMetricConstants.TAG_BP_NAME, executionServiceInput.actionIdentifiers.blueprintName), + Tag.of(SelfServiceMetricConstants.TAG_BP_VERSION, executionServiceInput.actionIdentifiers.blueprintVersion), + Tag.of(SelfServiceMetricConstants.TAG_BP_ACTION, executionServiceInput.actionIdentifiers.actionName) + ) + + val metricTag = cbaMetricTags(executionServiceInput) + + assertEquals(expectedTags, metricTag) + } + + @Test + fun testCbaMetricExecutionOutputTags() { + val executionServiceOutput = ExecutionServiceOutput().apply { + actionIdentifiers = ActionIdentifiers().apply { + blueprintName = "bpName" + blueprintVersion = "1.0.0" + actionName = "bpAction" + } + status = Status().apply { + code = 200 + message = "success" + } + } + + val expectedTags = mutableListOf( + Tag.of(SelfServiceMetricConstants.TAG_BP_NAME, executionServiceOutput.actionIdentifiers.blueprintName), + Tag.of(SelfServiceMetricConstants.TAG_BP_VERSION, executionServiceOutput.actionIdentifiers.blueprintVersion), + Tag.of(SelfServiceMetricConstants.TAG_BP_ACTION, executionServiceOutput.actionIdentifiers.actionName), + Tag.of(SelfServiceMetricConstants.TAG_BP_STATUS, executionServiceOutput.status.code.toString()), + Tag.of(SelfServiceMetricConstants.TAG_BP_OUTCOME, executionServiceOutput.status.message) + ) + + val metricTag = cbaMetricTags(executionServiceOutput) + + assertEquals(expectedTags, metricTag) + } } -- cgit 1.2.3-korg