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,
|
||||
providedUpstreamId: String?
|
||||
): Boolean {
|
||||
val lagging = upstream.getLag() > maxLag
|
||||
val lagging = upstream.getLag()?.run { this > maxLag } ?: true
|
||||
if (!lagging) {
|
||||
result.set(response)
|
||||
sig = signature
|
||||
@@ -72,7 +72,7 @@ class NotLaggingQuorum(val maxLag: Long = 0) : CallQuorum {
|
||||
upstream: Upstream
|
||||
) {
|
||||
this.rpcError = error.error
|
||||
val lagging = upstream.getLag() > maxLag
|
||||
val lagging = upstream.getLag()?.run { this > maxLag } ?: true
|
||||
if (!lagging && result.get() == null) {
|
||||
failed.set(true)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.concurrent.atomic.AtomicReference
|
||||
abstract class DefaultUpstream(
|
||||
private val id: String,
|
||||
private val hash: Byte,
|
||||
defaultLag: Long,
|
||||
defaultLag: Long?,
|
||||
defaultAvail: UpstreamAvailability,
|
||||
private val options: UpstreamsConfig.Options,
|
||||
private val role: UpstreamsConfig.UpstreamRole,
|
||||
@@ -47,7 +47,7 @@ abstract class DefaultUpstream(
|
||||
node: QuorumForLabels.QuorumItem?,
|
||||
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)
|
||||
|
||||
@@ -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 we specifically told that this upstream should be _always valid_ then skip
|
||||
// the status calculation and trust the proposed value as is
|
||||
return proposed
|
||||
}
|
||||
if (lag == null) {
|
||||
return UpstreamAvailability.UNAVAILABLE
|
||||
}
|
||||
return if (proposed == UpstreamAvailability.OK) {
|
||||
when {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -169,7 +172,7 @@ abstract class DefaultUpstream(
|
||||
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(
|
||||
val status: UpstreamAvailability,
|
||||
|
||||
@@ -122,7 +122,9 @@ abstract class Multistream(
|
||||
removeUpstreamMeters(upstreamId)
|
||||
|
||||
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("upstream", upstreamId)
|
||||
.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
|
||||
// status with such value. use NA (as Not Available) instead
|
||||
val value = it.getLag()
|
||||
if (value == Long.MAX_VALUE) {
|
||||
"NA"
|
||||
} else {
|
||||
value.toString()
|
||||
}
|
||||
value?.toString() ?: "NA"
|
||||
}
|
||||
val weak = upstreams.plus(removed.values)
|
||||
.filter { it.getStatus() != UpstreamAvailability.OK }
|
||||
|
||||
@@ -35,7 +35,7 @@ interface Upstream {
|
||||
fun getOptions(): UpstreamsConfig.Options
|
||||
fun getRole(): UpstreamsConfig.UpstreamRole
|
||||
fun setLag(lag: Long)
|
||||
fun getLag(): Long
|
||||
fun getLag(): Long?
|
||||
fun getLabels(): Collection<UpstreamsConfig.Labels>
|
||||
fun getMethods(): CallMethods
|
||||
fun getId(): String
|
||||
|
||||
Reference in New Issue
Block a user