add latency to access log

This commit is contained in:
terminal
2022-08-11 18:51:45 +04:00
parent cf04f50ab6
commit ded1ebcaa5
4 changed files with 12 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ import io.grpc.ServerInterceptor
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import java.time.Instant
@Service @Service
class AccessHandlerGrpc( class AccessHandlerGrpc(
@@ -119,7 +120,7 @@ class AccessHandlerGrpc(
): ServerCall.Listener<ReqT> { ): ServerCall.Listener<ReqT> {
return process( return process(
call, headers, next, call, headers, next,
EventsBuilder.NativeCall() as EventsBuilder.RequestReply<*, ReqT, RespT> EventsBuilder.NativeCall(Instant.now()) as EventsBuilder.RequestReply<*, ReqT, RespT>
) )
} }

View File

@@ -127,11 +127,13 @@ class AccessHandlerHttp(
private val accessLogWriter: AccessLogWriter, private val accessLogWriter: AccessLogWriter,
private val channel: Events.Channel private val channel: Events.Channel
) : RequestHandler { ) : RequestHandler {
protected var startTs: Instant? = null
protected var request: BlockchainOuterClass.NativeCallRequest? = null protected var request: BlockchainOuterClass.NativeCallRequest? = null
protected val responses = ArrayList<NativeCall.CallResult>() protected val responses = ArrayList<NativeCall.CallResult>()
protected val updateLock = ReentrantLock() protected val updateLock = ReentrantLock()
override fun onRequest(request: BlockchainOuterClass.NativeCallRequest) { override fun onRequest(request: BlockchainOuterClass.NativeCallRequest) {
this.startTs = Instant.now()
this.request = request this.request = request
} }
@@ -164,7 +166,7 @@ class AccessHandlerHttp(
if (request == null) { if (request == null) {
return return
} }
val builder = EventsBuilder.NativeCall() val builder = EventsBuilder.NativeCall(startTs!!)
builder.withChain(blockchain.id) builder.withChain(blockchain.id)
builder.start(httpRequest) builder.start(httpRequest)
builder.onRequest(request!!) builder.onRequest(request!!)
@@ -182,7 +184,7 @@ class AccessHandlerHttp(
if (request == null) { if (request == null) {
return return
} }
val builder = EventsBuilder.NativeCall() val builder = EventsBuilder.NativeCall(startTs!!)
builder.withChain(blockchain.id) builder.withChain(blockchain.id)
builder.start(wsRequest) builder.start(wsRequest)
builder.onRequest(request!!) builder.onRequest(request!!)

View File

@@ -18,6 +18,7 @@ package io.emeraldpay.dshackle.monitoring.accesslog
import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonInclude
import io.emeraldpay.grpc.Chain import io.emeraldpay.grpc.Chain
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.time.Duration
import java.time.Instant import java.time.Instant
import java.util.UUID import java.util.UUID
@@ -104,6 +105,7 @@ class Events {
val selector: String? = null, val selector: String? = null,
val quorum: Long? = null, val quorum: Long? = null,
val minAvailability: String? = null, val minAvailability: String? = null,
val latency: Long,
val succeed: Boolean, val succeed: Boolean,
val rpcError: Int? = null, val rpcError: Int? = null,

View File

@@ -30,6 +30,7 @@ import reactor.netty.http.server.HttpServerRequest
import reactor.netty.http.websocket.WebsocketInbound import reactor.netty.http.websocket.WebsocketInbound
import java.net.InetAddress import java.net.InetAddress
import java.net.InetSocketAddress import java.net.InetSocketAddress
import java.time.Duration
import java.time.Instant import java.time.Instant
import java.util.Locale import java.util.Locale
import java.util.UUID import java.util.UUID
@@ -294,7 +295,7 @@ class EventsBuilder {
} }
} }
class NativeCall : class NativeCall(private val startTs : Instant) :
Base<NativeCall>(), Base<NativeCall>(),
RequestReply<Events.NativeCall, BlockchainOuterClass.NativeCallRequest, BlockchainOuterClass.NativeCallReplyItem> { RequestReply<Events.NativeCall, BlockchainOuterClass.NativeCallRequest, BlockchainOuterClass.NativeCallReplyItem> {
val items = ArrayList<Events.NativeCallItemDetails>() val items = ArrayList<Events.NativeCallItemDetails>()
@@ -330,6 +331,7 @@ class EventsBuilder {
index = index++, index = index++,
succeed = msg.succeed, succeed = msg.succeed,
blockchain = chain, blockchain = chain,
latency = Duration.between(Instant.now(), startTs).toMillis(),
nativeCall = item, nativeCall = item,
payloadSizeBytes = item.payloadSizeBytes, payloadSizeBytes = item.payloadSizeBytes,
id = UUID.randomUUID(), id = UUID.randomUUID(),
@@ -354,6 +356,7 @@ class EventsBuilder {
index = index++, index = index++,
succeed = !reply.isError(), succeed = !reply.isError(),
blockchain = chain, blockchain = chain,
latency = Duration.between(startTs, Instant.now()).toMillis(),
nativeCall = item, nativeCall = item,
payloadSizeBytes = item.payloadSizeBytes, payloadSizeBytes = item.payloadSizeBytes,
id = UUID.randomUUID(), id = UUID.randomUUID(),