From 6fa6fa005511b52cc728a987546f2499a3e25800 Mon Sep 17 00:00:00 2001 From: Maksim Fomenkov Date: Fri, 16 Dec 2022 02:46:28 +0300 Subject: [PATCH 1/2] fix upstream lag metrics stuck --- .../dshackle/upstream/Multistream.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt index ffbd5d21..738e972a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt @@ -26,6 +26,8 @@ import io.emeraldpay.dshackle.upstream.calls.AggregatedCallMethods import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse +import io.micrometer.core.instrument.Gauge +import io.micrometer.core.instrument.Meter import io.micrometer.core.instrument.Metrics import io.micrometer.core.instrument.Tag import org.apache.commons.collections4.Factory @@ -73,6 +75,7 @@ abstract class Multistream( private var subscription: Disposable? = null private var capabilities: Set = emptySet() private val removed: MutableMap = HashMap() + private val meters: MutableMap = HashMap() init { UpstreamAvailability.values().forEach { status -> @@ -98,12 +101,17 @@ abstract class Multistream( } private fun monitorUpstream(upstream: Upstream) { - Metrics.gauge( - "$metrics.lag", - listOf(Tag.of("chain", chain.chainCode), Tag.of("upstream", upstream.getId())), upstream - ) { - it.getLag().toDouble() + val id = upstream.getId() + //remove gouge for given upstream if exists - otherwise metric will stuck with prev upstream instance + meters[id]?.let { + Metrics.globalRegistry.remove(it) } + + meters[id] = Gauge.builder("$metrics.lag", upstream) { it.getLag().toDouble() } + .tag("chain", chain.chainCode) + .tag("upstream", id) + .register(Metrics.globalRegistry) + .id } open fun init() { From 56760319e3269f4bfb83f212294fb466e4889e17 Mon Sep 17 00:00:00 2001 From: Maksim Fomenkov Date: Fri, 16 Dec 2022 03:04:58 +0300 Subject: [PATCH 2/2] code style --- src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt index 738e972a..81741a2f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt @@ -102,7 +102,7 @@ abstract class Multistream( private fun monitorUpstream(upstream: Upstream) { val id = upstream.getId() - //remove gouge for given upstream if exists - otherwise metric will stuck with prev upstream instance + // remove gouge for given upstream if exists - otherwise metric will stuck with prev upstream instance meters[id]?.let { Metrics.globalRegistry.remove(it) }