Skip to content

Commit b0eee4d

Browse files
authored
Fix invalid rpc id metrics (heroiclabs#1304)
Do not report custom RPC endpoints that are invoked with an invalid id (404) to the prometheus RPC calls counts.
1 parent 723250f commit b0eee4d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
77
### Fixed
88
- Ensure persisted chat messages listing returns correct order.
99
- Return correct tournament details in console API leaderboard details endpoint.
10+
- Do not report invalid http RPC ids to prometheus counts.
1011

1112
## [3.25.0] - 2024-11-25
1213
### Added

server/api_rpc.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,9 @@ func (s *ApiServer) RpcFuncHttp(w http.ResponseWriter, r *http.Request) {
107107
}
108108

109109
start := time.Now()
110-
var success bool
110+
111111
var recvBytes, sentBytes int
112112
var err error
113-
var id string
114-
115-
// After this point the RPC will be captured in metrics.
116-
defer func() {
117-
s.metrics.ApiRpc(id, time.Since(start), int64(recvBytes), int64(sentBytes), !success)
118-
}()
119-
120113
// Check the RPC function ID.
121114
maybeID, ok := mux.Vars(r)["id"]
122115
if !ok || maybeID == "" {
@@ -129,7 +122,8 @@ func (s *ApiServer) RpcFuncHttp(w http.ResponseWriter, r *http.Request) {
129122
}
130123
return
131124
}
132-
id = strings.ToLower(maybeID)
125+
126+
id := strings.ToLower(maybeID)
133127

134128
// Find the correct RPC function.
135129
fn := s.runtime.Rpc(id)
@@ -144,6 +138,12 @@ func (s *ApiServer) RpcFuncHttp(w http.ResponseWriter, r *http.Request) {
144138
return
145139
}
146140

141+
var success bool
142+
// After this point the RPC will be captured in metrics.
143+
defer func() {
144+
s.metrics.ApiRpc(id, time.Since(start), int64(recvBytes), int64(sentBytes), !success)
145+
}()
146+
147147
// Check if we need to mimic existing GRPC Gateway behaviour or expect to receive/send unwrapped data.
148148
// Any value for this query parameter, including the parameter existing with an empty value, will
149149
// indicate that raw behaviour is expected.

0 commit comments

Comments
 (0)