aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-main/src/test
diff options
context:
space:
mode:
authorPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2018-12-12 09:07:05 +0100
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2018-12-13 15:06:49 +0100
commit62fc38ca67632825f64965a7f70a9845de7ad35e (patch)
tree910f067c1e15f1b5826bd2a5da7ca5c2840d30da /sources/hv-collector-main/src/test
parentfb4914b7b200772f70e9a7b011d9b17c35df5bfc (diff)
Expose Prometheus metrics
Expose both JVM and HV-VES metrics by means of HealthCheckApiServer in Prometheus format. Change-Id: I81b74cd945c67569703a4a74f5a2683ede18d64a Issue-ID: DCAEGEN2-1029 Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'sources/hv-collector-main/src/test')
-rw-r--r--sources/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/MicrometerMetricsTest.kt59
1 files changed, 35 insertions, 24 deletions
diff --git a/sources/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/MicrometerMetricsTest.kt b/sources/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/MicrometerMetricsTest.kt
index a379933e..66326ddc 100644
--- a/sources/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/MicrometerMetricsTest.kt
+++ b/sources/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/MicrometerMetricsTest.kt
@@ -24,12 +24,17 @@ import io.micrometer.core.instrument.Counter
import io.micrometer.core.instrument.Gauge
import io.micrometer.core.instrument.search.RequiredSearch
import io.micrometer.core.instrument.simple.SimpleMeterRegistry
+import io.micrometer.prometheus.PrometheusConfig
+import io.micrometer.prometheus.PrometheusMeterRegistry
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.data.Percentage
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
+import org.onap.dcae.collectors.veshv.healthcheck.ports.PrometheusMetricsProvider
+import org.onap.dcae.collectors.veshv.main.metrics.MicrometerMetrics
+import org.onap.dcae.collectors.veshv.main.metrics.MicrometerMetrics.Companion.PREFIX
/**
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
@@ -37,11 +42,11 @@ import org.jetbrains.spek.api.dsl.on
*/
object MicrometerMetricsTest : Spek({
val doublePrecision = Percentage.withPercentage(0.5)
- lateinit var registry: SimpleMeterRegistry
+ lateinit var registry: PrometheusMeterRegistry
lateinit var cut: MicrometerMetrics
beforeEachTest {
- registry = SimpleMeterRegistry()
+ registry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT)
cut = MicrometerMetrics(registry)
}
@@ -67,14 +72,17 @@ object MicrometerMetricsTest : Spek({
fun verifyAllCountersAreUnchangedBut(vararg changedCounters: String) {
registry.meters
.filter { it is Counter }
+ .map { it as Counter }
.filterNot { it.id.name in changedCounters }
- .forEach { assertThat((it as Counter).count()).isCloseTo(0.0, doublePrecision) }
+ .forEach {
+ assertThat(it.count()).describedAs(it.id.toString()).isCloseTo(0.0, doublePrecision)
+ }
}
describe("notifyBytesReceived") {
- on("data.received.bytes counter") {
- val counterName = "data.received.bytes"
+ on("$PREFIX.data.received.bytes counter") {
+ val counterName = "$PREFIX.data.received.bytes"
it("should increment counter") {
val bytes = 128
@@ -93,8 +101,8 @@ object MicrometerMetricsTest : Spek({
}
describe("notifyMessageReceived") {
- on("messages.received.count counter") {
- val counterName = "messages.received.count"
+ on("$PREFIX.messages.received.count counter") {
+ val counterName = "$PREFIX.messages.received.count"
it("should increment counter") {
cut.notifyMessageReceived(777)
@@ -105,8 +113,8 @@ object MicrometerMetricsTest : Spek({
}
}
- on("messages.received.bytes counter") {
- val counterName = "messages.received.bytes"
+ on("$PREFIX.messages.received.bytes counter") {
+ val counterName = "$PREFIX.messages.received.bytes"
it("should increment counter") {
val bytes = 888
@@ -120,39 +128,42 @@ object MicrometerMetricsTest : Spek({
it("should leave all other counters unchanged") {
cut.notifyMessageReceived(128)
- verifyAllCountersAreUnchangedBut("messages.received.count", "messages.received.bytes")
+ verifyAllCountersAreUnchangedBut("$PREFIX.messages.received.count", "$PREFIX.messages.received.bytes")
}
}
describe("notifyMessageSent") {
- val topicName = "dmaap_topic_name"
- val counterName = "messages.sent.count"
+ val topicName1 = "PERF3GPP"
+ val topicName2 = "CALLTRACE"
- on("$counterName counter") {
+ on("$PREFIX.messages.sent.count counter") {
+ val counterName = "$PREFIX.messages.sent.count"
it("should increment counter") {
- cut.notifyMessageSent(topicName)
+ cut.notifyMessageSent(topicName1)
verifyCounter(counterName) { counter ->
assertThat(counter.count()).isCloseTo(1.0, doublePrecision)
}
+ verifyAllCountersAreUnchangedBut(counterName, "$PREFIX.messages.sent.topic.count")
}
}
- on("$counterName[topic=$topicName] counter") {
-
- it("should increment counter") {
- cut.notifyMessageSent(topicName)
+ on("$PREFIX.messages.sent.topic.count counter") {
+ val counterName = "$PREFIX.messages.sent.topic.count"
+ it("should handle counters for different topics") {
+ cut.notifyMessageSent(topicName1)
+ cut.notifyMessageSent(topicName2)
+ cut.notifyMessageSent(topicName2)
- verifyCounter(registrySearch().name(counterName).tag("topic", topicName)) { counter ->
+ verifyCounter(registrySearch().name(counterName).tag("topic", topicName1)) { counter ->
assertThat(counter.count()).isCloseTo(1.0, doublePrecision)
}
- }
- }
- it("should leave all other counters unchanged") {
- cut.notifyMessageSent(topicName)
- verifyAllCountersAreUnchangedBut(counterName)
+ verifyCounter(registrySearch().name(counterName).tag("topic", topicName2)) { counter ->
+ assertThat(counter.count()).isCloseTo(2.0, doublePrecision)
+ }
+ }
}
}