Skip to content

Commit

Permalink
Observability - remove round gauage, add attributes to stage duration…
Browse files Browse the repository at this point in the history
… histogram
  • Loading branch information
oleg-ssvlabs committed Dec 3, 2024
1 parent e9825fe commit df8f86a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion protocol/v2/qbft/instance/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (i *Instance) UponCommit(ctx context.Context, logger *zap.Logger, msg *spec
zap.Any("agg_signers", agg.OperatorIDs),
fields.Root(msg.QBFTMessage.Root))

i.metrics.EndStageCommit(ctx)
i.metrics.EndStageCommit(ctx, i.State.Round)

return true, fullData, agg, nil
}
Expand Down
1 change: 0 additions & 1 deletion protocol/v2/qbft/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ func (i *Instance) Decode(data []byte) error {
// bumpToRound sets round and sends current round metrics.
func (i *Instance) bumpToRound(ctx context.Context, round specqbft.Round) {
i.State.Round = round
i.metrics.SetRound(ctx, round)
}

// CanProcessMessages will return true if instance can process messages
Expand Down
31 changes: 16 additions & 15 deletions protocol/v2/qbft/instance/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package instance

import (
"context"
"math"
"time"

specqbft "github.com/ssvlabs/ssv-spec/qbft"
"github.com/ssvlabs/ssv-spec/qbft"
"go.opentelemetry.io/otel/metric"
)

Expand All @@ -24,33 +23,35 @@ func (m *metrics) StartStage() {
m.stageStart = time.Now()
}

func (m *metrics) EndStageProposal(ctx context.Context) {
func (m *metrics) EndStageProposal(ctx context.Context, round qbft.Round) {
validatorStageDurationHistogram.Record(
ctx,
time.Since(m.stageStart).Seconds(),
metric.WithAttributes(stageAttribute(proposalStage)))
metric.WithAttributes(
stageAttribute(proposalStage),
roleAttribute(m.role),
roundAttribute(round)))
m.stageStart = time.Now()
}

func (m *metrics) EndStagePrepare(ctx context.Context) {
func (m *metrics) EndStagePrepare(ctx context.Context, round qbft.Round) {
validatorStageDurationHistogram.Record(
ctx,
time.Since(m.stageStart).Seconds(),
metric.WithAttributes(stageAttribute(prepareStage)))
metric.WithAttributes(
stageAttribute(prepareStage),
roleAttribute(m.role),
roundAttribute(round)))
m.stageStart = time.Now()
}

func (m *metrics) EndStageCommit(ctx context.Context) {
func (m *metrics) EndStageCommit(ctx context.Context, round qbft.Round) {
validatorStageDurationHistogram.Record(
ctx,
time.Since(m.stageStart).Seconds(),
metric.WithAttributes(stageAttribute(commitStage)))
metric.WithAttributes(
stageAttribute(commitStage),
roleAttribute(m.role),
roundAttribute(round)))
m.stageStart = time.Now()
}

func (m *metrics) SetRound(ctx context.Context, round specqbft.Round) {
convertedRound := uint64(round)
if convertedRound <= math.MaxInt64 {
roundGauge.Record(ctx, int64(convertedRound), metric.WithAttributes(roleAttribute(m.role)))
}
}
19 changes: 13 additions & 6 deletions protocol/v2/qbft/instance/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package instance

import (
"fmt"
"math"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"

"github.com/ssvlabs/ssv-spec/qbft"
"github.com/ssvlabs/ssv/observability"
)

Expand All @@ -32,12 +34,6 @@ var (
metric.WithUnit("s"),
metric.WithDescription("validator stage(proposal, prepare, commit) duration"),
metric.WithExplicitBucketBoundaries(observability.SecondsHistogramBuckets...)))

roundGauge = observability.NewMetric(
meter.Int64Gauge(
metricName("round"),
metric.WithUnit("{round}"),
metric.WithDescription("QBFT instance round")))
)

func metricName(name string) string {
Expand All @@ -51,3 +47,14 @@ func stageAttribute(stage stage) attribute.KeyValue {
func roleAttribute(role string) attribute.KeyValue {
return attribute.String("ssv.runner.role", role)
}

func roundAttribute(round qbft.Round) attribute.KeyValue {
var convertedRound int64 = -1

uintRound := uint64(round)
if uintRound <= math.MaxInt64 {
convertedRound = int64(uintRound)
}

return attribute.Int64("ssv.validator.duty.round", convertedRound)
}
2 changes: 1 addition & 1 deletion protocol/v2/qbft/instance/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (i *Instance) uponPrepare(ctx context.Context, logger *zap.Logger, msg *spe
i.State.LastPreparedValue = i.State.ProposalAcceptedForCurrentRound.SignedMessage.FullData
i.State.LastPreparedRound = i.State.Round

i.metrics.EndStagePrepare(ctx)
i.metrics.EndStagePrepare(ctx, i.State.Round)

logger.Debug("🎯 got prepare quorum",
fields.Round(i.State.Round),
Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/qbft/instance/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (i *Instance) uponProposal(ctx context.Context, logger *zap.Logger, msg *sp
}
i.bumpToRound(ctx, newRound)

i.metrics.EndStageProposal(ctx)
i.metrics.EndStageProposal(ctx, newRound)

// value root
r, err := specqbft.HashDataRoot(msg.SignedMessage.FullData)
Expand Down

0 comments on commit df8f86a

Please sign in to comment.