Skip to content

Commit

Permalink
Add logs for batch request (#228)
Browse files Browse the repository at this point in the history
* add logs for batch request

* add metric
  • Loading branch information
giskook authored Jul 1, 2024
1 parent 2042790 commit a809236
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions jsonrpc/metrics/metrics_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
requestAuthCountName = requestPrefix + "auth_count"
requestAuthErrorCountName = requestPrefix + "auth_error_count"
requestRelayFailCountName = requestPrefix + "relay_fail_count"
requestBatchSizeName = requestPrefix + "batch_size"

wsRequestPrefix = prefix + "ws_request_"
requestWsMethodName = wsRequestPrefix + "method"
Expand All @@ -38,6 +39,10 @@ var (
Name: lastRawGasPriceName,
Help: "[JSONRPC] raw gas price",
},
{
Name: requestBatchSizeName,
Help: "[JSONRPC] batch request size",
},
}

histogramVecs = []metrics.HistogramVecOpts{
Expand Down Expand Up @@ -192,3 +197,8 @@ func RequestAuthErrorCount(tp RequestAuthErrorType) {
func RequestRelayFailCount(method string) {
metrics.CounterVecInc(requestRelayFailCountName, method)
}

// RequestBatchSize increments the batch requests count
func RequestBatchSize(batchSize int) {
metrics.GaugeSet(requestBatchSizeName, float64(batchSize))
}
5 changes: 4 additions & 1 deletion jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (s *Server) handleBatchRequest(httpRequest *http.Request, w http.ResponseWr
}

responses := make([]types.Response, 0, len(requests))

var methods string
for _, request := range requests {
if !methodRateLimitAllow(request.Method) {
responses = append(responses, types.NewResponse(request, nil, types.NewRPCError(types.InvalidParamsErrorCode, "server is too busy")))
Expand All @@ -384,7 +384,10 @@ func (s *Server) handleBatchRequest(httpRequest *http.Request, w http.ResponseWr
}
responses = append(responses, response)
metrics.RequestMethodDuration(request.Method, st)
methods += request.Method + ","
}
metrics.RequestBatchSize(len(responses))
log.Infof("Batch request handled: %s total: %d", methods, len(responses))

respBytes, _ := json.Marshal(responses)
_, err = w.Write(respBytes)
Expand Down

0 comments on commit a809236

Please sign in to comment.