diff options
author | 2018-12-14 15:20:56 +0100 | |
---|---|---|
committer | 2018-12-17 13:18:13 +0100 | |
commit | 8952e9970470b683773bfe3a8f40a10881a3f321 (patch) | |
tree | fe31f2eeca7fafcb62ea48dbccc08ad02ec9a5a9 /sources/hv-collector-utils/src/main/kotlin/org/onap | |
parent | e32d91541ffa6c3ec13729032979af8160bdb8dc (diff) |
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 <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-1037
Diffstat (limited to 'sources/hv-collector-utils/src/main/kotlin/org/onap')
2 files changed, 12 insertions, 2 deletions
diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt index 7381592d..cb1c6222 100644 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt +++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt @@ -21,6 +21,7 @@ package org.onap.dcae.collectors.veshv.utils.arrow import arrow.core.Either import arrow.core.Option +import arrow.core.Try import arrow.core.identity import arrow.syntax.collections.firstOption import java.util.concurrent.atomic.AtomicReference @@ -45,3 +46,10 @@ fun <A> Option.Companion.fromNullablesChain(firstValue: A?, vararg nextValues: ( .map { it() } .filter { it != null } .firstOption() + + +fun <A, B> Either<A, B>.doOnLeft(action: () -> Unit): Either<A, B> = apply { if (isLeft()) action() } + +fun <A> Option<A>.doOnEmpty(action: () -> Unit): Option<A> = apply { if (isEmpty()) action() } + +fun <A> Try<A>.doOnFailure(action: () -> Unit): Try<A> = apply { if (isFailure()) action() } diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt index 95590d9d..e7aca55d 100644 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt +++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt @@ -25,6 +25,8 @@ import arrow.core.Try import reactor.core.publisher.Flux import reactor.core.publisher.Mono +typealias MessageEither = Either<() -> String, () -> String> + fun <T> Logger.handleReactiveStreamError( context: MappedDiagnosticContext, ex: Throwable, @@ -60,7 +62,7 @@ fun <T> Option<T>.filterEmptyWithLog(logger: Logger, fun <T> Flux<T>.filterFailedWithLog(logger: Logger, context: MappedDiagnosticContext, - predicate: (T) -> Either<() -> String, () -> String>) = + predicate: (T) -> MessageEither): Flux<T> = flatMap { t -> predicate(t).fold({ logger.warn(context, it) @@ -69,4 +71,4 @@ fun <T> Flux<T>.filterFailedWithLog(logger: Logger, logger.trace(context, it) Mono.just<T>(t) }) - } + }
\ No newline at end of file |