Skip to content

Commit

Permalink
Merge pull request #11394 from jingyih/automated-cherry-pick-of-#1137…
Browse files Browse the repository at this point in the history
…4-upstream-release-3.3

Automated cherry pick of #11374 on release 3.3
  • Loading branch information
wenjiaswe committed Nov 26, 2019
2 parents 5cf80a6 + 47d3dea commit 9cd3eef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions mvcc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ var (
// overridden by mvcc initialization
reportCompactRevMu sync.RWMutex
reportCompactRev = func() float64 { return 0 }

totalPutSizeGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "etcd_debugging",
Subsystem: "mvcc",
Name: "total_put_size_in_bytes",
Help: "The total size of put kv pairs seen by this member.",
})
)

func init() {
Expand All @@ -262,6 +270,7 @@ func init() {
prometheus.MustRegister(hashRevDurations)
prometheus.MustRegister(currentRev)
prometheus.MustRegister(compactRev)
prometheus.MustRegister(totalPutSizeGauge)
}

// ReportEventReceived reports that an event is received.
Expand Down
8 changes: 6 additions & 2 deletions mvcc/metrics_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ type metricsTxnWrite struct {
ranges uint
puts uint
deletes uint
putSize int64
}

func newMetricsTxnRead(tr TxnRead) TxnRead {
return &metricsTxnWrite{&txnReadWrite{tr}, 0, 0, 0}
return &metricsTxnWrite{&txnReadWrite{tr}, 0, 0, 0, 0}
}

func newMetricsTxnWrite(tw TxnWrite) TxnWrite {
return &metricsTxnWrite{tw, 0, 0, 0}
return &metricsTxnWrite{tw, 0, 0, 0, 0}
}

func (tw *metricsTxnWrite) Range(key, end []byte, ro RangeOptions) (*RangeResult, error) {
Expand All @@ -45,6 +46,8 @@ func (tw *metricsTxnWrite) DeleteRange(key, end []byte) (n, rev int64) {

func (tw *metricsTxnWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) {
tw.puts++
size := int64(len(key) + len(value))
tw.putSize += size
return tw.TxnWrite.Put(key, value, lease)
}

Expand All @@ -55,5 +58,6 @@ func (tw *metricsTxnWrite) End() {
}
rangeCounter.Add(float64(tw.ranges))
putCounter.Add(float64(tw.puts))
totalPutSizeGauge.Add(float64(tw.putSize))
deleteCounter.Add(float64(tw.deletes))
}

0 comments on commit 9cd3eef

Please sign in to comment.