Skip to content

Commit

Permalink
add proposer api metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed May 23, 2024
1 parent b522fc7 commit 4ab0fa0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var (
GetPayloadLatencyHistogram otelapi.Float64Histogram
PublishBlockLatencyHistogram otelapi.Float64Histogram

GetHeaderCount otelapi.Int64Counter
GetPayloadCount otelapi.Int64Counter

SubmitNewBlockLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockReadLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockDecodeLatencyHistogram otelapi.Float64Histogram
Expand Down
28 changes: 23 additions & 5 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,25 @@ func (api *RelayAPI) handleGetHeader(w http.ResponseWriter, req *http.Request) {
}

log.Debug("getHeader request received")
defer func() {
s, err := strconv.ParseInt(slotStr, 10, 64)
if err != nil {
log.WithError(err).Error("could not parse slot to int64")
return
}
metrics.GetHeaderLatencyHistogram.Record(
req.Context(),
float64(time.Since(requestTime).Milliseconds()),
)
metrics.GetHeaderCount.Add(
req.Context(),
1,
otelapi.WithAttributes(
attribute.Int64("slot", s),
attribute.Int64("floorSecIntoSlot", msIntoSlot/1000),
),
)
}()

if slices.Contains(apiNoHeaderUserAgents, ua) {
log.Info("rejecting getHeader by user agent")
Expand Down Expand Up @@ -1236,11 +1255,6 @@ func (api *RelayAPI) handleGetHeader(w http.ResponseWriter, req *http.Request) {
"blockHash": blockHash.String(),
}).Info("bid delivered")

metrics.GetHeaderLatencyHistogram.Record(
req.Context(),
float64(time.Since(requestTime).Milliseconds()),
)

api.RespondOK(w, bid)
}

Expand Down Expand Up @@ -1285,6 +1299,10 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request)
req.Context(),
float64(time.Since(receivedAt).Milliseconds()),
)
metrics.GetPayloadCount.Add(
req.Context(),
1,
)
}()

// Read the body first, so we can decode it later
Expand Down

0 comments on commit 4ab0fa0

Please sign in to comment.