From 4dd658d28bc8b09909042342682e2d6df0d8f7fc Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 10 Mar 2020 12:10:07 -0500 Subject: [PATCH 1/7] added in slasher metrics --- slasher/beaconclient/BUILD.bazel | 3 +++ slasher/beaconclient/metrics.go | 13 +++++++++++ slasher/cache/span_cache.go | 2 +- slasher/db/kv/BUILD.bazel | 2 ++ slasher/db/kv/spanner.go | 17 +++++++++++++++ slasher/detection/BUILD.bazel | 3 +++ slasher/detection/attestations/BUILD.bazel | 2 ++ slasher/detection/attestations/spanner.go | 14 +++++++++++- slasher/detection/metrics.go | 25 ++++++++++++++++++++++ 9 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 slasher/beaconclient/metrics.go create mode 100644 slasher/detection/metrics.go diff --git a/slasher/beaconclient/BUILD.bazel b/slasher/beaconclient/BUILD.bazel index 45763f9988f4..408e3849cc1e 100644 --- a/slasher/beaconclient/BUILD.bazel +++ b/slasher/beaconclient/BUILD.bazel @@ -5,6 +5,7 @@ go_library( srcs = [ "chain_data.go", "historical_data_retrieval.go", + "metrics.go", "receivers.go", "service.go", "submit.go", @@ -20,6 +21,8 @@ go_library( "@com_github_grpc_ecosystem_go_grpc_middleware//tracing/opentracing:go_default_library", "@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library", "@com_github_pkg_errors//:go_default_library", + "@com_github_prometheus_client_golang//prometheus:go_default_library", + "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@io_opencensus_go//plugin/ocgrpc:go_default_library", diff --git a/slasher/beaconclient/metrics.go b/slasher/beaconclient/metrics.go new file mode 100644 index 000000000000..4176eadb3c35 --- /dev/null +++ b/slasher/beaconclient/metrics.go @@ -0,0 +1,13 @@ +package beaconclient + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +var ( + slasherNumAttestationsReceived = promauto.NewCounter(prometheus.CounterOpts{ + Name: "slasher_num_attestations_received", + Help: "The # of attestations received by slasher", + }) +) diff --git a/slasher/cache/span_cache.go b/slasher/cache/span_cache.go index 4245727b2e5a..1202ef8353b3 100644 --- a/slasher/cache/span_cache.go +++ b/slasher/cache/span_cache.go @@ -10,7 +10,7 @@ import ( var ( // epochSpansCacheSize defines the max number of epoch spans the cache can hold. epochSpansCacheSize = 256 - // Metrics + // Metrics for the span cache. epochSpansCacheHit = promauto.NewCounter(prometheus.CounterOpts{ Name: "epoch_spans_cache_hit", Help: "The total number of cache hits on the epoch spans cache.", diff --git a/slasher/db/kv/BUILD.bazel b/slasher/db/kv/BUILD.bazel index 71e9db91b01e..021c7c2118b5 100644 --- a/slasher/db/kv/BUILD.bazel +++ b/slasher/db/kv/BUILD.bazel @@ -25,6 +25,8 @@ go_library( "@com_github_boltdb_bolt//:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_pkg_errors//:go_default_library", + "@com_github_prometheus_client_golang//prometheus:go_default_library", + "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@io_opencensus_go//trace:go_default_library", diff --git a/slasher/db/kv/spanner.go b/slasher/db/kv/spanner.go index 8774aec351c3..9b1fdece328a 100644 --- a/slasher/db/kv/spanner.go +++ b/slasher/db/kv/spanner.go @@ -5,6 +5,8 @@ import ( "github.com/boltdb/bolt" "github.com/pkg/errors" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/slasher/detection/attestations/types" @@ -18,6 +20,21 @@ import ( var highestObservedEpoch uint64 var lowestObservedEpoch = params.BeaconConfig().FarFutureEpoch +var ( + slasherLowestObservedEpoch = promauto.NewCounter(prometheus.CounterOpts{ + Name: "slasher_lowest_observed_epoch", + Help: "The lowest epoch number seen by slasher", + }) + slasherHighestObservedEpoch = promauto.NewCounter(prometheus.CounterOpts{ + Name: "slasher_highest_observed_epoch", + Help: "The highest epoch number seen by slasher", + }) + epochSpansCacheEvictions = promauto.NewCounter(prometheus.CounterOpts{ + Name: "epoch_spans_cache_evictions", + Help: "The number of cache evictions seen by slasher", + }) +) + // This function defines a function which triggers upon a span map being // evicted from the cache. It allows us to persist the span map by the epoch value // to the database itself in the validatorsMinMaxSpanBucket. diff --git a/slasher/detection/BUILD.bazel b/slasher/detection/BUILD.bazel index c2bf453f2a69..2981c1a83f40 100644 --- a/slasher/detection/BUILD.bazel +++ b/slasher/detection/BUILD.bazel @@ -5,6 +5,7 @@ go_library( srcs = [ "detect.go", "listeners.go", + "metrics.go", "service.go", ], importpath = "github.com/prysmaticlabs/prysm/slasher/detection", @@ -19,6 +20,8 @@ go_library( "//slasher/detection/attestations/types:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_pkg_errors//:go_default_library", + "@com_github_prometheus_client_golang//prometheus:go_default_library", + "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@io_opencensus_go//trace:go_default_library", diff --git a/slasher/detection/attestations/BUILD.bazel b/slasher/detection/attestations/BUILD.bazel index 64a677bc913e..1a5e810e9101 100644 --- a/slasher/detection/attestations/BUILD.bazel +++ b/slasher/detection/attestations/BUILD.bazel @@ -14,6 +14,8 @@ go_library( "//slasher/db:go_default_library", "//slasher/detection/attestations/iface:go_default_library", "//slasher/detection/attestations/types:go_default_library", + "@com_github_prometheus_client_golang//prometheus:go_default_library", + "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@io_opencensus_go//trace:go_default_library", ], diff --git a/slasher/detection/attestations/spanner.go b/slasher/detection/attestations/spanner.go index fea8c87f104d..70d9d361745a 100644 --- a/slasher/detection/attestations/spanner.go +++ b/slasher/detection/attestations/spanner.go @@ -4,6 +4,8 @@ import ( "context" "fmt" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" @@ -13,6 +15,17 @@ import ( "go.opencensus.io/trace" ) +var ( + latestMinSpanDistanceObserved = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "latest_min_span_distance_observed", + Help: "The latest distance between target - source observed for min spans", + }) + latestMaxSpanDistanceObserved = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "latest_max_span_distance_observed", + Help: "The latest distance between target - source observed for max spans", + }) +) + // We look back 128 epochs when updating min/max spans // for incoming attestations. // TODO(#5040): Remove lookback and handle min spans properly. @@ -110,7 +123,6 @@ func (s *SpanDetector) DetectSlashingsForAttestation( } } - // Clear out any duplicate results. keys := make(map[[32]byte]bool) var detectionList []*types.DetectionResult diff --git a/slasher/detection/metrics.go b/slasher/detection/metrics.go new file mode 100644 index 000000000000..9000069be671 --- /dev/null +++ b/slasher/detection/metrics.go @@ -0,0 +1,25 @@ +package detection + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +var ( + doubleProposalsDetected = promauto.NewCounter(prometheus.CounterOpts{ + Name: "double_proposals_detected", + Help: "The # of double propose slashable events detected", + }) + doubleVotesDetected = promauto.NewCounter(prometheus.CounterOpts{ + Name: "double_votes_detected", + Help: "The # of double vote slashable events detected", + }) + surroundingVotesDetected = promauto.NewCounter(prometheus.CounterOpts{ + Name: "surrounding_votes_detected", + Help: "The # of surrounding slashable events detected", + }) + surroundedVotesDetected = promauto.NewCounter(prometheus.CounterOpts{ + Name: "surrounded_votes_detected", + Help: "The # of surrounded slashable events detected", + }) +) From 9c80eb63738e569582532fdf71a9912368f2996b Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 10 Mar 2020 13:50:21 -0500 Subject: [PATCH 2/7] add in prom bolt metrics for slasher --- slasher/beaconclient/receivers.go | 5 +++-- slasher/db/kv/BUILD.bazel | 1 + slasher/db/kv/kv.go | 13 +++++++++++++ slasher/db/kv/spanner.go | 7 +++++-- slasher/detection/attestations/spanner.go | 2 ++ slasher/detection/detect.go | 3 +++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/slasher/beaconclient/receivers.go b/slasher/beaconclient/receivers.go index 74b6760d2d58..c54bbbe5f8d4 100644 --- a/slasher/beaconclient/receivers.go +++ b/slasher/beaconclient/receivers.go @@ -79,7 +79,7 @@ func (bs *Service) collectReceivedAttestations(ctx context.Context) { defer span.End() var atts []*ethpb.IndexedAttestation - ticker := time.NewTicker(2*time.Second) + ticker := time.NewTicker(2 * time.Second) for { select { case <-ticker.C: @@ -95,6 +95,7 @@ func (bs *Service) collectReceivedAttestations(ctx context.Context) { continue } log.Infof("%d attestations for slot %d saved to slasher DB", len(collectedAtts), collectedAtts[0].Data.Slot) + slasherNumAttestationsReceived.Add(float64(len(collectedAtts))) // After saving, we send the received attestation over the attestation feed. for _, att := range collectedAtts { @@ -108,4 +109,4 @@ func (bs *Service) collectReceivedAttestations(ctx context.Context) { return } } -} \ No newline at end of file +} diff --git a/slasher/db/kv/BUILD.bazel b/slasher/db/kv/BUILD.bazel index 021c7c2118b5..f6fe6cb8837e 100644 --- a/slasher/db/kv/BUILD.bazel +++ b/slasher/db/kv/BUILD.bazel @@ -24,6 +24,7 @@ go_library( "//slasher/detection/attestations/types:go_default_library", "@com_github_boltdb_bolt//:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", + "@com_github_mdlayher_prombolt//:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", diff --git a/slasher/db/kv/kv.go b/slasher/db/kv/kv.go index 87d2b8efd223..d31ada9c1b66 100644 --- a/slasher/db/kv/kv.go +++ b/slasher/db/kv/kv.go @@ -6,7 +6,10 @@ import ( "time" "github.com/boltdb/bolt" + "github.com/mdlayher/prombolt" "github.com/pkg/errors" + "github.com/prometheus/client_golang/prometheus" + "github.com/prysmaticlabs/prysm/slasher/cache" ) @@ -30,6 +33,7 @@ type Config struct { // Close closes the underlying boltdb database. func (db *Store) Close() error { + prometheus.Unregister(createBoltCollector(db.db)) return db.db.Close() } @@ -53,6 +57,7 @@ func (db *Store) ClearDB() error { if _, err := os.Stat(db.databasePath); os.IsNotExist(err) { return nil } + prometheus.Unregister(createBoltCollector(db.db)) return os.Remove(db.databasePath) } @@ -108,6 +113,9 @@ func NewKVStore(dirPath string, cfg *Config) (*Store, error) { }); err != nil { return nil, err } + + err = prometheus.Register(createBoltCollector(kv.db)) + return kv, err } @@ -120,3 +128,8 @@ func (db *Store) Size() (int64, error) { }) return size, err } + +// createBoltCollector returns a prometheus collector specifically configured for boltdb. +func createBoltCollector(db *bolt.DB) prometheus.Collector { + return prombolt.New("boltDB", db) +} diff --git a/slasher/db/kv/spanner.go b/slasher/db/kv/spanner.go index 9b1fdece328a..813925880d47 100644 --- a/slasher/db/kv/spanner.go +++ b/slasher/db/kv/spanner.go @@ -21,11 +21,11 @@ var highestObservedEpoch uint64 var lowestObservedEpoch = params.BeaconConfig().FarFutureEpoch var ( - slasherLowestObservedEpoch = promauto.NewCounter(prometheus.CounterOpts{ + slasherLowestObservedEpoch = promauto.NewGauge(prometheus.GaugeOpts{ Name: "slasher_lowest_observed_epoch", Help: "The lowest epoch number seen by slasher", }) - slasherHighestObservedEpoch = promauto.NewCounter(prometheus.CounterOpts{ + slasherHighestObservedEpoch = promauto.NewGauge(prometheus.GaugeOpts{ Name: "slasher_highest_observed_epoch", Help: "The highest epoch number seen by slasher", }) @@ -62,6 +62,7 @@ func persistSpanMapsOnEviction(db *Store) func(key interface{}, value interface{ return err } } + epochSpansCacheEvictions.Inc() return nil }) if err != nil { @@ -332,9 +333,11 @@ func (db *Store) findOrLoadEpochInCache(ctx context.Context, epoch uint64) (map[ func setObservedEpochs(epoch uint64) { if epoch > highestObservedEpoch { + slasherHighestObservedEpoch.Set(float64(epoch)) highestObservedEpoch = epoch } if epoch < lowestObservedEpoch { + slasherLowestObservedEpoch.Set(float64(epoch)) lowestObservedEpoch = epoch } } diff --git a/slasher/detection/attestations/spanner.go b/slasher/detection/attestations/spanner.go index 70d9d361745a..c49aa63a7c80 100644 --- a/slasher/detection/attestations/spanner.go +++ b/slasher/detection/attestations/spanner.go @@ -203,6 +203,7 @@ func (s *SpanDetector) updateMinSpan(ctx context.Context, att *ethpb.IndexedAtte if int(lowestEpoch) <= 0 { lowestEpoch = 0 } + latestMinSpanDistanceObserved.Set(float64(att.Data.Target.Epoch - att.Data.Source.Epoch)) for epoch := source - 1; epoch >= lowestEpoch; epoch-- { spanMap, err := s.slasherDB.EpochSpansMap(ctx, epoch) @@ -244,6 +245,7 @@ func (s *SpanDetector) updateMaxSpan(ctx context.Context, att *ethpb.IndexedAtte defer traceSpan.End() source := att.Data.Source.Epoch target := att.Data.Target.Epoch + latestMaxSpanDistanceObserved.Set(float64(source - target)) valIndices := make([]uint64, len(att.AttestingIndices)) copy(valIndices, att.AttestingIndices) for epoch := source + 1; epoch < target; epoch++ { diff --git a/slasher/detection/detect.go b/slasher/detection/detect.go index ec60d974ff10..fc22da3d946a 100644 --- a/slasher/detection/detect.go +++ b/slasher/detection/detect.go @@ -76,6 +76,7 @@ func (ds *Service) detectDoubleVote( } if isDoubleVote(incomingAtt, att) { + doubleVotesDetected.Inc() return ðpb.AttesterSlashing{ Attestation_1: incomingAtt, Attestation_2: att, @@ -114,11 +115,13 @@ func (ds *Service) detectSurroundVotes( // Slashings must be submitted as the incoming attestation surrounding the saved attestation. // So we swap the order if needed. if isSurrounding(incomingAtt, att) { + surroundingVotesDetected.Inc() return ðpb.AttesterSlashing{ Attestation_1: incomingAtt, Attestation_2: att, }, nil } else if isSurrounded(incomingAtt, att) { + surroundedVotesDetected.Inc() return ðpb.AttesterSlashing{ Attestation_1: att, Attestation_2: incomingAtt, From 68e42429eea990af0553ceea145e4e2f7a177a7e Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 10 Mar 2020 13:52:23 -0500 Subject: [PATCH 3/7] imports --- slasher/db/kv/kv.go | 1 - 1 file changed, 1 deletion(-) diff --git a/slasher/db/kv/kv.go b/slasher/db/kv/kv.go index d31ada9c1b66..2a01f4f3fcd2 100644 --- a/slasher/db/kv/kv.go +++ b/slasher/db/kv/kv.go @@ -9,7 +9,6 @@ import ( "github.com/mdlayher/prombolt" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" - "github.com/prysmaticlabs/prysm/slasher/cache" ) From 78da3c2c701202ab6287b446b293435cf8ed97e6 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 10 Mar 2020 14:14:18 -0500 Subject: [PATCH 4/7] include all metrics --- beacon-chain/operations/slashings/BUILD.bazel | 3 ++ beacon-chain/operations/slashings/metrics.go | 45 +++++++++++++++++++ beacon-chain/operations/slashings/service.go | 11 +++++ 3 files changed, 59 insertions(+) create mode 100644 beacon-chain/operations/slashings/metrics.go diff --git a/beacon-chain/operations/slashings/BUILD.bazel b/beacon-chain/operations/slashings/BUILD.bazel index 74f1e8788e44..bcea792ed694 100644 --- a/beacon-chain/operations/slashings/BUILD.bazel +++ b/beacon-chain/operations/slashings/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "go_default_library", srcs = [ "doc.go", + "metrics.go", "service.go", "types.go", ], @@ -14,6 +15,8 @@ go_library( "//beacon-chain/state:go_default_library", "//shared/params:go_default_library", "//shared/sliceutil:go_default_library", + "@com_github_prometheus_client_golang//prometheus:go_default_library", + "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", ], ) diff --git a/beacon-chain/operations/slashings/metrics.go b/beacon-chain/operations/slashings/metrics.go new file mode 100644 index 000000000000..b2cf5a016ac8 --- /dev/null +++ b/beacon-chain/operations/slashings/metrics.go @@ -0,0 +1,45 @@ +package slashings + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +var ( + numPendingAttesterSlashings = promauto.NewGauge( + prometheus.GaugeOpts{ + Name: "num_pending_attester_slashings", + Help: "Number of pending attester slashings in the pool", + }, + ) + numAttesterSlashingsIncluded = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "num_attester_slashings_included", + Help: "Number of attester slashings included in blocks", + }, + ) + attesterSlashingReattempts = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "attester_slashing_reattempts", + Help: "Times an attester slashing for an already slashed validator is received", + }, + ) + numPendingProposerSlashings = promauto.NewGauge( + prometheus.GaugeOpts{ + Name: "num_pending_proposer_slashings", + Help: "Number of pending proposer slashings in the pool", + }, + ) + numProposerSlashingsIncluded = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "num_proposer_slashings_included", + Help: "Number of proposer slashings included in blocks", + }, + ) + proposerSlashingReattempts = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "proposer_slashing_reattempts", + Help: "Times a proposer slashing for an already slashed validator is received", + }, + ) +) diff --git a/beacon-chain/operations/slashings/service.go b/beacon-chain/operations/slashings/service.go index eb6cd9f6f6f0..f9543e3bfd24 100644 --- a/beacon-chain/operations/slashings/service.go +++ b/beacon-chain/operations/slashings/service.go @@ -27,6 +27,9 @@ func (p *Pool) PendingAttesterSlashings() []*ethpb.AttesterSlashing { p.lock.RLock() defer p.lock.RUnlock() + // Update prom metric. + numPendingAttesterSlashings.Set(float64(len(p.pendingAttesterSlashing))) + included := make(map[uint64]bool) pending := make([]*ethpb.AttesterSlashing, 0, params.BeaconConfig().MaxAttesterSlashings) for i, slashing := range p.pendingAttesterSlashing { @@ -52,6 +55,10 @@ func (p *Pool) PendingAttesterSlashings() []*ethpb.AttesterSlashing { func (p *Pool) PendingProposerSlashings() []*ethpb.ProposerSlashing { p.lock.RLock() defer p.lock.RUnlock() + + // Update prom metric. + numPendingProposerSlashings.Set(float64(len(p.pendingProposerSlashing))) + pending := make([]*ethpb.ProposerSlashing, 0, params.BeaconConfig().MaxProposerSlashings) for i, slashing := range p.pendingProposerSlashing { if i >= int(params.BeaconConfig().MaxProposerSlashings) { @@ -79,6 +86,7 @@ func (p *Pool) InsertAttesterSlashing(state *beaconstate.BeaconState, slashing * // has been recently included in the pool of slashings, do not process this new // slashing. if !ok { + attesterSlashingReattempts.Inc() return fmt.Errorf("validator at index %d cannot be slashed", val) } @@ -119,6 +127,7 @@ func (p *Pool) InsertProposerSlashing(state *beaconstate.BeaconState, slashing * // has been recently included in the pool of slashings, do not process this new // slashing. if !ok { + proposerSlashingReattempts.Inc() return fmt.Errorf("validator at index %d cannot be slashed", idx) } @@ -154,6 +163,7 @@ func (p *Pool) MarkIncludedAttesterSlashing(as *ethpb.AttesterSlashing) { p.pendingAttesterSlashing = append(p.pendingAttesterSlashing[:i], p.pendingAttesterSlashing[i+1:]...) } p.included[val] = true + numAttesterSlashingsIncluded.Inc() } } @@ -170,6 +180,7 @@ func (p *Pool) MarkIncludedProposerSlashing(ps *ethpb.ProposerSlashing) { p.pendingProposerSlashing = append(p.pendingProposerSlashing[:i], p.pendingProposerSlashing[i+1:]...) } p.included[ps.ProposerIndex] = true + numProposerSlashingsIncluded.Inc() } // this function checks a few items about a validator before proceeding with inserting From 5b660024d5c96855cf166bd37ed13ac5d06cab2c Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 10 Mar 2020 14:22:22 -0500 Subject: [PATCH 5/7] no dup bolt collector --- slasher/db/kv/BUILD.bazel | 1 - slasher/db/kv/kv.go | 11 ----------- 2 files changed, 12 deletions(-) diff --git a/slasher/db/kv/BUILD.bazel b/slasher/db/kv/BUILD.bazel index f6fe6cb8837e..021c7c2118b5 100644 --- a/slasher/db/kv/BUILD.bazel +++ b/slasher/db/kv/BUILD.bazel @@ -24,7 +24,6 @@ go_library( "//slasher/detection/attestations/types:go_default_library", "@com_github_boltdb_bolt//:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", - "@com_github_mdlayher_prombolt//:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", diff --git a/slasher/db/kv/kv.go b/slasher/db/kv/kv.go index 2a01f4f3fcd2..9dbce5af9e65 100644 --- a/slasher/db/kv/kv.go +++ b/slasher/db/kv/kv.go @@ -6,9 +6,7 @@ import ( "time" "github.com/boltdb/bolt" - "github.com/mdlayher/prombolt" "github.com/pkg/errors" - "github.com/prometheus/client_golang/prometheus" "github.com/prysmaticlabs/prysm/slasher/cache" ) @@ -32,7 +30,6 @@ type Config struct { // Close closes the underlying boltdb database. func (db *Store) Close() error { - prometheus.Unregister(createBoltCollector(db.db)) return db.db.Close() } @@ -56,7 +53,6 @@ func (db *Store) ClearDB() error { if _, err := os.Stat(db.databasePath); os.IsNotExist(err) { return nil } - prometheus.Unregister(createBoltCollector(db.db)) return os.Remove(db.databasePath) } @@ -113,8 +109,6 @@ func NewKVStore(dirPath string, cfg *Config) (*Store, error) { return nil, err } - err = prometheus.Register(createBoltCollector(kv.db)) - return kv, err } @@ -127,8 +121,3 @@ func (db *Store) Size() (int64, error) { }) return size, err } - -// createBoltCollector returns a prometheus collector specifically configured for boltdb. -func createBoltCollector(db *bolt.DB) prometheus.Collector { - return prombolt.New("boltDB", db) -} From 815eaa8855d4c3d31ee37af3c744f76d6867a845 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 10 Mar 2020 14:24:45 -0500 Subject: [PATCH 6/7] Update slasher/detection/attestations/spanner.go Co-Authored-By: Ivan Martinez --- slasher/detection/attestations/spanner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slasher/detection/attestations/spanner.go b/slasher/detection/attestations/spanner.go index c49aa63a7c80..dee89c0df4b7 100644 --- a/slasher/detection/attestations/spanner.go +++ b/slasher/detection/attestations/spanner.go @@ -245,7 +245,7 @@ func (s *SpanDetector) updateMaxSpan(ctx context.Context, att *ethpb.IndexedAtte defer traceSpan.End() source := att.Data.Source.Epoch target := att.Data.Target.Epoch - latestMaxSpanDistanceObserved.Set(float64(source - target)) + latestMaxSpanDistanceObserved.Set(float64(target-source)) valIndices := make([]uint64, len(att.AttestingIndices)) copy(valIndices, att.AttestingIndices) for epoch := source + 1; epoch < target; epoch++ { From 7adc6647603721dff23149591cb79995f4a12c05 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 10 Mar 2020 14:28:31 -0500 Subject: [PATCH 7/7] naming best practices for prom, thx Terence --- beacon-chain/operations/slashings/metrics.go | 8 ++++---- slasher/beaconclient/metrics.go | 2 +- slasher/db/kv/spanner.go | 2 +- slasher/detection/metrics.go | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/beacon-chain/operations/slashings/metrics.go b/beacon-chain/operations/slashings/metrics.go index b2cf5a016ac8..1ecaea787f18 100644 --- a/beacon-chain/operations/slashings/metrics.go +++ b/beacon-chain/operations/slashings/metrics.go @@ -14,13 +14,13 @@ var ( ) numAttesterSlashingsIncluded = promauto.NewCounter( prometheus.CounterOpts{ - Name: "num_attester_slashings_included", + Name: "attester_slashings_included_total", Help: "Number of attester slashings included in blocks", }, ) attesterSlashingReattempts = promauto.NewCounter( prometheus.CounterOpts{ - Name: "attester_slashing_reattempts", + Name: "attester_slashing_reattempts_total", Help: "Times an attester slashing for an already slashed validator is received", }, ) @@ -32,13 +32,13 @@ var ( ) numProposerSlashingsIncluded = promauto.NewCounter( prometheus.CounterOpts{ - Name: "num_proposer_slashings_included", + Name: "proposer_slashings_included_total", Help: "Number of proposer slashings included in blocks", }, ) proposerSlashingReattempts = promauto.NewCounter( prometheus.CounterOpts{ - Name: "proposer_slashing_reattempts", + Name: "proposer_slashing_reattempts_total", Help: "Times a proposer slashing for an already slashed validator is received", }, ) diff --git a/slasher/beaconclient/metrics.go b/slasher/beaconclient/metrics.go index 4176eadb3c35..d445413e50f2 100644 --- a/slasher/beaconclient/metrics.go +++ b/slasher/beaconclient/metrics.go @@ -7,7 +7,7 @@ import ( var ( slasherNumAttestationsReceived = promauto.NewCounter(prometheus.CounterOpts{ - Name: "slasher_num_attestations_received", + Name: "slasher_attestations_received_total", Help: "The # of attestations received by slasher", }) ) diff --git a/slasher/db/kv/spanner.go b/slasher/db/kv/spanner.go index 813925880d47..bbca40546037 100644 --- a/slasher/db/kv/spanner.go +++ b/slasher/db/kv/spanner.go @@ -30,7 +30,7 @@ var ( Help: "The highest epoch number seen by slasher", }) epochSpansCacheEvictions = promauto.NewCounter(prometheus.CounterOpts{ - Name: "epoch_spans_cache_evictions", + Name: "epoch_spans_cache_evictions_total", Help: "The number of cache evictions seen by slasher", }) ) diff --git a/slasher/detection/metrics.go b/slasher/detection/metrics.go index 9000069be671..724bdb3eb103 100644 --- a/slasher/detection/metrics.go +++ b/slasher/detection/metrics.go @@ -7,19 +7,19 @@ import ( var ( doubleProposalsDetected = promauto.NewCounter(prometheus.CounterOpts{ - Name: "double_proposals_detected", + Name: "double_proposals_detected_total", Help: "The # of double propose slashable events detected", }) doubleVotesDetected = promauto.NewCounter(prometheus.CounterOpts{ - Name: "double_votes_detected", + Name: "double_votes_detected_total", Help: "The # of double vote slashable events detected", }) surroundingVotesDetected = promauto.NewCounter(prometheus.CounterOpts{ - Name: "surrounding_votes_detected", + Name: "surrounding_votes_detected_total", Help: "The # of surrounding slashable events detected", }) surroundedVotesDetected = promauto.NewCounter(prometheus.CounterOpts{ - Name: "surrounded_votes_detected", + Name: "surrounded_votes_detected_total", Help: "The # of surrounded slashable events detected", }) )