fix upstream lag metrics stuck
This commit is contained in:
@@ -26,6 +26,8 @@ import io.emeraldpay.dshackle.upstream.calls.AggregatedCallMethods
|
|||||||
import io.emeraldpay.dshackle.upstream.calls.CallMethods
|
import io.emeraldpay.dshackle.upstream.calls.CallMethods
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
|
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.Metrics
|
||||||
import io.micrometer.core.instrument.Tag
|
import io.micrometer.core.instrument.Tag
|
||||||
import org.apache.commons.collections4.Factory
|
import org.apache.commons.collections4.Factory
|
||||||
@@ -73,6 +75,7 @@ abstract class Multistream(
|
|||||||
private var subscription: Disposable? = null
|
private var subscription: Disposable? = null
|
||||||
private var capabilities: Set<Capability> = emptySet()
|
private var capabilities: Set<Capability> = emptySet()
|
||||||
private val removed: MutableMap<String, Upstream> = HashMap()
|
private val removed: MutableMap<String, Upstream> = HashMap()
|
||||||
|
private val meters: MutableMap<String, Meter.Id> = HashMap()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
UpstreamAvailability.values().forEach { status ->
|
UpstreamAvailability.values().forEach { status ->
|
||||||
@@ -98,12 +101,17 @@ abstract class Multistream(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun monitorUpstream(upstream: Upstream) {
|
private fun monitorUpstream(upstream: Upstream) {
|
||||||
Metrics.gauge(
|
val id = upstream.getId()
|
||||||
"$metrics.lag",
|
//remove gouge for given upstream if exists - otherwise metric will stuck with prev upstream instance
|
||||||
listOf(Tag.of("chain", chain.chainCode), Tag.of("upstream", upstream.getId())), upstream
|
meters[id]?.let {
|
||||||
) {
|
Metrics.globalRegistry.remove(it)
|
||||||
it.getLag().toDouble()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meters[id] = Gauge.builder("$metrics.lag", upstream) { it.getLag().toDouble() }
|
||||||
|
.tag("chain", chain.chainCode)
|
||||||
|
.tag("upstream", id)
|
||||||
|
.register(Metrics.globalRegistry)
|
||||||
|
.id
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun init() {
|
open fun init() {
|
||||||
|
|||||||
Reference in New Issue
Block a user