Skip to content

Commit

Permalink
Node/CCQ/Server: Add per user metrics (#3596)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley authored Dec 11, 2023
1 parent 69dbfb7 commit 2a3d4c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 10 additions & 1 deletion node/cmd/ccq/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ func (s *httpServer) handleQuery(w http.ResponseWriter, r *http.Request) {
invalidQueryRequestReceived.WithLabelValues("invalid_api_key").Inc()
return
}
totalRequestsByUser.WithLabelValues(permEntry.userName).Inc()

queryRequestBytes, err := hex.DecodeString(q.Bytes)
if err != nil {
s.logger.Error("failed to decode request bytes", zap.String("userId", permEntry.userName), zap.Error(err))
http.Error(w, err.Error(), http.StatusBadRequest)
invalidQueryRequestReceived.WithLabelValues("failed_to_decode_request").Inc()
invalidRequestsByUser.WithLabelValues(permEntry.userName).Inc()
return
}

Expand All @@ -100,6 +102,7 @@ func (s *httpServer) handleQuery(w http.ResponseWriter, r *http.Request) {
s.logger.Error("failed to decode signature bytes", zap.String("userId", permEntry.userName), zap.Error(err))
http.Error(w, err.Error(), http.StatusBadRequest)
invalidQueryRequestReceived.WithLabelValues("failed_to_decode_signature").Inc()
invalidRequestsByUser.WithLabelValues(permEntry.userName).Inc()
return
}

Expand All @@ -114,7 +117,8 @@ func (s *httpServer) handleQuery(w http.ResponseWriter, r *http.Request) {
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))
http.Error(w, err.Error(), status)
// Metric has already been pegged.
// Error specific metric has already been pegged.
invalidRequestsByUser.WithLabelValues(permEntry.userName).Inc()
return
}

Expand All @@ -129,6 +133,7 @@ func (s *httpServer) handleQuery(w http.ResponseWriter, r *http.Request) {
s.logger.Error("failed to marshal gossip message", zap.String("userId", permEntry.userName), zap.String("requestId", requestId), zap.Error(err))
http.Error(w, err.Error(), http.StatusInternalServerError)
invalidQueryRequestReceived.WithLabelValues("failed_to_marshal_gossip_msg").Inc()
invalidRequestsByUser.WithLabelValues(permEntry.userName).Inc()
return
}

Expand All @@ -138,6 +143,7 @@ func (s *httpServer) handleQuery(w http.ResponseWriter, r *http.Request) {
s.logger.Info("duplicate request", zap.String("userId", permEntry.userName), zap.String("requestId", requestId))
http.Error(w, "Duplicate request", http.StatusBadRequest)
invalidQueryRequestReceived.WithLabelValues("duplicate_request").Inc()
invalidRequestsByUser.WithLabelValues(permEntry.userName).Inc()
return
}

Expand All @@ -147,6 +153,7 @@ func (s *httpServer) handleQuery(w http.ResponseWriter, r *http.Request) {
s.logger.Error("failed to publish gossip message", zap.String("userId", permEntry.userName), zap.String("requestId", requestId), zap.Error(err))
http.Error(w, err.Error(), http.StatusInternalServerError)
invalidQueryRequestReceived.WithLabelValues("failed_to_publish_gossip_msg").Inc()
invalidRequestsByUser.WithLabelValues(permEntry.userName).Inc()
s.pendingResponses.Remove(pendingResponse)
return
}
Expand All @@ -163,6 +170,7 @@ func (s *httpServer) handleQuery(w http.ResponseWriter, r *http.Request) {
s.logger.Error("failed to marshal response", zap.String("userId", permEntry.userName), zap.String("requestId", requestId), zap.Error(err))
http.Error(w, err.Error(), http.StatusInternalServerError)
invalidQueryRequestReceived.WithLabelValues("failed_to_marshal_response").Inc()
invalidRequestsByUser.WithLabelValues(permEntry.userName).Inc()
break
}
// Signature indices must be ascending for on-chain verification
Expand All @@ -184,6 +192,7 @@ func (s *httpServer) handleQuery(w http.ResponseWriter, r *http.Request) {
s.logger.Error("failed to encode response", zap.String("userId", permEntry.userName), zap.String("requestId", requestId), zap.Error(err))
http.Error(w, err.Error(), http.StatusInternalServerError)
invalidQueryRequestReceived.WithLabelValues("failed_to_encode_response").Inc()
invalidRequestsByUser.WithLabelValues(permEntry.userName).Inc()
break
}
}
Expand Down
12 changes: 12 additions & 0 deletions node/cmd/ccq/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ var (
Help: "Total number of requested calls by chain",
}, []string{"chain_name"})

totalRequestsByUser = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "ccq_server_total_requests_by_user",
Help: "Total number of requests by user name",
}, []string{"user_name"})

invalidRequestsByUser = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "ccq_server_invalid_requests_by_user",
Help: "Total number of invalid requests by user name",
}, []string{"user_name"})

queryResponsesReceived = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "ccq_server_total_query_responses_received_by_peer_id",
Expand Down

0 comments on commit 2a3d4c8

Please sign in to comment.