Skip to content

Commit

Permalink
Block submission metrics (#625)
Browse files Browse the repository at this point in the history
* Block submission metrics

* add proposer api metrics

* fix: adjust latency buckets for milliseconds

* comments

---------

Co-authored-by: Anton Bronnikov <anton@northernforest.nl>
  • Loading branch information
avalonche and 0x416e746f6e authored Jun 4, 2024
1 parent 035cde8 commit 7dc9c0d
Show file tree
Hide file tree
Showing 3 changed files with 288 additions and 11 deletions.
13 changes: 13 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ type Profile struct {
Simulation uint64
RedisUpdate uint64
Total uint64

// Redis profiling
RedisSavePayload uint64
RedisUpdateTopBid uint64
RedisUpdateFloor uint64

// Attributes
IsGzip bool
ContentType string
AboveFloorBid bool
SimulationSuccess bool
WasBidSaved bool
Optimistic bool
}

func (p *Profile) String() string {
Expand Down
184 changes: 175 additions & 9 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,32 @@ const (
var (
meter otelapi.Meter

GetHeaderLatencyHistogram otelapi.Float64Histogram
GetPayloadLatencyHistogram otelapi.Float64Histogram
PublishBlockLatencyHistogram otelapi.Float64Histogram

SubmitNewBlockLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockReadLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockDecodeLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockPrechecksLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockSimulationLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockRedisLatencyHistogram otelapi.Float64Histogram

SubmitNewBlockRedisPayloadLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockRedisTopBidLatencyHistogram otelapi.Float64Histogram
SubmitNewBlockRedisFloorLatencyHistogram otelapi.Float64Histogram

BuilderDemotionCount otelapi.Int64Counter

latencyBoundaries = otelapi.WithExplicitBucketBoundaries(func() []float64 {
// latencyBoundariesMs is the set of buckets of exponentially growing
// latencies that are ranging from 5ms up to 12s
latencyBoundariesMs = otelapi.WithExplicitBucketBoundaries(func() []float64 {
base := math.Exp(math.Log(12.0) / 15.0)
res := make([]float64, 0, 31)
for i := -15; i < 16; i++ {
res = append(res, math.Pow(base, float64(i)))
res := make([]float64, 0, 48)
for i := -31; i < 16; i++ {
res = append(res,
1000.0*math.Pow(base, float64(i)),
)
}
return res
}()...)
Expand All @@ -37,8 +53,18 @@ var (
func Setup(ctx context.Context) error {
for _, setup := range []func(context.Context) error{
setupMeter, // must come first
setupGetHeaderLatency,
setupGetPayloadLatency,
setupPublishBlockLatency,
setupSubmitNewBlockLatency,
setupSubmitNewBlockReadLatency,
setupSubmitNewBlockDecodeLatency,
setupSubmitNewBlockPrechecksLatency,
setupSubmitNewBlockSimulationLatency,
setupSubmitNewBlockRedisLatency,
setupSubmitNewBlockRedisPayloadLatency,
setupSubmitNewBlockRedisTopBidLatency,
setupSubmitNewBlockRedisFloorLatency,
setupBuilderDemotionCount,
} {
if err := setup(ctx); err != nil {
Expand Down Expand Up @@ -74,12 +100,26 @@ func setupMeter(ctx context.Context) error {
return nil
}

func setupGetPayloadLatency(ctx context.Context) error {
func setupGetHeaderLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"get_header_latency",
otelapi.WithDescription("statistics on the duration of getHeader requests execution"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
GetHeaderLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupGetPayloadLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"get_payload_latency",
otelapi.WithDescription("statistics on the duration of getPayload requests execution"),
otelapi.WithUnit("ms"),
latencyBoundaries,
latencyBoundariesMs,
)
GetPayloadLatencyHistogram = latency
if err != nil {
Expand All @@ -88,12 +128,12 @@ func setupGetPayloadLatency(ctx context.Context) error {
return nil
}

func setupPublishBlockLatency(ctx context.Context) error {
func setupPublishBlockLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"publish_block_latency",
otelapi.WithDescription("statistics on the duration of publishBlock requests sent to beacon node"),
otelapi.WithUnit("ms"),
latencyBoundaries,
latencyBoundariesMs,
)
PublishBlockLatencyHistogram = latency
if err != nil {
Expand All @@ -102,7 +142,133 @@ func setupPublishBlockLatency(ctx context.Context) error {
return nil
}

func setupBuilderDemotionCount(ctx context.Context) error {
func setupSubmitNewBlockLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_latency",
otelapi.WithDescription("statistics on the duration of submitNewBlock requests execution"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupSubmitNewBlockReadLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_read_latency",
otelapi.WithDescription("statistics on the duration of reading the payload of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockReadLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupSubmitNewBlockDecodeLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_decode_latency",
otelapi.WithDescription("statistics on the duration of decoding the payload of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockDecodeLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupSubmitNewBlockPrechecksLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_prechecks_latency",
otelapi.WithDescription("statistics on the duration of prechecks (floor bid, signature etc.) of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockPrechecksLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupSubmitNewBlockSimulationLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_simulation_latency",
otelapi.WithDescription("statistics on the block simulation duration of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockSimulationLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupSubmitNewBlockRedisLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_redis_latency",
otelapi.WithDescription("statistics on the redis update duration of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockRedisLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupSubmitNewBlockRedisPayloadLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_redis_payload_latency",
otelapi.WithDescription("statistics on the redis save payload duration during redis updates of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockRedisPayloadLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupSubmitNewBlockRedisTopBidLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_redis_top_bid_latency",
otelapi.WithDescription("statistics on the redis update top bid duration during redis updates of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockRedisTopBidLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupSubmitNewBlockRedisFloorLatency(_ context.Context) error {
latency, err := meter.Float64Histogram(
"submit_new_block_redis_floor_latency",
otelapi.WithDescription("statistics on the redis update floor bid duration during redis updates of submitNewBlock requests"),
otelapi.WithUnit("ms"),
latencyBoundariesMs,
)
SubmitNewBlockRedisFloorLatencyHistogram = latency
if err != nil {
return err
}
return nil
}

func setupBuilderDemotionCount(_ context.Context) error {
counter, err := meter.Int64Counter(
"builder_demotion_count",
otelapi.WithDescription("number of times a builder has been demoted"),
Expand Down
Loading

0 comments on commit 7dc9c0d

Please sign in to comment.