From 9980ca3b7ebe49ff798d83df9b86b4e67ef3d4cc Mon Sep 17 00:00:00 2001 From: Benoit Perroud Date: Tue, 9 Mar 2021 22:13:11 +0100 Subject: [PATCH] Add metrics per keys for next scheduled attestation and proposal (#8583) * Add metrics per keys for next scheduled attestation and proposal * Found a better place where to update the counters * Wrap with emitAccountMetrics flag --- validator/client/metrics.go | 22 ++++++++++++++++++++++ validator/client/validator.go | 10 ++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/validator/client/metrics.go b/validator/client/metrics.go index e8b4f0b48acb..afaa5828f066 100644 --- a/validator/client/metrics.go +++ b/validator/client/metrics.go @@ -172,6 +172,28 @@ var ( "pubkey", }, ) + // ValidatorNextAttestationSlotGaugeVec used to track validator statuses by public key. + ValidatorNextAttestationSlotGaugeVec = promauto.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: "validator", + Name: "next_attestation_slot", + Help: "validator next scheduled attestation slot", + }, + []string{ + "pubkey", + }, + ) + // ValidatorNextProposalSlotGaugeVec used to track validator statuses by public key. + ValidatorNextProposalSlotGaugeVec = promauto.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: "validator", + Name: "next_proposal_slot", + Help: "validator next scheduled proposal slot", + }, + []string{ + "pubkey", + }, + ) ) // LogValidatorGainsAndLosses logs important metrics related to this validator client's diff --git a/validator/client/validator.go b/validator/client/validator.go index 69f7712045ec..24817bfe0304 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -634,9 +634,9 @@ func (v *validator) logDuties(slot types.Slot, duties []*ethpb.DutiesResponse_Du slotOffset := slot - (slot % params.BeaconConfig().SlotsPerEpoch) var totalAttestingKeys uint64 for _, duty := range duties { + validatorNotTruncatedKey := fmt.Sprintf("%#x", duty.PublicKey) if v.emitAccountMetrics { - fmtKey := fmt.Sprintf("%#x", duty.PublicKey) - ValidatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(duty.Status)) + ValidatorStatusesGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(duty.Status)) } // Only interested in validators who are attesting/proposing. @@ -652,6 +652,9 @@ func (v *validator) logDuties(slot types.Slot, duties []*ethpb.DutiesResponse_Du } else { attesterKeys[duty.AttesterSlot-slotOffset] = append(attesterKeys[duty.AttesterSlot-slotOffset], validatorKey) totalAttestingKeys++ + if v.emitAccountMetrics { + ValidatorNextAttestationSlotGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(duty.AttesterSlot)) + } } for _, proposerSlot := range duty.ProposerSlots { @@ -661,6 +664,9 @@ func (v *validator) logDuties(slot types.Slot, duties []*ethpb.DutiesResponse_Du } else { proposerKeys[proposerIndex] = validatorKey } + if v.emitAccountMetrics { + ValidatorNextProposalSlotGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(proposerSlot)) + } } } for i := types.Slot(0); i < params.BeaconConfig().SlotsPerEpoch; i++ {