Skip to content

Commit

Permalink
telemetry: telemetry supports count flashback cluster (#38901)
Browse files Browse the repository at this point in the history
close #38896
  • Loading branch information
Defined2014 authored Nov 4, 2022
1 parent 2f03a8d commit 6ab1707
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
13 changes: 7 additions & 6 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ func (a *recordSet) OnFetchReturned() {

// TelemetryInfo records some telemetry information during execution.
type TelemetryInfo struct {
UseNonRecursive bool
UseRecursive bool
UseMultiSchemaChange bool
UesExchangePartition bool
PartitionTelemetry *PartitionTelemetryInfo
AccountLockTelemetry *AccountLockTelemetryInfo
UseNonRecursive bool
UseRecursive bool
UseMultiSchemaChange bool
UesExchangePartition bool
UseFlashbackToCluster bool
PartitionTelemetry *PartitionTelemetryInfo
AccountLockTelemetry *AccountLockTelemetryInfo
}

// PartitionTelemetryInfo records table partition telemetry information during execution.
Expand Down
2 changes: 2 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,8 @@ func (b *executorBuilder) setTelemetryInfo(v *plannercore.DDL) {
}
}
}
case *ast.FlashBackToTimestampStmt:
b.Ti.UseFlashbackToCluster = true
}
}

Expand Down
20 changes: 15 additions & 5 deletions metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ var (
Name: "add_index_ingest_usage",
Help: "Counter of usage of add index acceleration solution",
})
TelemetryFlashbackClusterCnt = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "telemetry",
Name: "flashback_cluster_usage",
Help: "Counter of usage of flashback cluster",
})
)

// readCounter reads the value of a prometheus.Counter.
Expand Down Expand Up @@ -354,22 +361,25 @@ func GetLazyPessimisticUniqueCheckSetCounter() int64 {
return readCounter(LazyPessimisticUniqueCheckSetCount)
}

// DDLUsageCounter records the usages of Add Index with acceleration solution.
// DDLUsageCounter records the usages of DDL related features.
type DDLUsageCounter struct {
AddIndexIngestUsed int64 `json:"add_index_ingest_used"`
MetadataLockUsed bool `json:"metadata_lock_used"`
AddIndexIngestUsed int64 `json:"add_index_ingest_used"`
MetadataLockUsed bool `json:"metadata_lock_used"`
FlashbackClusterUsed int64 `json:"flashback_cluster_used"`
}

// Sub returns the difference of two counters.
func (a DDLUsageCounter) Sub(rhs DDLUsageCounter) DDLUsageCounter {
return DDLUsageCounter{
AddIndexIngestUsed: a.AddIndexIngestUsed - rhs.AddIndexIngestUsed,
AddIndexIngestUsed: a.AddIndexIngestUsed - rhs.AddIndexIngestUsed,
FlashbackClusterUsed: a.FlashbackClusterUsed - rhs.FlashbackClusterUsed,
}
}

// GetDDLUsageCounter gets the add index acceleration solution counts.
func GetDDLUsageCounter() DDLUsageCounter {
return DDLUsageCounter{
AddIndexIngestUsed: readCounter(TelemetryAddIndexIngestCnt),
AddIndexIngestUsed: readCounter(TelemetryAddIndexIngestCnt),
FlashbackClusterUsed: readCounter(TelemetryFlashbackClusterCnt),
}
}
5 changes: 5 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ var (
telemetryCTEUsageNonRecurCTE = metrics.TelemetrySQLCTECnt.WithLabelValues("nonRecurCTE")
telemetryCTEUsageNotCTE = metrics.TelemetrySQLCTECnt.WithLabelValues("notCTE")
telemetryMultiSchemaChangeUsage = metrics.TelemetryMultiSchemaChangeCnt
telemetryFlashbackClusterUsage = metrics.TelemetryFlashbackClusterCnt

telemetryTablePartitionUsage = metrics.TelemetryTablePartitionCnt
telemetryTablePartitionListUsage = metrics.TelemetryTablePartitionListCnt
Expand Down Expand Up @@ -3518,6 +3519,10 @@ func (s *session) updateTelemetryMetric(es *executor.ExecStmt) {
telemetryMultiSchemaChangeUsage.Inc()
}

if ti.UseFlashbackToCluster {
telemetryFlashbackClusterUsage.Inc()
}

if ti.UesExchangePartition {
telemetryExchangePartitionUsage.Inc()
}
Expand Down
1 change: 1 addition & 0 deletions telemetry/data_feature_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ func getCostModelVer2UsageInfo(ctx sessionctx.Context) bool {
func getPagingUsageInfo(ctx sessionctx.Context) bool {
return ctx.GetSessionVars().EnablePaging
}

func getDDLUsageInfo(ctx sessionctx.Context) *m.DDLUsageCounter {
curr := m.GetDDLUsageCounter()
diff := curr.Sub(initialDDLUsageCounter)
Expand Down
21 changes: 21 additions & 0 deletions telemetry/data_feature_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,27 @@ func TestLazyPessimisticUniqueCheck(t *testing.T) {
require.Equal(t, int64(2), usage.LazyUniqueCheckSetCounter)
}

func TestFlashbackCluster(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk1 := testkit.NewTestKit(t, store)

usage, err := telemetry.GetFeatureUsage(tk.Session())
require.Equal(t, int64(0), usage.DDLUsageCounter.FlashbackClusterUsed)
require.NoError(t, err)

tk.MustExecToErr("flashback cluster to timestamp '2011-12-21 00:00:00'")
usage, err = telemetry.GetFeatureUsage(tk.Session())
require.Equal(t, int64(1), usage.DDLUsageCounter.FlashbackClusterUsed)
require.NoError(t, err)

tk1.MustExec("use test")
tk1.MustExec("create table t(a int)")
usage, err = telemetry.GetFeatureUsage(tk1.Session())
require.Equal(t, int64(1), usage.DDLUsageCounter.FlashbackClusterUsed)
require.NoError(t, err)
}

func TestAddIndexAccelerationAndMDL(t *testing.T) {
if !variable.EnableConcurrentDDL.Load() {
t.Skipf("test requires concurrent ddl")
Expand Down

0 comments on commit 6ab1707

Please sign in to comment.