Skip to content

Commit

Permalink
Add builder demotion metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed May 17, 2024
1 parent d6eaf00 commit 1aa7e47
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var (
GetPayloadLatencyHistogram otelapi.Float64Histogram
PublishBlockLatencyHistogram otelapi.Float64Histogram

BuilderDemotionCount otelapi.Int64Counter

latencyBoundaries = otelapi.WithExplicitBucketBoundaries(func() []float64 {
base := math.Exp(math.Log(12.0) / 15.0)
res := make([]float64, 0, 31)
Expand All @@ -37,6 +39,7 @@ func Setup(ctx context.Context) error {
setupMeter, // must come first
setupGetPayloadLatency,
setupPublishBlockLatency,
setupBuilderDemotionCount,
} {
if err := setup(ctx); err != nil {
return err
Expand Down Expand Up @@ -98,3 +101,15 @@ func setupPublishBlockLatency(ctx context.Context) error {
}
return nil
}

func setupBuilderDemotionCount(ctx context.Context) error {
counter, err := meter.Int64Counter(
"builder_demotion_count",
otelapi.WithDescription("number of times a builder has been demoted"),
)
BuilderDemotionCount = counter
if err != nil {
return err
}
return nil
}
8 changes: 8 additions & 0 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ func (api *RelayAPI) StartServer() (err error) {

// start block-builder API specific things
if api.opts.BlockBuilderAPI {
// Initialize metrics
metrics.BuilderDemotionCount.Add(context.Background(), 0)

// Get current proposer duties blocking before starting, to have them ready
api.updateProposerDuties(syncStatus.HeadSlot)

Expand Down Expand Up @@ -600,6 +603,11 @@ func (api *RelayAPI) simulateBlock(ctx context.Context, opts blockSimOptions) (r
}

func (api *RelayAPI) demoteBuilder(pubkey string, req *common.VersionedSubmitBlockRequest, simError error) {
metrics.BuilderDemotionCount.Add(
context.Background(),
1,
)

builderEntry, ok := api.blockBuildersCache[pubkey]
if !ok {
api.log.Warnf("builder %v not in the builder cache", pubkey)
Expand Down

0 comments on commit 1aa7e47

Please sign in to comment.