Skip to content

Commit

Permalink
metrics, store: remove confused counter and histogram (pingcap#14203)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp authored and sre-bot committed Dec 24, 2019
1 parent 8ab14c1 commit 1dbe685
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 58 deletions.
2 changes: 0 additions & 2 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ func RegisterMetrics() {
prometheus.MustRegister(TiKVRegionErrorCounter)
prometheus.MustRegister(TiKVSecondaryLockCleanupFailureCounter)
prometheus.MustRegister(TiKVSendReqHistogram)
prometheus.MustRegister(TiKVSnapshotCounter)
prometheus.MustRegister(TiKVTxnCmdCounter)
prometheus.MustRegister(TiKVTxnCmdHistogram)
prometheus.MustRegister(TiKVTxnCounter)
prometheus.MustRegister(TiKVTxnRegionsNumHistogram)
Expand Down
16 changes: 0 additions & 16 deletions metrics/tikvclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ var (
Help: "Counter of created txns.",
})

TiKVSnapshotCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "tikvclient",
Name: "snapshot_total",
Help: "Counter of snapshots.",
})

TiKVTxnCmdCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "tikvclient",
Name: "txn_cmd_total",
Help: "Counter of txn commands.",
}, []string{LblType})

TiKVTxnCmdHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Expand Down
1 change: 0 additions & 1 deletion store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ func (s *tikvStore) BeginWithStartTS(startTS uint64) (kv.Transaction, error) {

func (s *tikvStore) GetSnapshot(ver kv.Version) (kv.Snapshot, error) {
snapshot := newTiKVSnapshot(s, ver, s.nextReplicaReadSeed())
metrics.TiKVSnapshotCounter.Inc()
return snapshot, nil
}

Expand Down
6 changes: 0 additions & 6 deletions store/tikv/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"strings"
"sync"
"time"
"unsafe"

"github.com/opentracing/opentracing-go"
Expand All @@ -45,8 +44,6 @@ const (
)

var (
tikvTxnCmdCounterWithBatchGet = metrics.TiKVTxnCmdCounter.WithLabelValues("batch_get")
tikvTxnCmdHistogramWithBatchGet = metrics.TiKVTxnCmdHistogram.WithLabelValues("batch_get")
tikvTxnRegionsNumHistogramWithSnapshot = metrics.TiKVTxnRegionsNumHistogram.WithLabelValues("snapshot")
)

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

// We want [][]byte instead of []kv.Key, use some magic to save memory.
bytesKeys := *(*[][]byte)(unsafe.Pointer(&keys))
Expand Down
37 changes: 4 additions & 33 deletions store/tikv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,8 @@ var (
)

var (
tikvTxnCmdCountWithGet = metrics.TiKVTxnCmdCounter.WithLabelValues("get")
tikvTxnCmdHistogramWithGet = metrics.TiKVTxnCmdHistogram.WithLabelValues("get")
tikvTxnCmdCountWithSeek = metrics.TiKVTxnCmdCounter.WithLabelValues("seek")
tikvTxnCmdHistogramWithSeek = metrics.TiKVTxnCmdHistogram.WithLabelValues("seek")
tikvTxnCmdCountWithSeekReverse = metrics.TiKVTxnCmdCounter.WithLabelValues("seek_reverse")
tikvTxnCmdHistogramWithSeekReverse = metrics.TiKVTxnCmdHistogram.WithLabelValues("seek_reverse")
tikvTxnCmdCountWithDelete = metrics.TiKVTxnCmdCounter.WithLabelValues("delete")
tikvTxnCmdCountWithSet = metrics.TiKVTxnCmdCounter.WithLabelValues("set")
tikvTxnCmdCountWithCommit = metrics.TiKVTxnCmdCounter.WithLabelValues("commit")
tikvTxnCmdHistogramWithCommit = metrics.TiKVTxnCmdHistogram.WithLabelValues("commit")
tikvTxnCmdCountWithRollback = metrics.TiKVTxnCmdCounter.WithLabelValues("rollback")
tikvTxnCmdHistogramWithLockKeys = metrics.TiKVTxnCmdCounter.WithLabelValues("lock_keys")
tikvTxnCmdHistogramWithCommit = metrics.TiKVTxnCmdHistogram.WithLabelValues(metrics.LblCommit)
tikvTxnCmdHistogramWithRollback = metrics.TiKVTxnCmdHistogram.WithLabelValues(metrics.LblRollback)
)

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

// Get implements transaction interface.
func (txn *tikvTxn) Get(ctx context.Context, k kv.Key) ([]byte, error) {
tikvTxnCmdCountWithGet.Inc()
start := time.Now()
defer func() { tikvTxnCmdHistogramWithGet.Observe(time.Since(start).Seconds()) }()

ret, err := txn.us.Get(ctx, k)
if kv.IsErrNotFound(err) {
return nil, err
Expand Down Expand Up @@ -199,27 +185,15 @@ func (txn *tikvTxn) String() string {
}

func (txn *tikvTxn) Iter(k kv.Key, upperBound kv.Key) (kv.Iterator, error) {
tikvTxnCmdCountWithSeek.Inc()
start := time.Now()
defer func() { tikvTxnCmdHistogramWithSeek.Observe(time.Since(start).Seconds()) }()

return txn.us.Iter(k, upperBound)
}

// IterReverse creates a reversed Iterator positioned on the first entry which key is less than k.
func (txn *tikvTxn) IterReverse(k kv.Key) (kv.Iterator, error) {
tikvTxnCmdCountWithSeekReverse.Inc()
start := time.Now()
defer func() {
tikvTxnCmdHistogramWithSeekReverse.Observe(time.Since(start).Seconds())
}()

return txn.us.IterReverse(k)
}

func (txn *tikvTxn) Delete(k kv.Key) error {
tikvTxnCmdCountWithDelete.Inc()

txn.dirty = true
return txn.us.Delete(k)
}
Expand Down Expand Up @@ -267,8 +241,6 @@ func (txn *tikvTxn) Commit(ctx context.Context) error {
}
})

tikvTxnCmdCountWithSet.Add(float64(txn.setCnt))
tikvTxnCmdCountWithCommit.Inc()
start := time.Now()
defer func() { tikvTxnCmdHistogramWithCommit.Observe(time.Since(start).Seconds()) }()

Expand Down Expand Up @@ -344,6 +316,7 @@ func (txn *tikvTxn) Rollback() error {
if !txn.valid {
return kv.ErrInvalidTxn
}
start := time.Now()
// Clean up pessimistic lock.
if txn.IsPessimistic() && txn.committer != nil {
err := txn.rollbackPessimisticLocks()
Expand All @@ -354,8 +327,7 @@ func (txn *tikvTxn) Rollback() error {
}
txn.close()
logutil.BgLogger().Debug("[kv] rollback txn", zap.Uint64("txnStartTS", txn.StartTS()))
tikvTxnCmdCountWithRollback.Inc()

tikvTxnCmdHistogramWithRollback.Observe(time.Since(start).Seconds())
return nil
}

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

0 comments on commit 1dbe685

Please sign in to comment.