diff --git a/builder/builder.go b/builder/builder.go index bca64a60a1..7f1774177f 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -222,9 +222,11 @@ func (b *Builder) GetPayload(request PayloadRequestV1) (*builderSpec.VersionedSu } func (b *Builder) handleGetPayload(w http.ResponseWriter, req *http.Request) { + start := time.Now() vars := mux.Vars(req) slot, err := strconv.Atoi(vars["slot"]) if err != nil { + updateServeTimeHistogram("getPayload", false, time.Since(start)) respondError(w, http.StatusBadRequest, "incorrect slot") return } @@ -238,16 +240,19 @@ func (b *Builder) handleGetPayload(w http.ResponseWriter, req *http.Request) { }) if err != nil { handleError(w, err) + updateServeTimeHistogram("getPayload", false, time.Since(start)) return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) if err := json.NewEncoder(w).Encode(bestSubmission); err != nil { + updateServeTimeHistogram("getPayload", false, time.Since(start)) log.Error("could not encode response", "err", err) respondError(w, http.StatusInternalServerError, "could not encode response") return } + updateServeTimeHistogram("getPayload", true, time.Since(start)) } func (b *Builder) saveBlockSubmission(opts SubmitBlockOpts) error { diff --git a/builder/metrics.go b/builder/metrics.go new file mode 100644 index 0000000000..18ae2b1551 --- /dev/null +++ b/builder/metrics.go @@ -0,0 +1,39 @@ +// Copyright 2020 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package builder + +import ( + "fmt" + "time" + + "github.com/ethereum/go-ethereum/metrics" +) + +var serveTimeHistName = "builder/duration" + +// updateServeTimeHistogram tracks the serving time of serving a call. +func updateServeTimeHistogram(method string, success bool, elapsed time.Duration) { + note := "success" + if !success { + note = "failure" + } + h := fmt.Sprintf("%s/%s/%s", serveTimeHistName, method, note) + sampler := func() metrics.Sample { + return metrics.NewExpDecaySample(1028, 0.015) + } + metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(elapsed.Nanoseconds()) +} diff --git a/rpc/metrics.go b/rpc/metrics.go index ef7449ce05..6379f9f573 100644 --- a/rpc/metrics.go +++ b/rpc/metrics.go @@ -42,9 +42,7 @@ func updateServeTimeHistogram(method string, success bool, elapsed time.Duration } h := fmt.Sprintf("%s/%s/%s", serveTimeHistName, method, note) sampler := func() metrics.Sample { - return metrics.ResettingSample( - metrics.NewExpDecaySample(1028, 0.015), - ) + return metrics.NewExpDecaySample(1028, 0.015) } metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(elapsed.Nanoseconds()) }