Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a metrics gauge for built block slot #3048

Merged
merged 36 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c1182a5
initial version.
tsachiherman May 23, 2024
86da9b1
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman May 23, 2024
8765910
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman May 28, 2024
453fa82
prepare.
tsachiherman May 31, 2024
2080759
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman May 31, 2024
88db71e
update
tsachiherman May 31, 2024
ecf3f90
update
tsachiherman Jun 3, 2024
2b68605
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 3, 2024
d9cad44
rename
tsachiherman Jun 3, 2024
3747e86
rollback unwanted changes.
tsachiherman Jun 3, 2024
6d5cccd
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 3, 2024
c3c03c6
update per cr
tsachiherman Jun 4, 2024
af7b92c
update per CR.
tsachiherman Jun 4, 2024
83639ed
update per cr
tsachiherman Jun 4, 2024
2a885a2
update pr
tsachiherman Jun 4, 2024
3c17ddb
rollback unwanted changes.
tsachiherman Jun 4, 2024
ac28f28
fix regression in unit test.
tsachiherman Jun 4, 2024
289e2c9
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 4, 2024
e62aa39
make linter happy.
tsachiherman Jun 4, 2024
198e77b
fix proposerBuildSlotGauge.Set in case we're not the next proposer wi…
tsachiherman Jun 5, 2024
5c5804b
Update vms/proposervm/block.go
tsachiherman Jun 6, 2024
fa47a7c
Update vms/proposervm/post_fork_block.go
tsachiherman Jun 6, 2024
8feb86c
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
6562348
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
24c9fc6
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
f77c4fd
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
65aa579
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
8d8480a
Update vms/proposervm/block.go
tsachiherman Jun 6, 2024
ebfe48b
make nicer
tsachiherman Jun 6, 2024
d2c6045
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 6, 2024
bd2d17d
update
tsachiherman Jun 6, 2024
46d1eeb
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 6, 2024
8da20a6
reduce diff
StephenButtolph Jun 6, 2024
10af2bb
Merge branch 'master' into tsachi/report-proposer-slot
StephenButtolph Jun 6, 2024
bb2309b
fix merge
StephenButtolph Jun 6, 2024
72ffa86
fix merge again
StephenButtolph Jun 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions vms/proposervm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@ func (p *postForkCommonComponents) verifyPostDurangoBlockDelay(
currentSlot = proposer.TimeToSlot(parentTimestamp, blkTimestamp)
proposerID = blk.Proposer()
)
// populate the slot for the block.
blk.slot = &currentSlot

// find the expected proposer
expectedProposerID, err := p.vm.Windower.ExpectedProposer(
ctx,
blkHeight,
Expand Down Expand Up @@ -452,6 +455,11 @@ func (p *postForkCommonComponents) shouldBuildSignedBlockPostDurango(
)
return false, err
}

// report the build slot to the metrics.
p.vm.proposerBuildSlotGauge.Set(float64(proposer.TimeToSlot(parentTimestamp, nextStartTime)))

// set the scheduler to let us know when the next block need to be built.
p.vm.Scheduler.SetBuildBlockTime(nextStartTime)

// In case the inner VM only issued one pendingTxs message, we should
Expand Down
5 changes: 3 additions & 2 deletions vms/proposervm/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,9 @@ func TestPostDurangoBuildChildResetScheduler(t *testing.T) {
ValidatorState: vdrState,
Log: logging.NoLog{},
},
Windower: windower,
Scheduler: scheduler,
Windower: windower,
Scheduler: scheduler,
proposerBuildSlotGauge: prometheus.NewGauge(prometheus.GaugeOpts{}),
}
vm.Clock.Set(now)

Expand Down
13 changes: 12 additions & 1 deletion vms/proposervm/post_fork_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ var _ PostForkBlock = (*postForkBlock)(nil)
type postForkBlock struct {
block.SignedBlock
postForkCommonComponents

// slot of the proposer that produced this block.
// It is populated in verifyPostDurangoBlockDelay.
// It is used to report metrics during Accept.
slot *uint64
}

// Accept:
Expand All @@ -27,7 +32,13 @@ func (b *postForkBlock) Accept(ctx context.Context) error {
if err := b.acceptOuterBlk(); err != nil {
return err
}
return b.acceptInnerBlk(ctx)
if err := b.acceptInnerBlk(ctx); err != nil {
return err
}
if b.slot != nil {
b.vm.acceptedBlocksSlotHistogram.Observe(float64(*b.slot))
}
return nil
}

func (b *postForkBlock) acceptOuterBlk() error {
Expand Down
39 changes: 36 additions & 3 deletions vms/proposervm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"time"

"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/cache"
Expand All @@ -22,6 +23,7 @@ import (
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
Expand Down Expand Up @@ -97,6 +99,14 @@ type VM struct {

// lastAcceptedHeight is set to the last accepted PostForkBlock's height.
lastAcceptedHeight uint64

// proposerBuildSlotGauge reports the slot index when this node may attempt
// to build a block.
proposerBuildSlotGauge prometheus.Gauge

// acceptedBlocksSlotHistogram reports the slots that accepted blocks were
// proposed in.
acceptedBlocksSlotHistogram prometheus.Histogram
}

// New performs best when [minBlkDelay] is whole seconds. This is because block
Expand Down Expand Up @@ -206,7 +216,28 @@ func (vm *VM) Initialize(
default:
return err
}
return nil

vm.proposerBuildSlotGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "block_building_slot",
Help: "the slot that this node may attempt to build a block",
})
vm.acceptedBlocksSlotHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "accepted_blocks_slot",
Help: "the slot accepted blocks were proposed in",
// define the following ranges:
// (-inf, 0]
// (0, 1]
// (1, 2]
// (2, inf)
// the usage of ".5" before was to ensure we work around the limitation
// of comparing floating point of the same numerical value.
Buckets: []float64{0.5, 1.5, 2.5},
})

return utils.Err(
vm.Config.Registerer.Register(vm.proposerBuildSlotGauge),
vm.Config.Registerer.Register(vm.acceptedBlocksSlotHistogram),
)
}

// shutdown ops then propagate shutdown to innerVM
Expand Down Expand Up @@ -294,13 +325,15 @@ func (vm *VM) SetPreference(ctx context.Context, preferred ids.ID) error {
)
if vm.IsDurangoActivated(parentTimestamp) {
currentTime := vm.Clock.Time().Truncate(time.Second)
nextStartTime, err = vm.getPostDurangoSlotTime(
if nextStartTime, err = vm.getPostDurangoSlotTime(
ctx,
childBlockHeight,
pChainHeight,
proposer.TimeToSlot(parentTimestamp, currentTime),
parentTimestamp,
)
); err == nil {
vm.proposerBuildSlotGauge.Set(float64(proposer.TimeToSlot(parentTimestamp, nextStartTime)))
}
} else {
nextStartTime, err = vm.getPreDurangoSlotTime(
ctx,
Expand Down
Loading