From 4ab0fa060d9d444a67ec6de96c0bbd9322dce471 Mon Sep 17 00:00:00 2001 From: avalonche Date: Fri, 24 May 2024 06:20:59 +1000 Subject: [PATCH] add proposer api metrics --- metrics/metrics.go | 3 +++ services/api/service.go | 28 +++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index 9a5ad5c6..27f189b8 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -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 diff --git a/services/api/service.go b/services/api/service.go index 1cc4c56a..aa0b28a8 100644 --- a/services/api/service.go +++ b/services/api/service.go @@ -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") @@ -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) } @@ -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