solution: monitoring and access log for Fee Estimation requests
This commit is contained in:
@@ -50,6 +50,7 @@ class AccessHandlerGrpc(
|
|||||||
"NativeSubscribe" -> processNativeSubscribe(call, headers, next)
|
"NativeSubscribe" -> processNativeSubscribe(call, headers, next)
|
||||||
"Describe" -> processDescribe(call, headers, next)
|
"Describe" -> processDescribe(call, headers, next)
|
||||||
"SubscribeStatus" -> processStatus(call, headers, next)
|
"SubscribeStatus" -> processStatus(call, headers, next)
|
||||||
|
"EstimateFee" -> processEstimateFee(call, headers, next)
|
||||||
else -> {
|
else -> {
|
||||||
log.warn("unsupported method `{}`", method)
|
log.warn("unsupported method `{}`", method)
|
||||||
next.startCall(call, headers)
|
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, *>>(
|
open class StdCallListener<Req, EB : EventsBuilder.RequestReply<*, Req, *>>(
|
||||||
val next: ServerCall.Listener<Req>,
|
val next: ServerCall.Listener<Req>,
|
||||||
val builder: EB
|
val builder: EB
|
||||||
|
|||||||
@@ -136,6 +136,14 @@ class Events {
|
|||||||
val request: StreamRequestDetails
|
val request: StreamRequestDetails
|
||||||
) : ChainBase(blockchain, "Status", id, Channel.GRPC)
|
) : 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(
|
data class StreamRequestDetails(
|
||||||
val id: UUID,
|
val id: UUID,
|
||||||
val start: Instant,
|
val start: Instant,
|
||||||
@@ -180,4 +188,9 @@ class Events {
|
|||||||
val asset: String,
|
val asset: String,
|
||||||
val address: String
|
val address: String
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class EstimateFeeDetails(
|
||||||
|
val mode: String,
|
||||||
|
val blocks: Int
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,23 @@ class BlockchainRpc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun estimateFee(request: Mono<BlockchainOuterClass.EstimateFeeRequest>): Mono<BlockchainOuterClass.EstimateFeeResponse> {
|
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> {
|
override fun describe(request: Mono<BlockchainOuterClass.DescribeRequest>): Mono<BlockchainOuterClass.DescribeResponse> {
|
||||||
@@ -229,5 +245,14 @@ class BlockchainRpc(
|
|||||||
.tag("chain", chain.chainCode)
|
.tag("chain", chain.chainCode)
|
||||||
.publishPercentileHistogram()
|
.publishPercentileHistogram()
|
||||||
.register(Metrics.globalRegistry)
|
.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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user