2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.tests.component
22 import com.google.protobuf.ByteString
23 import org.assertj.core.api.Assertions.assertThat
24 import org.jetbrains.spek.api.Spek
25 import org.jetbrains.spek.api.dsl.describe
26 import org.jetbrains.spek.api.dsl.it
27 import org.onap.dcae.collectors.veshv.domain.VesEventDomain
28 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.HEARTBEAT
29 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.PERF3GPP
30 import org.onap.dcae.collectors.veshv.model.MessageDropCause.INVALID_MESSAGE
31 import org.onap.dcae.collectors.veshv.model.MessageDropCause.ROUTE_NOT_FOUND
32 import org.onap.dcae.collectors.veshv.tests.fakes.MEASUREMENTS_FOR_VF_SCALING_TOPIC
33 import org.onap.dcae.collectors.veshv.tests.fakes.PERF3GPP_TOPIC
34 import org.onap.dcae.collectors.veshv.tests.fakes.basicConfiguration
35 import org.onap.dcae.collectors.veshv.tests.fakes.twoDomainsToOneTopicConfiguration
36 import org.onap.dcae.collectors.veshv.tests.utils.messageWithInvalidListenerVersion
37 import org.onap.dcae.collectors.veshv.tests.utils.messageWithInvalidWireFrameHeader
38 import org.onap.dcae.collectors.veshv.tests.utils.vesEvent
39 import org.onap.dcae.collectors.veshv.tests.utils.vesWireFrameMessage
40 import org.onap.dcae.collectors.veshv.tests.utils.wireFrameMessageWithInvalidPayload
41 import java.time.Duration
43 object MetricsSpecification : Spek({
46 describe("Bytes received metrics") {
47 it("should sum up all bytes received") {
48 val sut = vesHvWithNoOpSink()
49 val vesWireFrameMessage = vesWireFrameMessage()
50 val invalidWireFrame = messageWithInvalidWireFrameHeader()
52 val bytesSent = invalidWireFrame.readableBytes() +
53 vesWireFrameMessage.readableBytes()
59 val metrics = sut.metrics
60 assertThat(metrics.bytesReceived)
61 .describedAs("bytesReceived metric")
66 describe("Messages received metrics") {
67 it("should sum up all received messages bytes") {
68 val sut = vesHvWithNoOpSink()
69 val firstVesEvent = vesEvent(eventFields = ByteString.copyFrom(ByteArray(10)))
70 val secondVesEvent = vesEvent(eventFields = ByteString.copyFrom(ByteArray(40)))
71 val firstVesMessage = vesWireFrameMessage(firstVesEvent)
72 val secondVesMessage = vesWireFrameMessage(secondVesEvent)
74 val serializedMessagesSize = firstVesEvent.serializedSize + secondVesEvent.serializedSize
80 val metrics = sut.metrics
81 assertThat(metrics.messageBytesReceived)
82 .describedAs("messageBytesReceived metric")
83 .isEqualTo(serializedMessagesSize)
87 describe("Messages sent metrics") {
88 it("should gather info for each topic separately") {
89 val sut = vesHvWithNoOpSink(twoDomainsToOneTopicConfiguration)
92 vesWireFrameMessage(PERF3GPP),
93 vesWireFrameMessage(PERF3GPP),
94 vesWireFrameMessage(VesEventDomain.MEASUREMENT)
97 val metrics = sut.metrics
98 assertThat(metrics.messagesSentCount)
99 .describedAs("messagesSentCount metric")
101 assertThat(metrics.messagesOnTopic(PERF3GPP_TOPIC))
102 .describedAs("messagesSentToTopic $PERF3GPP_TOPIC metric")
104 assertThat(metrics.messagesOnTopic(MEASUREMENTS_FOR_VF_SCALING_TOPIC))
105 .describedAs("messagesSentToTopic $MEASUREMENTS_FOR_VF_SCALING_TOPIC metric")
110 describe("Processing time") {
111 it("should gather processing time metric") {
112 val delay = Duration.ofMillis(10)
113 val sut = vesHvWithDelayingSink(delay)
115 sut.handleConnection(vesWireFrameMessage(PERF3GPP))
118 val metrics = sut.metrics
119 assertThat(metrics.lastProcessingTimeMicros)
120 .describedAs("processingTime metric")
121 .isGreaterThanOrEqualTo(delay.toNanos().toDouble() / 1000.0)
125 describe("Messages dropped metrics") {
126 it("should gather metrics for invalid messages") {
127 val sut = vesHvWithNoOpSink(basicConfiguration)
129 sut.handleConnection(
130 messageWithInvalidWireFrameHeader(),
131 wireFrameMessageWithInvalidPayload(),
132 vesWireFrameMessage(domain = PERF3GPP),
133 messageWithInvalidListenerVersion()
136 val metrics = sut.metrics
137 assertThat(metrics.messagesDropped(INVALID_MESSAGE))
138 .describedAs("messagesDroppedCause $INVALID_MESSAGE metric")
142 it("should gather metrics for route not found") {
143 val sut = vesHvWithNoOpSink(basicConfiguration)
145 sut.handleConnection(
146 vesWireFrameMessage(domain = PERF3GPP),
147 vesWireFrameMessage(domain = HEARTBEAT)
150 val metrics = sut.metrics
151 assertThat(metrics.messagesDropped(ROUTE_NOT_FOUND))
152 .describedAs("messagesDroppedCause $ROUTE_NOT_FOUND metric")
156 it("should gather summed metrics for dropped messages"){
157 val sut = vesHvWithNoOpSink(basicConfiguration)
159 sut.handleConnection(
160 vesWireFrameMessage(domain = PERF3GPP),
161 vesWireFrameMessage(domain = HEARTBEAT),
162 wireFrameMessageWithInvalidPayload()
165 val metrics = sut.metrics
166 assertThat(metrics.messagesDroppedCount)
167 .describedAs("messagesDroppedCount metric")