Skip to content

Commit 0e51508

Browse files
authored
Merge pull request #747 from onflow/mpeter/refactor-request-duration-metric
Refactor metric for request duration
2 parents fad9132 + eb5b592 commit 0e51508

File tree

2 files changed

+11
-74
lines changed

2 files changed

+11
-74
lines changed

api/server.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,15 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
248248
}
249249

250250
requestBody := make(map[string]any)
251+
requestMethod := ""
251252
if b, err := io.ReadAll(r.Body); err == nil {
252253
_ = json.Unmarshal(b, &requestBody)
253254

254255
// Do not log any debug info for methods that are not valid
255256
// JSON-RPC methods.
256257
if methodValue, ok := requestBody["method"]; ok {
257258
if methodStr, ok := methodValue.(string); ok && eth.IsValidMethod(methodStr) {
259+
requestMethod = methodStr
258260
h.logger.Debug().
259261
Str("IP", r.RemoteAddr).
260262
Str("url", r.URL.String()).
@@ -284,13 +286,16 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
284286
return
285287
}
286288

287-
if h.httpHandler != nil {
288-
if checkPath(r, "") {
289-
metrics.
290-
NewMetricsHandler(h.httpHandler, h.collector, h.logger).
291-
ServeHTTP(logW, r)
292-
return
289+
if h.httpHandler != nil && checkPath(r, "") {
290+
start := time.Now()
291+
292+
h.httpHandler.ServeHTTP(logW, r)
293+
294+
if eth.IsValidMethod(requestMethod) {
295+
h.collector.MeasureRequestDuration(start, requestMethod)
293296
}
297+
298+
return
294299
}
295300

296301
w.WriteHeader(http.StatusNotFound)

metrics/handler.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)