Skip to content

Commit 1dbe685

Browse files
jackyspsre-bot
authored andcommitted
metrics, store: remove confused counter and histogram (pingcap#14203)
1 parent 8ab14c1 commit 1dbe685

File tree

5 files changed

+4
-58
lines changed

5 files changed

+4
-58
lines changed

metrics/metrics.go

-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ func RegisterMetrics() {
123123
prometheus.MustRegister(TiKVRegionErrorCounter)
124124
prometheus.MustRegister(TiKVSecondaryLockCleanupFailureCounter)
125125
prometheus.MustRegister(TiKVSendReqHistogram)
126-
prometheus.MustRegister(TiKVSnapshotCounter)
127-
prometheus.MustRegister(TiKVTxnCmdCounter)
128126
prometheus.MustRegister(TiKVTxnCmdHistogram)
129127
prometheus.MustRegister(TiKVTxnCounter)
130128
prometheus.MustRegister(TiKVTxnRegionsNumHistogram)

metrics/tikvclient.go

-16
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ var (
2525
Help: "Counter of created txns.",
2626
})
2727

28-
TiKVSnapshotCounter = prometheus.NewCounter(
29-
prometheus.CounterOpts{
30-
Namespace: "tidb",
31-
Subsystem: "tikvclient",
32-
Name: "snapshot_total",
33-
Help: "Counter of snapshots.",
34-
})
35-
36-
TiKVTxnCmdCounter = prometheus.NewCounterVec(
37-
prometheus.CounterOpts{
38-
Namespace: "tidb",
39-
Subsystem: "tikvclient",
40-
Name: "txn_cmd_total",
41-
Help: "Counter of txn commands.",
42-
}, []string{LblType})
43-
4428
TiKVTxnCmdHistogram = prometheus.NewHistogramVec(
4529
prometheus.HistogramOpts{
4630
Namespace: "tidb",

store/tikv/kv.go

-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ func (s *tikvStore) BeginWithStartTS(startTS uint64) (kv.Transaction, error) {
287287

288288
func (s *tikvStore) GetSnapshot(ver kv.Version) (kv.Snapshot, error) {
289289
snapshot := newTiKVSnapshot(s, ver, s.nextReplicaReadSeed())
290-
metrics.TiKVSnapshotCounter.Inc()
291290
return snapshot, nil
292291
}
293292

store/tikv/snapshot.go

-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"strings"
2222
"sync"
23-
"time"
2423
"unsafe"
2524

2625
"github.com/opentracing/opentracing-go"
@@ -45,8 +44,6 @@ const (
4544
)
4645

4746
var (
48-
tikvTxnCmdCounterWithBatchGet = metrics.TiKVTxnCmdCounter.WithLabelValues("batch_get")
49-
tikvTxnCmdHistogramWithBatchGet = metrics.TiKVTxnCmdHistogram.WithLabelValues("batch_get")
5047
tikvTxnRegionsNumHistogramWithSnapshot = metrics.TiKVTxnRegionsNumHistogram.WithLabelValues("snapshot")
5148
)
5249

@@ -117,9 +114,6 @@ func (s *tikvSnapshot) BatchGet(ctx context.Context, keys []kv.Key) (map[string]
117114
if len(keys) == 0 {
118115
return m, nil
119116
}
120-
tikvTxnCmdCounterWithBatchGet.Inc()
121-
start := time.Now()
122-
defer func() { tikvTxnCmdHistogramWithBatchGet.Observe(time.Since(start).Seconds()) }()
123117

124118
// We want [][]byte instead of []kv.Key, use some magic to save memory.
125119
bytesKeys := *(*[][]byte)(unsafe.Pointer(&keys))

store/tikv/txn.go

+4-33
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,8 @@ var (
3838
)
3939

4040
var (
41-
tikvTxnCmdCountWithGet = metrics.TiKVTxnCmdCounter.WithLabelValues("get")
42-
tikvTxnCmdHistogramWithGet = metrics.TiKVTxnCmdHistogram.WithLabelValues("get")
43-
tikvTxnCmdCountWithSeek = metrics.TiKVTxnCmdCounter.WithLabelValues("seek")
44-
tikvTxnCmdHistogramWithSeek = metrics.TiKVTxnCmdHistogram.WithLabelValues("seek")
45-
tikvTxnCmdCountWithSeekReverse = metrics.TiKVTxnCmdCounter.WithLabelValues("seek_reverse")
46-
tikvTxnCmdHistogramWithSeekReverse = metrics.TiKVTxnCmdHistogram.WithLabelValues("seek_reverse")
47-
tikvTxnCmdCountWithDelete = metrics.TiKVTxnCmdCounter.WithLabelValues("delete")
48-
tikvTxnCmdCountWithSet = metrics.TiKVTxnCmdCounter.WithLabelValues("set")
49-
tikvTxnCmdCountWithCommit = metrics.TiKVTxnCmdCounter.WithLabelValues("commit")
50-
tikvTxnCmdHistogramWithCommit = metrics.TiKVTxnCmdHistogram.WithLabelValues("commit")
51-
tikvTxnCmdCountWithRollback = metrics.TiKVTxnCmdCounter.WithLabelValues("rollback")
52-
tikvTxnCmdHistogramWithLockKeys = metrics.TiKVTxnCmdCounter.WithLabelValues("lock_keys")
41+
tikvTxnCmdHistogramWithCommit = metrics.TiKVTxnCmdHistogram.WithLabelValues(metrics.LblCommit)
42+
tikvTxnCmdHistogramWithRollback = metrics.TiKVTxnCmdHistogram.WithLabelValues(metrics.LblRollback)
5343
)
5444

5545
// tikvTxn implements kv.Transaction.
@@ -129,10 +119,6 @@ func (txn *tikvTxn) Reset() {
129119

130120
// Get implements transaction interface.
131121
func (txn *tikvTxn) Get(ctx context.Context, k kv.Key) ([]byte, error) {
132-
tikvTxnCmdCountWithGet.Inc()
133-
start := time.Now()
134-
defer func() { tikvTxnCmdHistogramWithGet.Observe(time.Since(start).Seconds()) }()
135-
136122
ret, err := txn.us.Get(ctx, k)
137123
if kv.IsErrNotFound(err) {
138124
return nil, err
@@ -199,27 +185,15 @@ func (txn *tikvTxn) String() string {
199185
}
200186

201187
func (txn *tikvTxn) Iter(k kv.Key, upperBound kv.Key) (kv.Iterator, error) {
202-
tikvTxnCmdCountWithSeek.Inc()
203-
start := time.Now()
204-
defer func() { tikvTxnCmdHistogramWithSeek.Observe(time.Since(start).Seconds()) }()
205-
206188
return txn.us.Iter(k, upperBound)
207189
}
208190

209191
// IterReverse creates a reversed Iterator positioned on the first entry which key is less than k.
210192
func (txn *tikvTxn) IterReverse(k kv.Key) (kv.Iterator, error) {
211-
tikvTxnCmdCountWithSeekReverse.Inc()
212-
start := time.Now()
213-
defer func() {
214-
tikvTxnCmdHistogramWithSeekReverse.Observe(time.Since(start).Seconds())
215-
}()
216-
217193
return txn.us.IterReverse(k)
218194
}
219195

220196
func (txn *tikvTxn) Delete(k kv.Key) error {
221-
tikvTxnCmdCountWithDelete.Inc()
222-
223197
txn.dirty = true
224198
return txn.us.Delete(k)
225199
}
@@ -267,8 +241,6 @@ func (txn *tikvTxn) Commit(ctx context.Context) error {
267241
}
268242
})
269243

270-
tikvTxnCmdCountWithSet.Add(float64(txn.setCnt))
271-
tikvTxnCmdCountWithCommit.Inc()
272244
start := time.Now()
273245
defer func() { tikvTxnCmdHistogramWithCommit.Observe(time.Since(start).Seconds()) }()
274246

@@ -344,6 +316,7 @@ func (txn *tikvTxn) Rollback() error {
344316
if !txn.valid {
345317
return kv.ErrInvalidTxn
346318
}
319+
start := time.Now()
347320
// Clean up pessimistic lock.
348321
if txn.IsPessimistic() && txn.committer != nil {
349322
err := txn.rollbackPessimisticLocks()
@@ -354,8 +327,7 @@ func (txn *tikvTxn) Rollback() error {
354327
}
355328
txn.close()
356329
logutil.BgLogger().Debug("[kv] rollback txn", zap.Uint64("txnStartTS", txn.StartTS()))
357-
tikvTxnCmdCountWithRollback.Inc()
358-
330+
tikvTxnCmdHistogramWithRollback.Observe(time.Since(start).Seconds())
359331
return nil
360332
}
361333

@@ -392,7 +364,6 @@ func (txn *tikvTxn) LockKeys(ctx context.Context, lockCtx *kv.LockCtx, keysInput
392364
if len(keys) == 0 {
393365
return nil
394366
}
395-
tikvTxnCmdHistogramWithLockKeys.Inc()
396367
if txn.IsPessimistic() && lockCtx.ForUpdateTS > 0 {
397368
if txn.committer == nil {
398369
// connID is used for log.

0 commit comments

Comments
 (0)