check all actual upstreams before call
This commit is contained in:
@@ -166,7 +166,8 @@ open class NativeCall(
|
||||
}
|
||||
|
||||
val matcher = Selector.convertToMatcher(request.selector)
|
||||
if (!configuredUpstreams.hasMatchingUpstream(chain, matcher)) {
|
||||
|
||||
if (!multistreamHolder.getUpstream(chain).hasMatchingUpstream(matcher)) {
|
||||
if (Global.metricsExtended) {
|
||||
Metrics.globalRegistry
|
||||
.counter("no_matching_upstream", "chain", chain.chainCode, "matcher", matcher.describeInternal())
|
||||
@@ -176,7 +177,6 @@ open class NativeCall(
|
||||
}
|
||||
|
||||
val upstream = multistreamHolder.getUpstream(chain)
|
||||
?: return Flux.error(CallFailure(0, SilentException.UnsupportedBlockchain(chain)))
|
||||
|
||||
return prepareCall(request, upstream)
|
||||
}
|
||||
|
||||
@@ -117,11 +117,6 @@ open class ConfiguredUpstreams(
|
||||
}
|
||||
}
|
||||
|
||||
fun hasMatchingUpstream(chain: Chain, matcher: Selector.LabelSelectorMatcher): Boolean =
|
||||
config.upstreams.any { up ->
|
||||
(up.chain?.let { Global.chainById(it) == chain } ?: true) && matcher.matches(up.labels)
|
||||
}
|
||||
|
||||
private fun buildDefaultOptions(config: UpstreamsConfig): HashMap<Chain, UpstreamsConfig.Options> {
|
||||
val defaultOptions = HashMap<Chain, UpstreamsConfig.Options>()
|
||||
config.defaultOptions.forEach { defaultsConfig ->
|
||||
|
||||
@@ -30,8 +30,8 @@ open class CurrentMultistreamHolder(
|
||||
|
||||
private val chainMapping = multistreams.associateBy { it.chain }
|
||||
|
||||
override fun getUpstream(chain: Chain): Multistream? {
|
||||
return chainMapping[chain]
|
||||
override fun getUpstream(chain: Chain): Multistream {
|
||||
return chainMapping.getValue(chain)
|
||||
}
|
||||
|
||||
override fun getAvailable(): List<Chain> {
|
||||
|
||||
@@ -352,6 +352,10 @@ abstract class Multistream(
|
||||
fun haveUpstreams(): Boolean =
|
||||
upstreams.isNotEmpty()
|
||||
|
||||
fun hasMatchingUpstream(matcher: Selector.LabelSelectorMatcher): Boolean {
|
||||
return upstreams.any { matcher.matches(it) }
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------
|
||||
|
||||
class UpstreamStatus(val upstream: Upstream, val status: UpstreamAvailability, val ts: Instant = Instant.now())
|
||||
|
||||
@@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.Chain
|
||||
* Holds Multistreams configured for a chain.
|
||||
*/
|
||||
interface MultistreamHolder {
|
||||
fun getUpstream(chain: Chain): Multistream?
|
||||
fun getUpstream(chain: Chain): Multistream
|
||||
fun getAvailable(): List<Chain>
|
||||
fun isAvailable(chain: Chain): Boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user