Skip to content

Commit

Permalink
Refactor attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-ssvlabs committed Dec 9, 2024
1 parent 5335f0f commit f117ef6
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 54 deletions.
10 changes: 3 additions & 7 deletions message/validation/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,18 @@ func reasonAttribute(reason string) attribute.KeyValue {
return attribute.String("ssv.p2p.message.validation.discard_reason", reason)
}

func roleAttribute(role types.RunnerRole) attribute.KeyValue {
return attribute.String("ssv.runner.role", role.String())
}

func recordMessage(ctx context.Context) {
messageValidationsCounter.Add(ctx, 1)
}

func recordAcceptedMessage(ctx context.Context, role types.RunnerRole) {
messageValidationsAcceptedCounter.Add(ctx, 1, metric.WithAttributes(roleAttribute(role)))
messageValidationsAcceptedCounter.Add(ctx, 1, metric.WithAttributes(observability.RunnerRoleAttribute(role)))
}

func recordRejectedMessage(ctx context.Context, role types.RunnerRole, reason string) {
messageValidationsRejectedCounter.Add(ctx, 1, metric.WithAttributes(reasonAttribute(reason), roleAttribute(role)))
messageValidationsRejectedCounter.Add(ctx, 1, metric.WithAttributes(reasonAttribute(reason), observability.RunnerRoleAttribute(role)))
}

func recordIgnoredMessage(ctx context.Context, role types.RunnerRole, reason string) {
messageValidationsIgnoredCounter.Add(ctx, 1, metric.WithAttributes(reasonAttribute(reason), roleAttribute(role)))
messageValidationsIgnoredCounter.Add(ctx, 1, metric.WithAttributes(reasonAttribute(reason), observability.RunnerRoleAttribute(role)))
}
7 changes: 5 additions & 2 deletions observability/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

func BeaconRoleAttribute(role types.BeaconRole) attribute.KeyValue {
const eventNameAttrName = "ssv.beacon.role"
return attribute.String(eventNameAttrName, role.String())
return attribute.String("ssv.beacon.role", role.String())
}

func RunnerRoleAttribute(role types.RunnerRole) attribute.KeyValue {
return attribute.String("ssv.runner.role", role.String())
}
9 changes: 6 additions & 3 deletions operator/duties/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ssvlabs/ssv/logging/fields"
"github.com/ssvlabs/ssv/network"
"github.com/ssvlabs/ssv/networkconfig"
"github.com/ssvlabs/ssv/observability"
"github.com/ssvlabs/ssv/operator/duties/dutystore"
"github.com/ssvlabs/ssv/operator/slotticker"
"github.com/ssvlabs/ssv/protocol/v2/types"
Expand Down Expand Up @@ -377,8 +378,8 @@ func (s *Scheduler) ExecuteDuties(ctx context.Context, logger *zap.Logger, dutie
span.AddEvent("late duty execution",
trace.WithAttributes(
attribute.Int64("slot_delay_ms", slotDelay.Milliseconds()),
attribute.String("ssv.beacon.role", duty.Type.String()),
attribute.String("ssv.runner.role", duty.RunnerRole().String())))
observability.BeaconRoleAttribute(duty.Type),
observability.RunnerRoleAttribute(duty.RunnerRole())))
}

slotDelayHistogram.Record(ctx, slotDelay.Seconds())
Expand Down Expand Up @@ -417,7 +418,9 @@ func (s *Scheduler) ExecuteCommitteeDuties(ctx context.Context, logger *zap.Logg
slotDelayHistogram.Record(ctx, slotDelay.Seconds())
go func() {
s.waitOneThirdOrValidBlock(duty.Slot)
committeeDutiesExecutedCounter.Add(ctx, 1, metric.WithAttributes(attribute.String("ssv.runner.role", committee.duty.RunnerRole().String())))
committeeDutiesExecutedCounter.Add(ctx, 1,
metric.WithAttributes(
observability.RunnerRoleAttribute(committee.duty.RunnerRole())))
s.dutyExecutor.ExecuteCommitteeDuty(ctx, logger, committee.id, duty)
}()
}
Expand Down
7 changes: 4 additions & 3 deletions operator/validator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/ssvlabs/ssv/message/validation"
"github.com/ssvlabs/ssv/network"
"github.com/ssvlabs/ssv/networkconfig"
"github.com/ssvlabs/ssv/observability"
operatordatastore "github.com/ssvlabs/ssv/operator/datastore"
"github.com/ssvlabs/ssv/operator/duties"
nodestorage "github.com/ssvlabs/ssv/operator/storage"
Expand Down Expand Up @@ -638,8 +639,8 @@ func (c *controller) ExecuteDuty(ctx context.Context, logger *zap.Logger, duty *
fmt.Sprintf("%s.execute_duty", observabilityNamespace),
trace.WithAttributes(
attribute.Int("ssv.validator.duty.slot", int(duty.Slot)),
attribute.String("ssv.beacon.role", duty.Type.String()),
attribute.String("ssv.runner.role", duty.RunnerRole().String()),
observability.BeaconRoleAttribute(duty.Type),
observability.RunnerRoleAttribute(duty.RunnerRole()),
attribute.String("ssv.validator.pubkey", duty.PubKey.String()),
))
defer span.End()
Expand Down Expand Up @@ -676,7 +677,7 @@ func (c *controller) ExecuteCommitteeDuty(ctx context.Context, logger *zap.Logge
trace.WithAttributes(
attribute.Int("ssv.validator.duty.slot", int(duty.Slot)),
attribute.String("ssv.comittee.id", hex.EncodeToString(committeeID[:])),
attribute.String("ssv.runner.role", duty.RunnerRole().String()),
observability.RunnerRoleAttribute(duty.RunnerRole()),
))
defer span.End()

Expand Down
13 changes: 7 additions & 6 deletions protocol/v2/ssv/runner/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
specqbft "github.com/ssvlabs/ssv-spec/qbft"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/logging/fields"
"github.com/ssvlabs/ssv/observability"
"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
"github.com/ssvlabs/ssv/protocol/v2/qbft/controller"
ssvtypes "github.com/ssvlabs/ssv/protocol/v2/types"
Expand Down Expand Up @@ -88,7 +89,7 @@ func (r *AggregatorRunner) ProcessPreConsensus(ctx context.Context, logger *zap.
}

r.measurements.EndPreConsensus()
preConsensusDurationHistogram.Record(ctx, r.measurements.PreConsensusTime().Seconds(), metric.WithAttributes(roleAttribute(spectypes.RoleAggregator)))
preConsensusDurationHistogram.Record(ctx, r.measurements.PreConsensusTime().Seconds(), metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleAggregator)))

// only 1 root, verified by basePreConsensusMsgProcessing
root := roots[0]
Expand Down Expand Up @@ -145,7 +146,7 @@ func (r *AggregatorRunner) ProcessConsensus(ctx context.Context, logger *zap.Log
}

r.measurements.EndConsensus()
consensusDurationHistogram.Record(ctx, r.measurements.ConsensusTime().Seconds(), metric.WithAttributes(roleAttribute(spectypes.RoleAggregator)))
consensusDurationHistogram.Record(ctx, r.measurements.ConsensusTime().Seconds(), metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleAggregator)))

r.measurements.StartPostConsensus()

Expand Down Expand Up @@ -209,7 +210,7 @@ func (r *AggregatorRunner) ProcessPostConsensus(ctx context.Context, logger *zap
}

r.measurements.EndPostConsensus()
postConsensusDurationHistogram.Record(ctx, r.measurements.PostConsensusTime().Seconds(), metric.WithAttributes(roleAttribute(spectypes.RoleAggregator)))
postConsensusDurationHistogram.Record(ctx, r.measurements.PostConsensusTime().Seconds(), metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleAggregator)))

for _, root := range roots {
sig, err := r.GetState().ReconstructBeaconSig(r.GetState().PostConsensusContainer, root, r.GetShare().ValidatorPubKey[:], r.GetShare().ValidatorIndex)
Expand Down Expand Up @@ -241,7 +242,7 @@ func (r *AggregatorRunner) ProcessPostConsensus(ctx context.Context, logger *zap
start := time.Now()

if err := r.GetBeaconNode().SubmitSignedAggregateSelectionProof(msg); err != nil {
failedSubmissionCounter.Add(ctx, 1, metric.WithAttributes(roleAttribute(spectypes.RoleAggregator)))
failedSubmissionCounter.Add(ctx, 1, metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleAggregator)))

logger.Error("❌ could not submit to Beacon chain reconstructed contribution and proof",
fields.SubmissionTime(time.Since(start)),
Expand All @@ -250,8 +251,8 @@ func (r *AggregatorRunner) ProcessPostConsensus(ctx context.Context, logger *zap
}
r.measurements.EndDutyFlow()
dutyDurationHistogram.Record(ctx, r.measurements.DutyDurationTime().Seconds(),
metric.WithAttributes(roleAttribute(spectypes.RoleAggregator), roundAttribute(r.GetState().RunningInstance.State.Round)))
submissionCounter.Add(ctx, 1, metric.WithAttributes(roleAttribute(spectypes.RoleAggregator)))
metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleAggregator), roundAttribute(r.GetState().RunningInstance.State.Round)))
submissionCounter.Add(ctx, 1, metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleAggregator)))

logger.Debug("✅ successful submitted aggregate",
fields.SubmissionTime(time.Since(start)),
Expand Down
15 changes: 8 additions & 7 deletions protocol/v2/ssv/runner/committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/logging/fields"
"github.com/ssvlabs/ssv/networkconfig"
"github.com/ssvlabs/ssv/observability"
"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
"github.com/ssvlabs/ssv/protocol/v2/qbft/controller"
ssvtypes "github.com/ssvlabs/ssv/protocol/v2/types"
Expand Down Expand Up @@ -88,7 +89,7 @@ func (cr *CommitteeRunner) StartNewDuty(ctx context.Context, logger *zap.Logger,
ctx, span := tracer.Start(ctx,
fmt.Sprintf("%s.runner.start_new_duty", observabilityNamespace),
trace.WithAttributes(
roleAttribute(duty.RunnerRole()),
observability.RunnerRoleAttribute(duty.RunnerRole()),
attribute.Int64("ssv.validator.quorum", int64(quorum)),

Check failure on line 93 in protocol/v2/ssv/runner/committee.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion uint64 -> int64 (gosec)
attribute.Int64("ssv.validator.duty.slot", int64(duty.DutySlot()))))

Check failure on line 94 in protocol/v2/ssv/runner/committee.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion uint64 -> int64 (gosec)
defer span.End()
Expand Down Expand Up @@ -224,7 +225,7 @@ func (cr *CommitteeRunner) ProcessConsensus(ctx context.Context, logger *zap.Log
trace.WithAttributes(
attribute.String("ssv.validator.msg_id", msg.SSVMessage.MsgID.String()),
attribute.Int64("ssv.validator.msg_type", int64(msg.SSVMessage.MsgType)),

Check failure on line 227 in protocol/v2/ssv/runner/committee.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion uint64 -> int64 (gosec)
roleAttribute(msg.SSVMessage.GetID().GetRoleType()),
observability.RunnerRoleAttribute(msg.SSVMessage.GetID().GetRoleType()),
))
defer span.End()

Expand All @@ -242,7 +243,7 @@ func (cr *CommitteeRunner) ProcessConsensus(ctx context.Context, logger *zap.Log
}

cr.measurements.EndConsensus()
consensusDurationHistogram.Record(ctx, cr.measurements.ConsensusTime().Seconds(), metric.WithAttributes(roleAttribute(spectypes.RoleCommittee)))
consensusDurationHistogram.Record(ctx, cr.measurements.ConsensusTime().Seconds(), metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleCommittee)))

cr.measurements.StartPostConsensus()
// decided means consensus is done
Expand All @@ -260,7 +261,7 @@ func (cr *CommitteeRunner) ProcessConsensus(ctx context.Context, logger *zap.Log
span.SetAttributes(
attribute.Int64("ssv.validator.index", int64(duty.ValidatorIndex)),

Check failure on line 262 in protocol/v2/ssv/runner/committee.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion uint64 -> int64 (gosec)
attribute.String("ssv.validator.pubkey", duty.PubKey.String()),
attribute.String("ssv.beacon.role", duty.Type.String()),
observability.BeaconRoleAttribute(duty.Type),
)
if err := cr.DutyGuard.ValidDuty(duty.Type, spectypes.ValidatorPK(duty.PubKey), duty.DutySlot()); err != nil {
eventMsg := "duty is no longer valid"
Expand Down Expand Up @@ -435,7 +436,7 @@ func (cr *CommitteeRunner) ProcessPostConsensus(ctx context.Context, logger *zap
}
eventMsg := "found validators for root"
span.AddEvent(eventMsg, trace.WithAttributes(
attribute.String("ssv.beacon.role", role.String()),
observability.BeaconRoleAttribute(role),
attribute.String("ssv.validator.duty.root", hex.EncodeToString(root[:])),
))
logger.Debug(eventMsg,
Expand Down Expand Up @@ -516,7 +517,7 @@ func (cr *CommitteeRunner) ProcessPostConsensus(ctx context.Context, logger *zap
}

cr.measurements.EndPostConsensus()
postConsensusDurationHistogram.Record(ctx, cr.measurements.PostConsensusTime().Seconds(), metric.WithAttributes(roleAttribute(spectypes.RoleCommittee)))
postConsensusDurationHistogram.Record(ctx, cr.measurements.PostConsensusTime().Seconds(), metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleCommittee)))

logger = logger.With(fields.PostConsensusTime(cr.measurements.PostConsensusTime()))

Expand Down Expand Up @@ -777,7 +778,7 @@ func (cr *CommitteeRunner) executeDuty(ctx context.Context, logger *zap.Logger,
ctx, span := tracer.Start(ctx,
fmt.Sprintf("%s.runner.execute_duty", observabilityNamespace),
trace.WithAttributes(
roleAttribute(duty.RunnerRole()),
observability.RunnerRoleAttribute(duty.RunnerRole()),
attribute.Int64("ssv.validator.duty.slot", int64(duty.DutySlot()))))
defer span.End()

Expand Down
5 changes: 0 additions & 5 deletions protocol/v2/ssv/runner/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"go.opentelemetry.io/otel/metric"

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

Expand Down Expand Up @@ -67,10 +66,6 @@ func metricName(name string) string {
return fmt.Sprintf("%s.%s", observabilityNamespace, name)
}

func roleAttribute(role types.RunnerRole) attribute.KeyValue {
return attribute.String("ssv.runner.role", role.String())
}

func roundAttribute(qbftRound qbft.Round) attribute.KeyValue {
var round int64
r := uint64(qbftRound)
Expand Down
15 changes: 8 additions & 7 deletions protocol/v2/ssv/runner/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
specqbft "github.com/ssvlabs/ssv-spec/qbft"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/logging/fields"
"github.com/ssvlabs/ssv/observability"
"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
"github.com/ssvlabs/ssv/protocol/v2/qbft/controller"
ssvtypes "github.com/ssvlabs/ssv/protocol/v2/types"
Expand Down Expand Up @@ -103,7 +104,7 @@ func (r *ProposerRunner) ProcessPreConsensus(ctx context.Context, logger *zap.Lo
}

r.measurements.EndPreConsensus()
preConsensusDurationHistogram.Record(ctx, r.measurements.PreConsensusTime().Seconds(), metric.WithAttributes(roleAttribute(spectypes.RoleProposer)))
preConsensusDurationHistogram.Record(ctx, r.measurements.PreConsensusTime().Seconds(), metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleProposer)))

// only 1 root, verified in basePreConsensusMsgProcessing
root := roots[0]
Expand Down Expand Up @@ -167,7 +168,7 @@ func (r *ProposerRunner) ProcessConsensus(ctx context.Context, logger *zap.Logge
}

r.measurements.EndConsensus()
consensusDurationHistogram.Record(ctx, r.measurements.ConsensusTime().Seconds(), metric.WithAttributes(roleAttribute(spectypes.RoleProposer)))
consensusDurationHistogram.Record(ctx, r.measurements.ConsensusTime().Seconds(), metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleProposer)))

r.measurements.StartPostConsensus()

Expand Down Expand Up @@ -255,7 +256,7 @@ func (r *ProposerRunner) ProcessPostConsensus(ctx context.Context, logger *zap.L
copy(specSig[:], sig)

r.measurements.EndPostConsensus()
postConsensusDurationHistogram.Record(ctx, r.measurements.PostConsensusTime().Seconds(), metric.WithAttributes(roleAttribute(spectypes.RoleProposer)))
postConsensusDurationHistogram.Record(ctx, r.measurements.PostConsensusTime().Seconds(), metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleProposer)))

logger.Debug("🧩 reconstructed partial post consensus signatures proposer",
zap.Uint64s("signers", getPostConsensusProposerSigners(r.GetState(), root)),
Expand Down Expand Up @@ -294,7 +295,7 @@ func (r *ProposerRunner) ProcessPostConsensus(ctx context.Context, logger *zap.L
)

if err := r.GetBeaconNode().SubmitBlindedBeaconBlock(vBlindedBlk, specSig); err != nil {
failedSubmissionCounter.Add(ctx, 1, metric.WithAttributes(roleAttribute(spectypes.RoleProposer)))
failedSubmissionCounter.Add(ctx, 1, metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleProposer)))
logger.Error("❌ could not submit blinded Beacon block",
fields.SubmissionTime(time.Since(start)),
zap.Error(err))
Expand All @@ -312,7 +313,7 @@ func (r *ProposerRunner) ProcessPostConsensus(ctx context.Context, logger *zap.L
)

if err := r.GetBeaconNode().SubmitBeaconBlock(vBlk, specSig); err != nil {
failedSubmissionCounter.Add(ctx, 1, metric.WithAttributes(roleAttribute(spectypes.RoleProposer)))
failedSubmissionCounter.Add(ctx, 1, metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleProposer)))
logger.Error("❌ could not submit Beacon block",
fields.SubmissionTime(time.Since(start)),
zap.Error(err))
Expand All @@ -322,8 +323,8 @@ func (r *ProposerRunner) ProcessPostConsensus(ctx context.Context, logger *zap.L

r.measurements.EndDutyFlow()
dutyDurationHistogram.Record(ctx, r.measurements.DutyDurationTime().Seconds(),
metric.WithAttributes(roleAttribute(spectypes.RoleProposer), roundAttribute(r.GetState().RunningInstance.State.Round)))
submissionCounter.Add(ctx, 1, metric.WithAttributes(roleAttribute(spectypes.RoleProposer)))
metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleProposer), roundAttribute(r.GetState().RunningInstance.State.Round)))
submissionCounter.Add(ctx, 1, metric.WithAttributes(observability.RunnerRoleAttribute(spectypes.RoleProposer)))

logger.Info("✅ successfully submitted block proposal",
fields.Slot(validatorConsensusData.Duty.Slot),
Expand Down
5 changes: 3 additions & 2 deletions protocol/v2/ssv/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

specqbft "github.com/ssvlabs/ssv-spec/qbft"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/observability"
"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
"github.com/ssvlabs/ssv/protocol/v2/qbft/controller"
"github.com/ssvlabs/ssv/protocol/v2/ssv"
Expand Down Expand Up @@ -150,7 +151,7 @@ func (b *BaseRunner) baseStartNewDuty(ctx context.Context, logger *zap.Logger, r
ctx, span := tracer.Start(ctx,
fmt.Sprintf("%s.base_runner.start_new_duty", observabilityNamespace),
trace.WithAttributes(
roleAttribute(duty.RunnerRole()),
observability.RunnerRoleAttribute(duty.RunnerRole()),
attribute.Int64("ssv.validator.quorum", int64(quorum)),
attribute.Int64("ssv.validator.duty.slot", int64(duty.DutySlot()))))
defer span.End()
Expand Down Expand Up @@ -314,7 +315,7 @@ func (b *BaseRunner) decide(ctx context.Context, logger *zap.Logger, runner Runn
ctx, span := tracer.Start(ctx,
fmt.Sprintf("%s.base_runner.decide", observabilityNamespace),
trace.WithAttributes(
roleAttribute(runner.GetBaseRunner().RunnerRoleType),
observability.RunnerRoleAttribute(runner.GetBaseRunner().RunnerRoleType),
attribute.Int64("ssv.validator.duty.slot", int64(slot))))
defer span.End()

Expand Down
Loading

0 comments on commit f117ef6

Please sign in to comment.