Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mvcc: add "etcd_mvcc_put_size_in_bytes" metrics #11374

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mvcc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ var (
// overridden by mvcc initialization
reportCompactRevMu sync.RWMutex
reportCompactRev = func() float64 { return 0 }

putSizeGauge = prometheus.NewGauge(
YoyinZyc marked this conversation as resolved.
Show resolved Hide resolved
prometheus.GaugeOpts{
Namespace: "etcd",
YoyinZyc marked this conversation as resolved.
Show resolved Hide resolved
Subsystem: "mvcc",
Name: "put_size_in_bytes",
YoyinZyc marked this conversation as resolved.
Show resolved Hide resolved
Help: "The total size of put kv pairs seen by this member.",
})
)

func init() {
Expand Down Expand Up @@ -325,6 +333,7 @@ func init() {
prometheus.MustRegister(hashRevSec)
prometheus.MustRegister(currentRev)
prometheus.MustRegister(compactRev)
prometheus.MustRegister(putSizeGauge)
}

// 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 @@ -21,14 +21,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 @@ -43,6 +44,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 @@ -60,6 +63,7 @@ func (tw *metricsTxnWrite) End() {
puts := float64(tw.puts)
putCounter.Add(puts)
putCounterDebug.Add(puts) // TODO: remove in 3.5 release
putSizeGauge.Add(float64(tw.putSize))

deletes := float64(tw.deletes)
deleteCounter.Add(deletes)
Expand Down