Package com.linkedin.venice.listener
Class ServerStatsContext
java.lang.Object
com.linkedin.venice.listener.ServerStatsContext
We need to be able to record server side statistics for gRPC requests. The current StatsHandler in the Netty
Pipeline maintains instance variables per channel, and guarantees that each request will be handled by the same
thread, thus we cannot augment StatsHandler in the same way as other handlers for gRPC requests. We create a
new StatsContext for each gRPC request, so we can maintain per request stats which will be aggregated on request
completion using references to the proper Metrics Repository in AggServerHttpRequestStats. This class is almost a
direct copy of StatsHandler, without Netty Channel Read/Write logic.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSentinel store name used when the actual store name is unknown (e.g., request failed before store resolution). -
Constructor Summary
ConstructorsConstructorDescriptionServerStatsContext(AggServerHttpRequestStats singleGetStats, AggServerHttpRequestStats multiGetStats, AggServerHttpRequestStats computeStats) -
Method Summary
Modifier and TypeMethodDescriptionvoiderrorRequest(ServerHttpRequestStats stats, double elapsedTime) Records error request metrics.intlongio.netty.handler.codec.http.HttpResponseStatusbooleanbooleanbooleanvoidrecordBasicMetrics(ServerHttpRequestStats serverHttpRequestStats) Records request-level and response-level metrics for the current request.voidvoidsetFlushLatency(double latency) voidsetMetadataRequest(boolean metadataRequest) voidsetMisroutedStoreVersion(boolean misroutedStoreVersion) voidvoidsetReadResponseStats(ReadResponseStatsRecorder responseStatsRecorder) voidsetRequestInfo(RouterRequest request) voidsetRequestKeyCount(int keyCount) voidsetRequestSize(int requestSizeInBytes) voidvoidsetRequestType(RequestType requestType) voidsetResponseSize(int size) voidsetResponseStatus(io.netty.handler.codec.http.HttpResponseStatus status) voidsetStatCallBackExecuted(boolean statCallbackExecuted) voidsetStoreName(String name) voidsuccessRequest(ServerHttpRequestStats stats, double elapsedTime)
-
Field Details
-
UNKNOWN_STORE_NAME
Sentinel store name used when the actual store name is unknown (e.g., request failed before store resolution). Using a sentinel instead ofnullensures both Tehuti and OTel metrics are recorded rather than otel getting silently dropped as otel needs non-null values for all dimensions rather than having a diff metric for such cases.- See Also:
-
-
Constructor Details
-
ServerStatsContext
public ServerStatsContext(AggServerHttpRequestStats singleGetStats, AggServerHttpRequestStats multiGetStats, AggServerHttpRequestStats computeStats)
-
-
Method Details
-
isNewRequest
public boolean isNewRequest() -
resetContext
public void resetContext() -
setReadResponseStats
-
setNewRequest
public void setNewRequest() -
isMetadataRequest
public boolean isMetadataRequest() -
isStatCallBackExecuted
public boolean isStatCallBackExecuted() -
setStatCallBackExecuted
public void setStatCallBackExecuted(boolean statCallbackExecuted) -
setResponseStatus
public void setResponseStatus(io.netty.handler.codec.http.HttpResponseStatus status) -
getStoreName
-
setStoreName
-
setMetadataRequest
public void setMetadataRequest(boolean metadataRequest) -
setRequestTerminatedEarly
public void setRequestTerminatedEarly() -
getResponseStatus
public io.netty.handler.codec.http.HttpResponseStatus getResponseStatus() -
setRequestType
-
getRequestType
-
setRequestKeyCount
public void setRequestKeyCount(int keyCount) -
getCurrentStats
-
setRequestInfo
-
setRequestSize
public void setRequestSize(int requestSizeInBytes) -
getRequestStartTimeInNS
public long getRequestStartTimeInNS() -
setFlushLatency
public void setFlushLatency(double latency) -
setResponseSize
public void setResponseSize(int size) -
recordBasicMetrics
Records request-level and response-level metrics for the current request.responseStatusmust be non-null when this method is called. Both callers enforce this:StatsHandler.write(io.netty.channel.ChannelHandlerContext, java.lang.Object, io.netty.channel.ChannelPromise)throwsVeniceExceptionif responseStatus is null, andGrpcOutboundStatsHandler.processRequest(com.linkedin.venice.listener.grpc.GrpcRequestContext)does the same. The null guard on responseStatus below is purely defensive.- Parameters:
serverHttpRequestStats- the per-store stats object; may be null if the store name is unknown, in which case this method is a no-op. This is acceptable because when the store is unknown the request failed before store resolution, so most fields here (keyCount, requestSize, responseStats) won't have meaningful values. The critical error count and latency metrics are still captured byerrorRequest(com.linkedin.venice.stats.ServerHttpRequestStats, double), which resolves unknown stores toUNKNOWN_STORE_NAME.
-
successRequest
-
errorRequest
Records error request metrics. Whenstatsis null (store unknown), resolves a per-store stats object usingUNKNOWN_STORE_NAMEso that both Tehuti and OTel metrics are recorded rather than OTel getting silently dropped.This method does not have to be synchronized since Tehuti Sensor.record() is internally synchronized and OTel SDK recording methods are thread-safe. Please re-consider if new logic is added.
-
getRequestKeyCount
public int getRequestKeyCount() -
setMisroutedStoreVersion
public void setMisroutedStoreVersion(boolean misroutedStoreVersion)
-