blob: 64b629c785b61d171dcb9b29ec1edbebd589279b [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001// Copyright 2017 The etcd Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package mvcc
16
17import "go.etcd.io/etcd/lease"
18
19type metricsTxnWrite struct {
20 TxnWrite
21 ranges uint
22 puts uint
23 deletes uint
24}
25
26func newMetricsTxnRead(tr TxnRead) TxnRead {
27 return &metricsTxnWrite{&txnReadWrite{tr}, 0, 0, 0}
28}
29
30func newMetricsTxnWrite(tw TxnWrite) TxnWrite {
31 return &metricsTxnWrite{tw, 0, 0, 0}
32}
33
34func (tw *metricsTxnWrite) Range(key, end []byte, ro RangeOptions) (*RangeResult, error) {
35 tw.ranges++
36 return tw.TxnWrite.Range(key, end, ro)
37}
38
39func (tw *metricsTxnWrite) DeleteRange(key, end []byte) (n, rev int64) {
40 tw.deletes++
41 return tw.TxnWrite.DeleteRange(key, end)
42}
43
44func (tw *metricsTxnWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) {
45 tw.puts++
46 return tw.TxnWrite.Put(key, value, lease)
47}
48
49func (tw *metricsTxnWrite) End() {
50 defer tw.TxnWrite.End()
51 if sum := tw.ranges + tw.puts + tw.deletes; sum > 1 {
52 txnCounter.Inc()
53 txnCounterDebug.Inc() // TODO: remove in 3.5 release
54 }
55
56 ranges := float64(tw.ranges)
57 rangeCounter.Add(ranges)
58 rangeCounterDebug.Add(ranges) // TODO: remove in 3.5 release
59
60 puts := float64(tw.puts)
61 putCounter.Add(puts)
62 putCounterDebug.Add(puts) // TODO: remove in 3.5 release
63
64 deletes := float64(tw.deletes)
65 deleteCounter.Add(deletes)
66 deleteCounterDebug.Add(deletes) // TODO: remove in 3.5 release
67}