From 1e8c4e1ab11bcbff824c5fd7dbe99091b264b454 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Wed, 25 Jan 2023 13:25:47 +0400 Subject: [PATCH] Change Status class to data class for better logging Log every node status change in blockchain rpc --- .../kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt | 7 ++++++- .../io/emeraldpay/dshackle/upstream/DefaultUpstream.kt | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt index ac3143e9..76b43fb1 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt @@ -25,6 +25,7 @@ import io.emeraldpay.dshackle.SilentException import io.micrometer.core.instrument.Counter import io.micrometer.core.instrument.Metrics import io.micrometer.core.instrument.Timer +import org.apache.commons.lang3.RandomStringUtils import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Qualifier import org.springframework.context.annotation.DependsOn @@ -222,7 +223,11 @@ class BlockchainRpc( } override fun subscribeNodeStatus(request: Mono): Flux { - return subscribeNodeStatus.subscribe(request).subscribeOn(scheduler).doOnError { failMetric.increment() } + val subId = RandomStringUtils.randomAlphanumeric(8) + log.debug("Subscription for node status with id [$subId] created") + return subscribeNodeStatus.subscribe(request).subscribeOn(scheduler) + .doOnError { failMetric.increment() } + .doOnNext { log.debug("Emitted next node status to [$subId] with data [$it] ") } } class RequestMetrics(val chain: Chain) { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/DefaultUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/DefaultUpstream.kt index 11f3b65c..3b52ecb7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/DefaultUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/DefaultUpstream.kt @@ -163,5 +163,5 @@ abstract class DefaultUpstream( return quorumByLabel } - class Status(val lag: Long, val avail: UpstreamAvailability, val status: UpstreamAvailability) + data class Status(val lag: Long, val avail: UpstreamAvailability, val status: UpstreamAvailability) }