From ccbbb2f8d6445a810ed49a1d901d1793bf56d4e5 Mon Sep 17 00:00:00 2001 From: Jingyi Hu Date: Thu, 5 Sep 2019 15:40:06 -0700 Subject: [PATCH] mvcc: add store revision metrics Add experimental metrics etcd_debugging_mvcc_current_revision and etcd_debugging_mvcc_compact_revision. --- mvcc/kvstore.go | 44 +++++++++++++++++++++++++++++++------------- mvcc/metrics.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 13 deletions(-) diff --git a/mvcc/kvstore.go b/mvcc/kvstore.go index 27c50db09b3..c2ef4b252a5 100644 --- a/mvcc/kvstore.go +++ b/mvcc/kvstore.go @@ -355,19 +355,7 @@ func (s *store) Restore(b backend.Backend) error { } func (s *store) restore() error { - b := s.b - reportDbTotalSizeInBytesMu.Lock() - reportDbTotalSizeInBytes = func() float64 { return float64(b.Size()) } - reportDbTotalSizeInBytesMu.Unlock() - reportDbTotalSizeInBytesDebugMu.Lock() - reportDbTotalSizeInBytesDebug = func() float64 { return float64(b.Size()) } - reportDbTotalSizeInBytesDebugMu.Unlock() - reportDbTotalSizeInUseInBytesMu.Lock() - reportDbTotalSizeInUseInBytes = func() float64 { return float64(b.SizeInUse()) } - reportDbTotalSizeInUseInBytesMu.Unlock() - reportDbOpenReadTxNMu.Lock() - reportDbOpenReadTxN = func() float64 { return float64(b.OpenReadTxN()) } - reportDbOpenReadTxNMu.Unlock() + s.setupMetricsReporter() min, max := newRevBytes(), newRevBytes() revToBytes(revision{main: 1}, min) @@ -579,6 +567,36 @@ func (s *store) ConsistentIndex() uint64 { return v } +func (s *store) setupMetricsReporter() { + b := s.b + reportDbTotalSizeInBytesMu.Lock() + reportDbTotalSizeInBytes = func() float64 { return float64(b.Size()) } + reportDbTotalSizeInBytesMu.Unlock() + reportDbTotalSizeInBytesDebugMu.Lock() + reportDbTotalSizeInBytesDebug = func() float64 { return float64(b.Size()) } + reportDbTotalSizeInBytesDebugMu.Unlock() + reportDbTotalSizeInUseInBytesMu.Lock() + reportDbTotalSizeInUseInBytes = func() float64 { return float64(b.SizeInUse()) } + reportDbTotalSizeInUseInBytesMu.Unlock() + reportDbOpenReadTxNMu.Lock() + reportDbOpenReadTxN = func() float64 { return float64(b.OpenReadTxN()) } + reportDbOpenReadTxNMu.Unlock() + reportCurrentRevMu.Lock() + reportCurrentRev = func() float64 { + s.revMu.RLock() + defer s.revMu.RUnlock() + return float64(s.currentRev) + } + reportCurrentRevMu.Unlock() + reportCompactRevMu.Lock() + reportCompactRev = func() float64 { + s.revMu.RLock() + defer s.revMu.RUnlock() + return float64(s.compactMainRev) + } + reportCompactRevMu.Unlock() +} + // appendMarkTombstone appends tombstone mark to normal revision bytes. func appendMarkTombstone(lg *zap.Logger, b []byte) []byte { if len(b) != revBytesLen { diff --git a/mvcc/metrics.go b/mvcc/metrics.go index 9bcbc8fe3cf..7526ee4b593 100644 --- a/mvcc/metrics.go +++ b/mvcc/metrics.go @@ -264,6 +264,38 @@ var ( // highest bucket start of 0.01 sec * 2^14 == 163.84 sec Buckets: prometheus.ExponentialBuckets(.01, 2, 15), }) + + currentRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ + Namespace: "etcd_debugging", + Subsystem: "mvcc", + Name: "current_revision", + Help: "The current revision of store.", + }, + func() float64 { + reportCurrentRevMu.RLock() + defer reportCurrentRevMu.RUnlock() + return reportCurrentRev() + }, + ) + // overridden by mvcc initialization + reportCurrentRevMu sync.RWMutex + reportCurrentRev = func() float64 { return 0 } + + compactRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ + Namespace: "etcd_debugging", + Subsystem: "mvcc", + Name: "compact_revision", + Help: "The revision of the last compaction in store.", + }, + func() float64 { + reportCompactRevMu.RLock() + defer reportCompactRevMu.RUnlock() + return reportCompactRev() + }, + ) + // overridden by mvcc initialization + reportCompactRevMu sync.RWMutex + reportCompactRev = func() float64 { return 0 } ) func init() { @@ -291,6 +323,8 @@ func init() { prometheus.MustRegister(dbOpenReadTxN) prometheus.MustRegister(hashSec) prometheus.MustRegister(hashRevSec) + prometheus.MustRegister(currentRev) + prometheus.MustRegister(compactRev) } // ReportEventReceived reports that an event is received.