sslobodr | d046be8 | 2019-01-16 10:02:22 -0500 | [diff] [blame] | 1 | // 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 | |
| 15 | package mvcc |
| 16 | |
| 17 | import ( |
| 18 | "github.com/coreos/etcd/lease" |
| 19 | ) |
| 20 | |
| 21 | type metricsTxnWrite struct { |
| 22 | TxnWrite |
| 23 | ranges uint |
| 24 | puts uint |
| 25 | deletes uint |
| 26 | } |
| 27 | |
| 28 | func newMetricsTxnRead(tr TxnRead) TxnRead { |
| 29 | return &metricsTxnWrite{&txnReadWrite{tr}, 0, 0, 0} |
| 30 | } |
| 31 | |
| 32 | func newMetricsTxnWrite(tw TxnWrite) TxnWrite { |
| 33 | return &metricsTxnWrite{tw, 0, 0, 0} |
| 34 | } |
| 35 | |
| 36 | func (tw *metricsTxnWrite) Range(key, end []byte, ro RangeOptions) (*RangeResult, error) { |
| 37 | tw.ranges++ |
| 38 | return tw.TxnWrite.Range(key, end, ro) |
| 39 | } |
| 40 | |
| 41 | func (tw *metricsTxnWrite) DeleteRange(key, end []byte) (n, rev int64) { |
| 42 | tw.deletes++ |
| 43 | return tw.TxnWrite.DeleteRange(key, end) |
| 44 | } |
| 45 | |
| 46 | func (tw *metricsTxnWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) { |
| 47 | tw.puts++ |
| 48 | return tw.TxnWrite.Put(key, value, lease) |
| 49 | } |
| 50 | |
| 51 | func (tw *metricsTxnWrite) End() { |
| 52 | defer tw.TxnWrite.End() |
| 53 | if sum := tw.ranges + tw.puts + tw.deletes; sum > 1 { |
| 54 | txnCounter.Inc() |
| 55 | } |
| 56 | rangeCounter.Add(float64(tw.ranges)) |
| 57 | putCounter.Add(float64(tw.puts)) |
| 58 | deleteCounter.Add(float64(tw.deletes)) |
| 59 | } |