diff --git a/beacon-chain/rpc/eth/beacon/BUILD.bazel b/beacon-chain/rpc/eth/beacon/BUILD.bazel index 09b40a6cc2..110dd27e3e 100644 --- a/beacon-chain/rpc/eth/beacon/BUILD.bazel +++ b/beacon-chain/rpc/eth/beacon/BUILD.bazel @@ -8,6 +8,7 @@ go_library( "handlers_state.go", "handlers_validator.go", "log.go", + "metrics.go", "server.go", ], importpath = "github.com/OffchainLabs/prysm/v6/beacon-chain/rpc/eth/beacon", @@ -61,6 +62,8 @@ go_library( "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", "@com_github_ethereum_go_ethereum//crypto/kzg4844:go_default_library", "@com_github_pkg_errors//:go_default_library", + "@com_github_prometheus_client_golang//prometheus:go_default_library", + "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", "@com_github_prysmaticlabs_fastssz//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ], diff --git a/beacon-chain/rpc/eth/beacon/handlers.go b/beacon-chain/rpc/eth/beacon/handlers.go index ddffa24a75..3558b368f9 100644 --- a/beacon-chain/rpc/eth/beacon/handlers.go +++ b/beacon-chain/rpc/eth/beacon/handlers.go @@ -9,6 +9,7 @@ import ( "net/http" "strconv" "strings" + "time" "github.com/OffchainLabs/prysm/v6/api" "github.com/OffchainLabs/prysm/v6/api/server/structs" @@ -658,6 +659,12 @@ func (s *Server) PublishBlock(w http.ResponseWriter, r *http.Request) { // broadcast all given signed blobs. The broadcast behaviour may be adjusted via the // `broadcast_validation` query parameter. func (s *Server) PublishBlockV2(w http.ResponseWriter, r *http.Request) { + start := time.Now() + defer func() { + duration := time.Since(start).Milliseconds() + publishBlockV2Duration.Observe(float64(duration)) + }() + ctx, span := trace.StartSpan(r.Context(), "beacon.PublishBlockV2") defer span.End() if shared.IsSyncing(r.Context(), w, s.SyncChecker, s.HeadFetcher, s.TimeFetcher, s.OptimisticModeFetcher) { diff --git a/beacon-chain/rpc/eth/beacon/metrics.go b/beacon-chain/rpc/eth/beacon/metrics.go new file mode 100644 index 0000000000..6a0fcfb769 --- /dev/null +++ b/beacon-chain/rpc/eth/beacon/metrics.go @@ -0,0 +1,16 @@ +package beacon + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +var ( + publishBlockV2Duration = promauto.NewHistogram( + prometheus.HistogramOpts{ + Name: "publish_block_v2_duration_milliseconds", + Help: "Duration of publishBlockV2 endpoint processing in milliseconds", + Buckets: []float64{1, 5, 20, 100, 500, 1000, 2000, 5000}, + }, + ) +) diff --git a/changelog/potuz_add_publishv2_metric.md b/changelog/potuz_add_publishv2_metric.md new file mode 100644 index 0000000000..02667e08ca --- /dev/null +++ b/changelog/potuz_add_publishv2_metric.md @@ -0,0 +1,3 @@ +### Added + +- Add timing metric `publish_block_v2_duration_milliseconds` to measure processing duration of the `PublishBlockV2` beacon API endpoint. \ No newline at end of file