From 8952e9970470b683773bfe3a8f40a10881a3f321 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Fri, 14 Dec 2018 15:20:56 +0100 Subject: Add metrics for dropped messages Add counters for messages dropped due to validation or undefined routing Slight refactoring Change-Id: Ibe4e38445e81babc745d7a7d95356910845293ce Signed-off-by: Jakub Dudycz Issue-ID: DCAEGEN2-1037 --- .../dcae/collectors/veshv/boundary/adapters.kt | 2 ++ .../dcae/collectors/veshv/impl/VesHvCollector.kt | 23 ++++++++++++++--- .../collectors/veshv/model/MessageDropCause.kt | 29 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/model/MessageDropCause.kt (limited to 'sources/hv-collector-core/src/main/kotlin') diff --git a/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/boundary/adapters.kt b/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/boundary/adapters.kt index b686b250..3f69c088 100644 --- a/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/boundary/adapters.kt +++ b/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/boundary/adapters.kt @@ -21,6 +21,7 @@ package org.onap.dcae.collectors.veshv.boundary import org.onap.dcae.collectors.veshv.model.ClientContext import org.onap.dcae.collectors.veshv.model.CollectorConfiguration +import org.onap.dcae.collectors.veshv.model.MessageDropCause import org.onap.dcae.collectors.veshv.model.RoutedMessage import reactor.core.publisher.Flux @@ -32,6 +33,7 @@ interface Metrics { fun notifyBytesReceived(size: Int) fun notifyMessageReceived(size: Int) fun notifyMessageSent(topic: String) + fun notifyMessageDropped(cause: MessageDropCause) } @FunctionalInterface diff --git a/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/VesHvCollector.kt b/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/VesHvCollector.kt index ca1605e6..b29432f0 100644 --- a/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/VesHvCollector.kt +++ b/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/VesHvCollector.kt @@ -19,7 +19,6 @@ */ package org.onap.dcae.collectors.veshv.impl -import arrow.core.Either import io.netty.buffer.ByteBuf import org.onap.dcae.collectors.veshv.boundary.Collector import org.onap.dcae.collectors.veshv.boundary.Metrics @@ -29,9 +28,15 @@ import org.onap.dcae.collectors.veshv.domain.WireFrameMessage import org.onap.dcae.collectors.veshv.impl.adapters.ClientContextLogging.handleReactiveStreamError import org.onap.dcae.collectors.veshv.impl.wire.WireChunkDecoder import org.onap.dcae.collectors.veshv.model.ClientContext +import org.onap.dcae.collectors.veshv.model.MessageDropCause.INVALID_MESSAGE +import org.onap.dcae.collectors.veshv.model.MessageDropCause.ROUTE_NOT_FOUND import org.onap.dcae.collectors.veshv.model.RoutedMessage import org.onap.dcae.collectors.veshv.model.VesMessage +import org.onap.dcae.collectors.veshv.utils.arrow.doOnEmpty +import org.onap.dcae.collectors.veshv.utils.arrow.doOnFailure +import org.onap.dcae.collectors.veshv.utils.arrow.doOnLeft import org.onap.dcae.collectors.veshv.utils.logging.Logger +import org.onap.dcae.collectors.veshv.utils.logging.MessageEither import org.onap.dcae.collectors.veshv.utils.logging.filterEmptyWithLog import org.onap.dcae.collectors.veshv.utils.logging.filterFailedWithLog import reactor.core.publisher.Flux @@ -66,7 +71,11 @@ internal class VesHvCollector( .doOnNext { metrics.notifyMessageReceived(it.payloadSize) } private fun filterInvalidWireFrame(flux: Flux): Flux = flux - .filterFailedWithLog(MessageValidator::validateFrameMessage) + .filterFailedWithLog { + MessageValidator + .validateFrameMessage(it) + .doOnLeft { metrics.notifyMessageDropped(INVALID_MESSAGE) } + } private fun decodeProtobufPayload(flux: Flux): Flux = flux .map(WireFrameMessage::payload) @@ -74,12 +83,17 @@ internal class VesHvCollector( private fun decodePayload(rawPayload: ByteData): Flux = protobufDecoder .decode(rawPayload) + .doOnFailure { metrics.notifyMessageDropped(INVALID_MESSAGE) } .filterFailedWithLog(logger, clientContext::fullMdc, { "Ves event header decoded successfully" }, { "Failed to decode ves event header, reason: ${it.message}" }) private fun filterInvalidProtobufMessages(flux: Flux): Flux = flux - .filterFailedWithLog(MessageValidator::validateProtobufMessage) + .filterFailedWithLog { + MessageValidator + .validateProtobufMessage(it) + .doOnLeft { metrics.notifyMessageDropped(INVALID_MESSAGE) } + } private fun routeMessage(flux: Flux): Flux = flux .flatMap(this::findRoute) @@ -88,6 +102,7 @@ internal class VesHvCollector( private fun findRoute(msg: VesMessage) = router .findDestination(msg) + .doOnEmpty { metrics.notifyMessageDropped(ROUTE_NOT_FOUND) } .filterEmptyWithLog(logger, clientContext::fullMdc, { "Found route for message: ${it.topic}, partition: ${it.partition}" }, { "Could not find route for message" }) @@ -95,7 +110,7 @@ internal class VesHvCollector( private fun releaseBuffersMemory() = wireChunkDecoder.release() .also { logger.debug { "Released buffer memory after handling message stream" } } - fun Flux.filterFailedWithLog(predicate: (T) -> Either<() -> String, () -> String>) = + private fun Flux.filterFailedWithLog(predicate: (T) -> MessageEither): Flux = filterFailedWithLog(logger, clientContext::fullMdc, predicate) companion object { diff --git a/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/model/MessageDropCause.kt b/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/model/MessageDropCause.kt new file mode 100644 index 00000000..af43ae67 --- /dev/null +++ b/sources/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/model/MessageDropCause.kt @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018 NOKIA + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.model + +/** + * @author Jakub Dudycz + * @since December 2018 + */ +enum class MessageDropCause(val tag: String) { + ROUTE_NOT_FOUND("routing"), + INVALID_MESSAGE("invalid") +} -- cgit 1.2.3-korg