Set default lag value to null (#217)
This commit is contained in:
@@ -55,7 +55,7 @@ class NotLaggingQuorum(val maxLag: Long = 0) : CallQuorum {
|
|||||||
upstream: Upstream,
|
upstream: Upstream,
|
||||||
providedUpstreamId: String?
|
providedUpstreamId: String?
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val lagging = upstream.getLag() > maxLag
|
val lagging = upstream.getLag()?.run { this > maxLag } ?: true
|
||||||
if (!lagging) {
|
if (!lagging) {
|
||||||
result.set(response)
|
result.set(response)
|
||||||
sig = signature
|
sig = signature
|
||||||
@@ -72,7 +72,7 @@ class NotLaggingQuorum(val maxLag: Long = 0) : CallQuorum {
|
|||||||
upstream: Upstream
|
upstream: Upstream
|
||||||
) {
|
) {
|
||||||
this.rpcError = error.error
|
this.rpcError = error.error
|
||||||
val lagging = upstream.getLag() > maxLag
|
val lagging = upstream.getLag()?.run { this > maxLag } ?: true
|
||||||
if (!lagging && result.get() == null) {
|
if (!lagging && result.get() == null) {
|
||||||
failed.set(true)
|
failed.set(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import java.util.concurrent.atomic.AtomicReference
|
|||||||
abstract class DefaultUpstream(
|
abstract class DefaultUpstream(
|
||||||
private val id: String,
|
private val id: String,
|
||||||
private val hash: Byte,
|
private val hash: Byte,
|
||||||
defaultLag: Long,
|
defaultLag: Long?,
|
||||||
defaultAvail: UpstreamAvailability,
|
defaultAvail: UpstreamAvailability,
|
||||||
private val options: UpstreamsConfig.Options,
|
private val options: UpstreamsConfig.Options,
|
||||||
private val role: UpstreamsConfig.UpstreamRole,
|
private val role: UpstreamsConfig.UpstreamRole,
|
||||||
@@ -47,7 +47,7 @@ abstract class DefaultUpstream(
|
|||||||
node: QuorumForLabels.QuorumItem?,
|
node: QuorumForLabels.QuorumItem?,
|
||||||
chainConfig: ChainsConfig.ChainConfig
|
chainConfig: ChainsConfig.ChainConfig
|
||||||
) :
|
) :
|
||||||
this(id, hash, Long.MAX_VALUE, UpstreamAvailability.UNAVAILABLE, options, role, targets, node, chainConfig)
|
this(id, hash, null, UpstreamAvailability.UNAVAILABLE, options, role, targets, node, chainConfig)
|
||||||
|
|
||||||
protected val log = LoggerFactory.getLogger(this::class.java)
|
protected val log = LoggerFactory.getLogger(this::class.java)
|
||||||
|
|
||||||
@@ -97,12 +97,15 @@ abstract class DefaultUpstream(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun statusByLag(lag: Long, proposed: UpstreamAvailability): UpstreamAvailability {
|
private fun statusByLag(lag: Long?, proposed: UpstreamAvailability): UpstreamAvailability {
|
||||||
if (options.disableValidation) {
|
if (options.disableValidation) {
|
||||||
// if we specifically told that this upstream should be _always valid_ then skip
|
// if we specifically told that this upstream should be _always valid_ then skip
|
||||||
// the status calculation and trust the proposed value as is
|
// the status calculation and trust the proposed value as is
|
||||||
return proposed
|
return proposed
|
||||||
}
|
}
|
||||||
|
if (lag == null) {
|
||||||
|
return UpstreamAvailability.UNAVAILABLE
|
||||||
|
}
|
||||||
return if (proposed == UpstreamAvailability.OK) {
|
return if (proposed == UpstreamAvailability.OK) {
|
||||||
when {
|
when {
|
||||||
lag > chainConfig.syncingLagSize -> UpstreamAvailability.SYNCING
|
lag > chainConfig.syncingLagSize -> UpstreamAvailability.SYNCING
|
||||||
@@ -140,7 +143,7 @@ abstract class DefaultUpstream(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getLag(): Long {
|
override fun getLag(): Long? {
|
||||||
return this.status.get().lag
|
return this.status.get().lag
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +172,7 @@ abstract class DefaultUpstream(
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Status(val lag: Long, val avail: UpstreamAvailability, val status: UpstreamAvailability)
|
data class Status(val lag: Long?, val avail: UpstreamAvailability, val status: UpstreamAvailability)
|
||||||
|
|
||||||
private data class UpstreamChangeState(
|
private data class UpstreamChangeState(
|
||||||
val status: UpstreamAvailability,
|
val status: UpstreamAvailability,
|
||||||
|
|||||||
@@ -122,7 +122,9 @@ abstract class Multistream(
|
|||||||
removeUpstreamMeters(upstreamId)
|
removeUpstreamMeters(upstreamId)
|
||||||
|
|
||||||
meters[upstreamId] = listOf(
|
meters[upstreamId] = listOf(
|
||||||
Gauge.builder("$metrics.lag", upstream) { it.getLag().toDouble() }
|
Gauge.builder("$metrics.lag", upstream) {
|
||||||
|
it.getLag()?.toDouble() ?: Double.NaN
|
||||||
|
}
|
||||||
.tag("chain", chain.chainCode)
|
.tag("chain", chain.chainCode)
|
||||||
.tag("upstream", upstreamId)
|
.tag("upstream", upstreamId)
|
||||||
.register(Metrics.globalRegistry)
|
.register(Metrics.globalRegistry)
|
||||||
@@ -374,11 +376,7 @@ abstract class Multistream(
|
|||||||
// by default, when no lag is available it uses Long.MAX_VALUE, and it doesn't make sense to print
|
// by default, when no lag is available it uses Long.MAX_VALUE, and it doesn't make sense to print
|
||||||
// status with such value. use NA (as Not Available) instead
|
// status with such value. use NA (as Not Available) instead
|
||||||
val value = it.getLag()
|
val value = it.getLag()
|
||||||
if (value == Long.MAX_VALUE) {
|
value?.toString() ?: "NA"
|
||||||
"NA"
|
|
||||||
} else {
|
|
||||||
value.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val weak = upstreams.plus(removed.values)
|
val weak = upstreams.plus(removed.values)
|
||||||
.filter { it.getStatus() != UpstreamAvailability.OK }
|
.filter { it.getStatus() != UpstreamAvailability.OK }
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ interface Upstream {
|
|||||||
fun getOptions(): UpstreamsConfig.Options
|
fun getOptions(): UpstreamsConfig.Options
|
||||||
fun getRole(): UpstreamsConfig.UpstreamRole
|
fun getRole(): UpstreamsConfig.UpstreamRole
|
||||||
fun setLag(lag: Long)
|
fun setLag(lag: Long)
|
||||||
fun getLag(): Long
|
fun getLag(): Long?
|
||||||
fun getLabels(): Collection<UpstreamsConfig.Labels>
|
fun getLabels(): Collection<UpstreamsConfig.Labels>
|
||||||
fun getMethods(): CallMethods
|
fun getMethods(): CallMethods
|
||||||
fun getId(): String
|
fun getId(): String
|
||||||
|
|||||||
Reference in New Issue
Block a user