From de13d783a07dbe7f64d377256be465486c65309b Mon Sep 17 00:00:00 2001 From: Julien Fontaine Date: Fri, 5 Feb 2021 14:18:06 -0500 Subject: Added Kafka metrics for CDS workers Added counters to gather metrics on CDS Kafka workers. This will enable us to get metrics on how many messages we consumer and produce to/from kafka. For consumers we count how many messages we consume and how many failed ie. consumed but not able to be processed (parsing error). For producers we count how many messages we produce and how many failed ie. failed to be pushed to the cluster (unavailable brokers, network error, ...). Relocated metrics tag constants to BlueprintConstants so that they can be use by any CDS module. If they make sense for other metrics then they should be shared. Issue-ID: CCSDK-3155 Signed-off-by: Julien Fontaine Change-Id: Iad6aba588766f655f3a74cd626e0f74e29188f96 --- .../api/BlueprintProcessingKafkaConsumer.kt | 16 +++- .../selfservice/api/SelfServiceMetricConstants.kt | 23 ++++-- .../api/utils/BlueprintProcessingUtils.kt | 86 +++++++++++++++++++ .../selfservice/api/utils/Utils.kt | 86 ------------------- .../api/BlueprintProcessingKafkaConsumerTest.kt | 4 +- .../api/utils/BlueprintProcessingUtilsTest.kt | 96 ++++++++++++++++++++++ .../selfservice/api/utils/UtilsTest.kt | 80 ------------------ 7 files changed, 213 insertions(+), 178 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BlueprintProcessingUtils.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BlueprintProcessingUtilsTest.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/UtilsTest.kt (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src') diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BlueprintProcessingKafkaConsumer.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BlueprintProcessingKafkaConsumer.kt index 0ab38c6bd..661e76b2b 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BlueprintProcessingKafkaConsumer.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BlueprintProcessingKafkaConsumer.kt @@ -17,13 +17,16 @@ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api +import io.micrometer.core.instrument.MeterRegistry import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.consumeEach import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.message.BlueprintMessageMetricConstants import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BlueprintMessageLibPropertyService import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BlueprintMessageConsumerService +import org.onap.ccsdk.cds.blueprintsprocessor.message.utils.BlueprintMessageUtils import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsType import org.onap.ccsdk.cds.controllerblueprints.core.logger @@ -43,8 +46,9 @@ import javax.annotation.PreDestroy ) @Service open class BlueprintProcessingKafkaConsumer( - private val bluePrintMessageLibPropertyService: BlueprintMessageLibPropertyService, - private val executionServiceHandler: ExecutionServiceHandler + private val blueprintMessageLibPropertyService: BlueprintMessageLibPropertyService, + private val executionServiceHandler: ExecutionServiceHandler, + private val meterRegistry: MeterRegistry ) { val log = logger(BlueprintProcessingKafkaConsumer::class) @@ -69,7 +73,7 @@ open class BlueprintProcessingKafkaConsumer( /** Get the Message Consumer Service **/ blueprintMessageConsumerService = try { - bluePrintMessageLibPropertyService + blueprintMessageLibPropertyService .blueprintMessageConsumerService(CONSUMER_SELECTOR) } catch (e: BlueprintProcessorException) { val errorMsg = "Failed creating Kafka consumer message service." @@ -83,7 +87,7 @@ open class BlueprintProcessingKafkaConsumer( /** Get the Message Producer Service **/ val blueprintMessageProducerService = try { - bluePrintMessageLibPropertyService + blueprintMessageLibPropertyService .blueprintMessageProducerService(PRODUCER_SELECTOR) } catch (e: BlueprintProcessorException) { val errorMsg = "Failed creating Kafka producer message service." @@ -117,6 +121,10 @@ open class BlueprintProcessingKafkaConsumer( val executionServiceOutput = executionServiceHandler.doProcess(executionServiceInput) blueprintMessageProducerService.sendMessage(key, executionServiceOutput) } catch (e: Exception) { + meterRegistry.counter( + BlueprintMessageMetricConstants.KAFKA_CONSUMED_MESSAGES_ERROR_COUNTER, + BlueprintMessageUtils.kafkaMetricTag(message.topic()) + ).increment() log.error("failed in processing the consumed message : $message", e) } finally { ph.arriveAndDeregister() 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 index 97c73243d..7c8f4ed5a 100644 --- 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 @@ -1,3 +1,19 @@ +/* + * Copyright © 2021 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api object SelfServiceMetricConstants { @@ -6,13 +22,6 @@ object SelfServiceMetricConstants { 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" diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BlueprintProcessingUtils.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BlueprintProcessingUtils.kt new file mode 100644 index 000000000..c04410a2f --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BlueprintProcessingUtils.kt @@ -0,0 +1,86 @@ +/* + * Copyright © 2021 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException +import org.springframework.http.HttpStatus +import org.springframework.http.codec.multipart.FilePart +import org.springframework.util.StringUtils +import java.io.File +import java.io.IOException +import java.nio.file.Path +import java.util.UUID + +const val INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE = 500 + +@Throws(BlueprintException::class, IOException::class) +fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Path { + + val fileName = StringUtils.cleanPath(filePart.filename()) + + if (StringUtils.getFilenameExtension(fileName) != "zip") { + throw BlueprintException("Invalid file extension required ZIP") + } + + val changedFileName = UUID.randomUUID().toString() + ".zip" + + val targetLocation = targetDirectory.resolve(changedFileName) + + val file = File(targetLocation.toString()) + if (file.exists()) { + file.delete() + } + file.createNewFile() + + filePart.transferTo(file) + + return targetLocation +} + +fun determineHttpStatusCode(statusCode: Int): HttpStatus { + + try { + return HttpStatus.valueOf(statusCode) + } catch (exception: Exception) { + // if statusCode cannot be converted to a proper HttpStatus, the resource still needs to assign a HTTP status + // code to the response. In this case, a 500 Internal Server Error will be returned as default. + return HttpStatus.valueOf(INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE) + } +} + +fun cbaMetricTags(executionServiceInput: ExecutionServiceInput): MutableList = + executionServiceInput.actionIdentifiers.let { + mutableListOf( + Tag.of(BlueprintConstants.METRIC_TAG_BP_NAME, it.blueprintName), + Tag.of(BlueprintConstants.METRIC_TAG_BP_VERSION, it.blueprintVersion), + Tag.of(BlueprintConstants.METRIC_TAG_BP_ACTION, it.actionName) + ) + } + +fun cbaMetricTags(executionServiceOutput: ExecutionServiceOutput): MutableList = + executionServiceOutput.let { + mutableListOf( + Tag.of(BlueprintConstants.METRIC_TAG_BP_NAME, it.actionIdentifiers.blueprintName), + Tag.of(BlueprintConstants.METRIC_TAG_BP_VERSION, it.actionIdentifiers.blueprintVersion), + Tag.of(BlueprintConstants.METRIC_TAG_BP_ACTION, it.actionIdentifiers.actionName), + Tag.of(BlueprintConstants.METRIC_TAG_BP_STATUS, it.status.code.toString()), + Tag.of(BlueprintConstants.METRIC_TAG_BP_OUTCOME, it.status.message) + ) + } 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 deleted file mode 100644 index aa2938379..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 -import org.springframework.util.StringUtils -import java.io.File -import java.io.IOException -import java.nio.file.Path -import java.util.UUID - -const val INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE = 500 - -@Throws(BlueprintException::class, IOException::class) -fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Path { - - val fileName = StringUtils.cleanPath(filePart.filename()) - - if (StringUtils.getFilenameExtension(fileName) != "zip") { - throw BlueprintException("Invalid file extension required ZIP") - } - - val changedFileName = UUID.randomUUID().toString() + ".zip" - - val targetLocation = targetDirectory.resolve(changedFileName) - - val file = File(targetLocation.toString()) - if (file.exists()) { - file.delete() - } - file.createNewFile() - - filePart.transferTo(file) - - return targetLocation -} - -fun determineHttpStatusCode(statusCode: Int): HttpStatus { - - try { - return HttpStatus.valueOf(statusCode) - } catch (exception: Exception) { - // if statusCode cannot be converted to a proper HttpStatus, the resource still needs to assign a HTTP status - // code to the response. In this case, a 500 Internal Server Error will be returned as default. - 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/BlueprintProcessingKafkaConsumerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BlueprintProcessingKafkaConsumerTest.kt index 3a5cebc61..56cc691a4 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 @@ -1,5 +1,6 @@ /* * Copyright © 2019 IBM. + * Modifications Copyright © 2021 Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,7 +66,8 @@ class BlueprintProcessingKafkaConsumerTest { val bluePrintProcessingKafkaConsumer = BlueprintProcessingKafkaConsumer( bluePrintMessageLibPropertyService, - executionServiceHandle + executionServiceHandle, + meterRegistry ) launch { diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BlueprintProcessingUtilsTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BlueprintProcessingUtilsTest.kt new file mode 100644 index 000000000..10db349e6 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BlueprintProcessingUtilsTest.kt @@ -0,0 +1,96 @@ +/* + * Copyright © 2021 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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.controllerblueprints.core.BlueprintConstants +import org.springframework.http.HttpStatus +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +class BlueprintProcessingUtilsTest { + + @Test + fun `valid Http status codes should be produced for valid parameters`() { + val httpStatusCode200 = determineHttpStatusCode(200) + assertEquals(HttpStatus.OK, httpStatusCode200) + + val httpStatusCode500 = determineHttpStatusCode(500) + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpStatusCode500) + } + + @Test + fun `Http status code 500 should be produced for any invalid parameter`() { + 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(BlueprintConstants.METRIC_TAG_BP_NAME, executionServiceInput.actionIdentifiers.blueprintName), + Tag.of(BlueprintConstants.METRIC_TAG_BP_VERSION, executionServiceInput.actionIdentifiers.blueprintVersion), + Tag.of(BlueprintConstants.METRIC_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(BlueprintConstants.METRIC_TAG_BP_NAME, executionServiceOutput.actionIdentifiers.blueprintName), + Tag.of(BlueprintConstants.METRIC_TAG_BP_VERSION, executionServiceOutput.actionIdentifiers.blueprintVersion), + Tag.of(BlueprintConstants.METRIC_TAG_BP_ACTION, executionServiceOutput.actionIdentifiers.actionName), + Tag.of(BlueprintConstants.METRIC_TAG_BP_STATUS, executionServiceOutput.status.code.toString()), + Tag.of(BlueprintConstants.METRIC_TAG_BP_OUTCOME, executionServiceOutput.status.message) + ) + + val metricTag = cbaMetricTags(executionServiceOutput) + + assertEquals(expectedTags, metricTag) + } +} 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 deleted file mode 100644 index 223896885..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/UtilsTest.kt +++ /dev/null @@ -1,80 +0,0 @@ -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 - -@RunWith(SpringRunner::class) -class UtilsTest { - - @Test - fun `valid Http status codes should be produced for valid parameters`() { - val httpStatusCode200 = determineHttpStatusCode(200) - assertEquals(HttpStatus.OK, httpStatusCode200) - - val httpStatusCode500 = determineHttpStatusCode(500) - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpStatusCode500) - } - - @Test - fun `Http status code 500 should be produced for any invalid parameter`() { - 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