Skip to content

Commit

Permalink
Node/CCQServer: Enhance response logging (#3754)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley authored Jan 30, 2024
1 parent 4138526 commit 82f1820
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions node/cmd/ccq/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ func (s *httpServer) handleQuery(w http.ResponseWriter, r *http.Request) {
Signature: signature,
}

requestId := hex.EncodeToString(signedQueryRequest.Signature)
s.logger.Info("received request from client", zap.String("userId", permEntry.userName), zap.String("requestId", requestId))

if status, err := validateRequest(s.logger, s.env, s.permissions, s.signerKey, apiKey, signedQueryRequest); err != nil {
s.logger.Error("failed to validate request", zap.String("userId", permEntry.userName), zap.String("requestId", requestId), zap.Int("status", status), zap.Error(err))
s.logger.Error("failed to validate request", zap.String("userId", permEntry.userName), zap.String("requestId", hex.EncodeToString(signedQueryRequest.Signature)), zap.Int("status", status), zap.Error(err))
http.Error(w, err.Error(), status)
// Error specific metric has already been pegged.
invalidRequestsByUser.WithLabelValues(permEntry.userName).Inc()
return
}

requestId := hex.EncodeToString(signedQueryRequest.Signature)
s.logger.Info("received request from client", zap.String("userId", permEntry.userName), zap.String("requestId", requestId))

m := gossipv1.GossipMessage{
Message: &gossipv1.GossipMessage_SignedQueryRequest{
SignedQueryRequest: signedQueryRequest,
Expand Down
7 changes: 6 additions & 1 deletion node/cmd/ccq/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ func runP2P(ctx context.Context, priv crypto.PrivKey, port uint, networkID, boot
requestSignature := hex.EncodeToString(queryResponse.Request.Signature)
logger.Info("query response received from gossip", zap.String("peerId", peerId), zap.Any("requestId", requestSignature))
if loggingMap.ShouldLogResponse(requestSignature) {
logger.Info("logging response", zap.Any("requestId", requestSignature), zap.Any("response", queryResponse))
var queryRequest query.QueryRequest
if err := queryRequest.Unmarshal(queryResponse.Request.QueryRequest); err == nil {
logger.Info("logging response", zap.String("peerId", peerId), zap.Any("requestId", requestSignature), zap.Any("request", queryRequest), zap.Any("response", queryResponse))
} else {
logger.Error("logging response (failed to unmarshal request)", zap.String("peerId", peerId), zap.Any("requestId", requestSignature), zap.Any("response", queryResponse))
}
}
// Check that we're handling the request for this response
pendingResponse := pendingResponses.Get(requestSignature)
Expand Down

0 comments on commit 82f1820

Please sign in to comment.