add latency to access log
This commit is contained in:
@@ -25,6 +25,7 @@ import io.grpc.ServerInterceptor
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Service
|
||||
import java.time.Instant
|
||||
|
||||
@Service
|
||||
class AccessHandlerGrpc(
|
||||
@@ -119,7 +120,7 @@ class AccessHandlerGrpc(
|
||||
): ServerCall.Listener<ReqT> {
|
||||
return process(
|
||||
call, headers, next,
|
||||
EventsBuilder.NativeCall() as EventsBuilder.RequestReply<*, ReqT, RespT>
|
||||
EventsBuilder.NativeCall(Instant.now()) as EventsBuilder.RequestReply<*, ReqT, RespT>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -127,11 +127,13 @@ class AccessHandlerHttp(
|
||||
private val accessLogWriter: AccessLogWriter,
|
||||
private val channel: Events.Channel
|
||||
) : RequestHandler {
|
||||
protected var startTs: Instant? = null
|
||||
protected var request: BlockchainOuterClass.NativeCallRequest? = null
|
||||
protected val responses = ArrayList<NativeCall.CallResult>()
|
||||
protected val updateLock = ReentrantLock()
|
||||
|
||||
override fun onRequest(request: BlockchainOuterClass.NativeCallRequest) {
|
||||
this.startTs = Instant.now()
|
||||
this.request = request
|
||||
}
|
||||
|
||||
@@ -164,7 +166,7 @@ class AccessHandlerHttp(
|
||||
if (request == null) {
|
||||
return
|
||||
}
|
||||
val builder = EventsBuilder.NativeCall()
|
||||
val builder = EventsBuilder.NativeCall(startTs!!)
|
||||
builder.withChain(blockchain.id)
|
||||
builder.start(httpRequest)
|
||||
builder.onRequest(request!!)
|
||||
@@ -182,7 +184,7 @@ class AccessHandlerHttp(
|
||||
if (request == null) {
|
||||
return
|
||||
}
|
||||
val builder = EventsBuilder.NativeCall()
|
||||
val builder = EventsBuilder.NativeCall(startTs!!)
|
||||
builder.withChain(blockchain.id)
|
||||
builder.start(wsRequest)
|
||||
builder.onRequest(request!!)
|
||||
|
||||
@@ -18,6 +18,7 @@ package io.emeraldpay.dshackle.monitoring.accesslog
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import io.emeraldpay.grpc.Chain
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.util.UUID
|
||||
|
||||
@@ -104,6 +105,7 @@ class Events {
|
||||
val selector: String? = null,
|
||||
val quorum: Long? = null,
|
||||
val minAvailability: String? = null,
|
||||
val latency: Long,
|
||||
|
||||
val succeed: Boolean,
|
||||
val rpcError: Int? = null,
|
||||
|
||||
@@ -30,6 +30,7 @@ import reactor.netty.http.server.HttpServerRequest
|
||||
import reactor.netty.http.websocket.WebsocketInbound
|
||||
import java.net.InetAddress
|
||||
import java.net.InetSocketAddress
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.util.Locale
|
||||
import java.util.UUID
|
||||
@@ -294,7 +295,7 @@ class EventsBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
class NativeCall :
|
||||
class NativeCall(private val startTs : Instant) :
|
||||
Base<NativeCall>(),
|
||||
RequestReply<Events.NativeCall, BlockchainOuterClass.NativeCallRequest, BlockchainOuterClass.NativeCallReplyItem> {
|
||||
val items = ArrayList<Events.NativeCallItemDetails>()
|
||||
@@ -330,6 +331,7 @@ class EventsBuilder {
|
||||
index = index++,
|
||||
succeed = msg.succeed,
|
||||
blockchain = chain,
|
||||
latency = Duration.between(Instant.now(), startTs).toMillis(),
|
||||
nativeCall = item,
|
||||
payloadSizeBytes = item.payloadSizeBytes,
|
||||
id = UUID.randomUUID(),
|
||||
@@ -354,6 +356,7 @@ class EventsBuilder {
|
||||
index = index++,
|
||||
succeed = !reply.isError(),
|
||||
blockchain = chain,
|
||||
latency = Duration.between(startTs, Instant.now()).toMillis(),
|
||||
nativeCall = item,
|
||||
payloadSizeBytes = item.payloadSizeBytes,
|
||||
id = UUID.randomUUID(),
|
||||
|
||||
Reference in New Issue
Block a user