solution: monitoring and access log for Fee Estimation requests

This commit is contained in:
Igor Artamonov
2021-12-08 21:07:43 -05:00
parent c8d94b8748
commit bb61d42bc9
4 changed files with 82 additions and 1 deletions

View File

@@ -50,6 +50,7 @@ class AccessHandlerGrpc(
"NativeSubscribe" -> processNativeSubscribe(call, headers, next)
"Describe" -> processDescribe(call, headers, next)
"SubscribeStatus" -> processStatus(call, headers, next)
"EstimateFee" -> processEstimateFee(call, headers, next)
else -> {
log.warn("unsupported method `{}`", method)
next.startCall(call, headers)
@@ -158,6 +159,18 @@ class AccessHandlerGrpc(
)
}
@Suppress("UNCHECKED_CAST")
private fun <ReqT : Any, RespT : Any> processEstimateFee(
call: ServerCall<ReqT, RespT>,
headers: Metadata,
next: ServerCallHandler<ReqT, RespT>
): ServerCall.Listener<ReqT> {
return process(
call, headers, next,
EventsBuilder.EstimateFee() as EventsBuilder.RequestReply<*, ReqT, RespT>
)
}
open class StdCallListener<Req, EB : EventsBuilder.RequestReply<*, Req, *>>(
val next: ServerCall.Listener<Req>,
val builder: EB

View File

@@ -136,6 +136,14 @@ class Events {
val request: StreamRequestDetails
) : ChainBase(blockchain, "Status", id, Channel.GRPC)
@JsonInclude(JsonInclude.Include.NON_NULL)
class EstimateFee(
blockchain: Chain,
id: UUID,
val request: StreamRequestDetails,
val estimateFee: EstimateFeeDetails
) : ChainBase(blockchain, "EstimateFee", id, Channel.GRPC)
data class StreamRequestDetails(
val id: UUID,
val start: Instant,
@@ -180,4 +188,9 @@ class Events {
val asset: String,
val address: String
)
data class EstimateFeeDetails(
val mode: String,
val blocks: Int
)
}

View File

@@ -452,4 +452,34 @@ class EventsBuilder {
)
}
}
class EstimateFee :
Base<EstimateFee>(),
RequestReply<Events.EstimateFee, BlockchainOuterClass.EstimateFeeRequest, BlockchainOuterClass.EstimateFeeResponse> {
private var mode: String = "UNKNOWN"
private var blocks: Int = 0
override fun getT(): EstimateFee {
return this
}
override fun onRequest(msg: BlockchainOuterClass.EstimateFeeRequest) {
this.chain = Chain.byId(msg.chain.number)
this.mode = msg.mode.name
this.blocks = msg.blocks
}
override fun onReply(msg: BlockchainOuterClass.EstimateFeeResponse): Events.EstimateFee {
return Events.EstimateFee(
blockchain = chain,
request = requestDetails,
id = UUID.randomUUID(),
estimateFee = Events.EstimateFeeDetails(
mode = mode,
blocks = blocks
)
)
}
}
}

View File

@@ -167,7 +167,23 @@ class BlockchainRpc(
}
override fun estimateFee(request: Mono<BlockchainOuterClass.EstimateFeeRequest>): Mono<BlockchainOuterClass.EstimateFeeResponse> {
return request.flatMap { estimateFee.estimateFee(it) }
return request
.flatMap {
val chain = Chain.byId(it.chainValue)
val metrics = chainMetrics.get(chain)
metrics.estimateFeeMetric.increment()
val startTime = System.currentTimeMillis()
estimateFee.estimateFee(it).doFinally {
metrics.estimateFeeRespMetric.record(
System.currentTimeMillis() - startTime,
TimeUnit.MILLISECONDS
)
}
}
.doOnError { t ->
log.error("Internal error during Fee Estimation", t)
errorMetric.increment()
}
}
override fun describe(request: Mono<BlockchainOuterClass.DescribeRequest>): Mono<BlockchainOuterClass.DescribeResponse> {
@@ -229,5 +245,14 @@ class BlockchainRpc(
.tag("chain", chain.chainCode)
.publishPercentileHistogram()
.register(Metrics.globalRegistry)
val estimateFeeMetric = Counter.builder("request.grpc.request")
.tag("type", "estimateFee")
.tag("chain", chain.chainCode)
.register(Metrics.globalRegistry)
val estimateFeeRespMetric = Timer.builder("request.grpc.response")
.tag("type", "estimateFee")
.tag("chain", chain.chainCode)
.publishPercentileHistogram()
.register(Metrics.globalRegistry)
}
}