Add logs and tracer span for logsoracle (#392)
This commit is contained in:
@@ -74,6 +74,7 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory)
|
||||
cs.subscriptionBuilder(headScheduler),
|
||||
logsOracleConfig,
|
||||
logsOracleScheduler,
|
||||
tracer,
|
||||
).also { register(it, name) }
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.emeraldpay.dshackle.upstream
|
||||
|
||||
import io.emeraldpay.dshackle.config.IndexConfig
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.cloud.sleuth.Tracer
|
||||
import reactor.core.Disposable
|
||||
import reactor.core.publisher.Mono
|
||||
import reactor.core.scheduler.Scheduler
|
||||
@@ -10,6 +11,7 @@ class LogsOracle(
|
||||
private val config: IndexConfig.Index,
|
||||
private val upstream: Multistream,
|
||||
private val scheduler: Scheduler,
|
||||
private val tracer: Tracer,
|
||||
) {
|
||||
|
||||
private val log = LoggerFactory.getLogger(LogsOracle::class.java)
|
||||
@@ -18,7 +20,7 @@ class LogsOracle(
|
||||
private var conn: org.drpc.logsoracle.LogsOracle? = null
|
||||
|
||||
fun start() {
|
||||
log.info("liboracle starting")
|
||||
log.info("liboracle starting: store=${config.store}, ram=${config.ram_limit}")
|
||||
|
||||
conn = org.drpc.logsoracle.LogsOracle(config.store, config.ram_limit ?: 0L)
|
||||
subscription = upstream.getHead().getFlux()
|
||||
@@ -46,8 +48,11 @@ class LogsOracle(
|
||||
address: List<String>,
|
||||
topics: List<List<String>>,
|
||||
): Mono<String> {
|
||||
val requestSpan = tracer.currentSpan()
|
||||
|
||||
return Mono.fromCallable {
|
||||
log.info("query: from=$fromBlock, to=$toBlock")
|
||||
val span = tracer.nextSpan(requestSpan).name("emerald.blockchain/logsoracle").start()
|
||||
log.info("query: from=$fromBlock, to=$toBlock, limit=$limit")
|
||||
|
||||
try {
|
||||
val estimate = conn?.Query(limit, fromBlock, toBlock, address, topics)
|
||||
@@ -58,6 +63,8 @@ class LogsOracle(
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
} finally {
|
||||
span.end()
|
||||
}
|
||||
}
|
||||
.publishOn(scheduler)
|
||||
|
||||
@@ -183,7 +183,7 @@ class EthereumLocalReader(
|
||||
|
||||
val req = params[0] as LinkedHashMap<String, Any?>
|
||||
|
||||
val limit = try { req.get("limit") as Integer? } catch (_: IllegalArgumentException) {
|
||||
val limit = try { req.get("limit") as Int? } catch (_: IllegalArgumentException) {
|
||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'limit' parameter")
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ class EthereumLocalReader(
|
||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'address' parameter")
|
||||
}
|
||||
val topics: List<List<String>> = try {
|
||||
val tpcs = req.get("topics")?.let { it as List<Any> } ?: listOf<Any>()
|
||||
val tpcs = req.get("topics")?.let { it as List<Any?> } ?: listOf<Any?>()
|
||||
if (tpcs.size > 4) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
@@ -223,7 +223,7 @@ class EthereumLocalReader(
|
||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'topics' parameter")
|
||||
}
|
||||
|
||||
return logsOracle.estimate(limit?.toLong() ?: null, fromBlock, toBlock, address, topics)
|
||||
return logsOracle.estimate(limit?.toLong(), fromBlock, toBlock, address, topics)
|
||||
.map { it.toByteArray() to null }
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import io.emeraldpay.dshackle.upstream.Upstream
|
||||
import io.emeraldpay.dshackle.upstream.calls.CallSelector
|
||||
import io.emeraldpay.dshackle.upstream.forkchoice.PriorityForkChoice
|
||||
import io.emeraldpay.dshackle.upstream.grpc.GrpcUpstream
|
||||
import org.springframework.cloud.sleuth.Tracer
|
||||
import org.springframework.util.ConcurrentReferenceHashMap
|
||||
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType.WEAK
|
||||
import reactor.core.publisher.Flux
|
||||
@@ -57,6 +58,7 @@ open class GenericMultistream(
|
||||
private val subscriptionBuilder: SubscriptionBuilder,
|
||||
logsOracleConfig: IndexConfig.Index? = null,
|
||||
private val logsOracleScheduler: Scheduler,
|
||||
private val tracer: Tracer,
|
||||
) : Multistream(chain, caches, callSelector, multistreamEventsScheduler) {
|
||||
|
||||
private val cachingReader = cachingReaderBuilder(this, caches, getMethodsFactory())
|
||||
@@ -76,7 +78,7 @@ open class GenericMultistream(
|
||||
)
|
||||
|
||||
private val logsOracle: LogsOracle? = logsOracleConfig?.let {
|
||||
LogsOracle(logsOracleConfig, this, logsOracleScheduler)
|
||||
LogsOracle(logsOracleConfig, this, logsOracleScheduler, tracer)
|
||||
}
|
||||
|
||||
private var subscription: EgressSubscription = subscriptionBuilder(this)
|
||||
|
||||
Reference in New Issue
Block a user