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

telemetry: add transaction usage info #23470

Merged
merged 7 commits into from
Mar 24, 2021
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
Prev Previous commit
Next Next commit
merge master
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
  • Loading branch information
youjiali1995 committed Mar 24, 2021
commit 300f885bc301671a72db5aacbfe5fdddfd1cea4c
6 changes: 3 additions & 3 deletions store/tikv/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ func readCounter(m prometheus.Counter) int64 {
// TxnCommitCounter is the counter of transactions committed with
// different protocols, i.e. 2PC, async-commit, 1PC.
type TxnCommitCounter struct {
TwoPC int64
AsyncCommit int64
OnePC int64
TwoPC int64 `json:"twoPC"`
AsyncCommit int64 `json:"asyncCommit"`
OnePC int64 `json:"onePC"`
}

// Sub returns the difference of two counters.
Expand Down
56 changes: 0 additions & 56 deletions telemetry/data_feature_info.go

This file was deleted.

46 changes: 31 additions & 15 deletions telemetry/data_feature_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import (

"github.com/cznic/mathutil"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/tikv/metrics"
"github.com/pingcap/tidb/util/sqlexec"
)

type featureUsageInfo struct {
AsyncCommitUsed bool `json:"asyncCommitUsed"`
TxnUsageInfo *TxnUsageInfo `json:"txnUsageInfo"`
CoprCacheUsed []*CoprCacheUsedWindowItem `json:"coprCacheUsed"`
ClusterIndexUsed map[string]bool `json:"clusterIndexUsed"`
TiFlashUsed []*TiFlashUsageItem `json:"tiFlashUsed"`
Expand Down Expand Up @@ -225,20 +227,34 @@ func getTelemetryFeatureUsageInfo(ctx sessionctx.Context) (*featureUsageInfo, er
usageInfo.ClusterIndexUsed[row.GetString(0)] = isClustered
}

// async commit
stmt, err = exec.ParseWithParams(context.TODO(), `show config where name = 'storage.enable-async-apply-prewrite'`)
if err != nil {
return nil, err
}
rows, _, err = exec.ExecRestrictedStmt(context.TODO(), stmt)
if err != nil {
return nil, err
}
if len(rows) > 0 {
if rows[0].GetString(3) == "true" {
usageInfo.AsyncCommitUsed = true
}
}
// transaction related feature
usageInfo.TxnUsageInfo = GetTxnUsageInfo(ctx)

return &usageInfo, nil
}

// TxnUsageInfo records the usage info of transaction related features, including
// async-commit, 1PC and counters of transactions committed with different protocols.
type TxnUsageInfo struct {
AsyncCommitUsed bool `json:"asyncCommitUsed"`
OnePCUsed bool `json:"onePCUsed"`
TxnCommitCounter metrics.TxnCommitCounter `json:"txnCommitCounter"`
}

var initialTxnCommitCounter metrics.TxnCommitCounter

// GetTxnUsageInfo gets the usage info of transaction related features. It's exported for tests.
func GetTxnUsageInfo(ctx sessionctx.Context) *TxnUsageInfo {
asyncCommitUsed := false
if val, err := variable.GetGlobalSystemVar(ctx.GetSessionVars(), variable.TiDBEnableAsyncCommit); err == nil {
asyncCommitUsed = val == variable.BoolOn
}
onePCUsed := false
if val, err := variable.GetGlobalSystemVar(ctx.GetSessionVars(), variable.TiDBEnable1PC); err == nil {
onePCUsed = val == variable.BoolOn
}
curr := metrics.GetTxnCommitCounter()
diff := curr.Sub(initialTxnCommitCounter)
initialTxnCommitCounter = curr
youjiali1995 marked this conversation as resolved.
Show resolved Hide resolved
return &TxnUsageInfo{asyncCommitUsed, onePCUsed, diff}
}