Skip to content

Commit

Permalink
telemetry: Adding telemetry for alter table reorganize partition (#40258
Browse files Browse the repository at this point in the history
)

ref #38535
  • Loading branch information
mjonss authored Jan 18, 2023
1 parent 2887591 commit 8db6a00
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
3 changes: 2 additions & 1 deletion executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ type TelemetryInfo struct {
UseNonRecursive bool
UseRecursive bool
UseMultiSchemaChange bool
UesExchangePartition bool
UseExchangePartition bool
UseFlashbackToCluster bool
PartitionTelemetry *PartitionTelemetryInfo
AccountLockTelemetry *AccountLockTelemetryInfo
Expand All @@ -220,6 +220,7 @@ type PartitionTelemetryInfo struct {
UseAddIntervalPartition bool
UseDropIntervalPartition bool
UseCompactTablePartition bool
UseReorganizePartition bool
}

// AccountLockTelemetryInfo records account lock/unlock information during execution
Expand Down
7 changes: 6 additions & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,12 @@ func (b *executorBuilder) setTelemetryInfo(v *plannercore.DDL) {
}
b.Ti.PartitionTelemetry.UseAddIntervalPartition = true
case ast.AlterTableExchangePartition:
b.Ti.UesExchangePartition = true
b.Ti.UseExchangePartition = true
case ast.AlterTableReorganizePartition:
if b.Ti.PartitionTelemetry == nil {
b.Ti.PartitionTelemetry = &PartitionTelemetryInfo{}
}
b.Ti.PartitionTelemetry.UseReorganizePartition = true
}
}
case *ast.CreateTableStmt:
Expand Down
31 changes: 21 additions & 10 deletions metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ var (
Name: "compact_partition_usage",
Help: "Counter of compact table partition",
})
TelemetryReorganizePartitionCnt = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "telemetry",
Name: "reorganize_partition_usage",
Help: "Counter of alter table reorganize partition",
})
)

// readCounter reads the value of a prometheus.Counter.
Expand Down Expand Up @@ -269,6 +276,7 @@ type TablePartitionUsageCounter struct {
TablePartitionAddIntervalPartitionsCnt int64 `json:"table_partition_add_interval_partitions_cnt"`
TablePartitionDropIntervalPartitionsCnt int64 `json:"table_partition_drop_interval_partitions_cnt"`
TablePartitionComactCnt int64 `json:"table_TablePartitionComactCnt"`
TablePartitionReorganizePartitionCnt int64 `json:"table_reorganize_partition_cnt"`
}

// ExchangePartitionUsageCounter records the usages of exchange partition.
Expand Down Expand Up @@ -307,22 +315,24 @@ func (c TablePartitionUsageCounter) Cal(rhs TablePartitionUsageCounter) TablePar
TablePartitionAddIntervalPartitionsCnt: c.TablePartitionAddIntervalPartitionsCnt - rhs.TablePartitionAddIntervalPartitionsCnt,
TablePartitionDropIntervalPartitionsCnt: c.TablePartitionDropIntervalPartitionsCnt - rhs.TablePartitionDropIntervalPartitionsCnt,
TablePartitionComactCnt: c.TablePartitionComactCnt - rhs.TablePartitionComactCnt,
TablePartitionReorganizePartitionCnt: c.TablePartitionReorganizePartitionCnt - rhs.TablePartitionReorganizePartitionCnt,
}
}

// ResetTablePartitionCounter gets the TxnCommitCounter.
func ResetTablePartitionCounter(pre TablePartitionUsageCounter) TablePartitionUsageCounter {
return TablePartitionUsageCounter{
TablePartitionCnt: readCounter(TelemetryTablePartitionCnt),
TablePartitionListCnt: readCounter(TelemetryTablePartitionListCnt),
TablePartitionRangeCnt: readCounter(TelemetryTablePartitionRangeCnt),
TablePartitionHashCnt: readCounter(TelemetryTablePartitionHashCnt),
TablePartitionRangeColumnsCnt: readCounter(TelemetryTablePartitionRangeColumnsCnt),
TablePartitionRangeColumnsGt1Cnt: readCounter(TelemetryTablePartitionRangeColumnsGt1Cnt),
TablePartitionRangeColumnsGt2Cnt: readCounter(TelemetryTablePartitionRangeColumnsGt2Cnt),
TablePartitionRangeColumnsGt3Cnt: readCounter(TelemetryTablePartitionRangeColumnsGt3Cnt),
TablePartitionListColumnsCnt: readCounter(TelemetryTablePartitionListColumnsCnt),
TablePartitionMaxPartitionsCnt: mathutil.Max(readCounter(TelemetryTablePartitionMaxPartitionsCnt)-pre.TablePartitionMaxPartitionsCnt, pre.TablePartitionMaxPartitionsCnt),
TablePartitionCnt: readCounter(TelemetryTablePartitionCnt),
TablePartitionListCnt: readCounter(TelemetryTablePartitionListCnt),
TablePartitionRangeCnt: readCounter(TelemetryTablePartitionRangeCnt),
TablePartitionHashCnt: readCounter(TelemetryTablePartitionHashCnt),
TablePartitionRangeColumnsCnt: readCounter(TelemetryTablePartitionRangeColumnsCnt),
TablePartitionRangeColumnsGt1Cnt: readCounter(TelemetryTablePartitionRangeColumnsGt1Cnt),
TablePartitionRangeColumnsGt2Cnt: readCounter(TelemetryTablePartitionRangeColumnsGt2Cnt),
TablePartitionRangeColumnsGt3Cnt: readCounter(TelemetryTablePartitionRangeColumnsGt3Cnt),
TablePartitionListColumnsCnt: readCounter(TelemetryTablePartitionListColumnsCnt),
TablePartitionMaxPartitionsCnt: mathutil.Max(readCounter(TelemetryTablePartitionMaxPartitionsCnt)-pre.TablePartitionMaxPartitionsCnt, pre.TablePartitionMaxPartitionsCnt),
TablePartitionReorganizePartitionCnt: readCounter(TelemetryReorganizePartitionCnt),
}
}

Expand All @@ -343,6 +353,7 @@ func GetTablePartitionCounter() TablePartitionUsageCounter {
TablePartitionAddIntervalPartitionsCnt: readCounter(TelemetryTablePartitionAddIntervalPartitionsCnt),
TablePartitionDropIntervalPartitionsCnt: readCounter(TelemetryTablePartitionDropIntervalPartitionsCnt),
TablePartitionComactCnt: readCounter(TelemetryCompactPartitionCnt),
TablePartitionReorganizePartitionCnt: readCounter(TelemetryReorganizePartitionCnt),
}
}

Expand Down
6 changes: 5 additions & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ var (
telemetryTablePartitionDropIntervalUsage = metrics.TelemetryTablePartitionDropIntervalPartitionsCnt
telemetryExchangePartitionUsage = metrics.TelemetryExchangePartitionCnt
telemetryTableCompactPartitionUsage = metrics.TelemetryCompactPartitionCnt
telemetryReorganizePartitionUsage = metrics.TelemetryReorganizePartitionCnt

telemetryLockUserUsage = metrics.TelemetryAccountLockCnt.WithLabelValues("lockUser")
telemetryUnlockUserUsage = metrics.TelemetryAccountLockCnt.WithLabelValues("unlockUser")
Expand Down Expand Up @@ -4006,7 +4007,7 @@ func (s *session) updateTelemetryMetric(es *executor.ExecStmt) {
telemetryFlashbackClusterUsage.Inc()
}

if ti.UesExchangePartition {
if ti.UseExchangePartition {
telemetryExchangePartitionUsage.Inc()
}

Expand Down Expand Up @@ -4051,6 +4052,9 @@ func (s *session) updateTelemetryMetric(es *executor.ExecStmt) {
if ti.PartitionTelemetry.UseCompactTablePartition {
telemetryTableCompactPartitionUsage.Inc()
}
if ti.PartitionTelemetry.UseReorganizePartition {
telemetryReorganizePartitionUsage.Inc()
}
}

if ti.AccountLockTelemetry != nil {
Expand Down
3 changes: 3 additions & 0 deletions telemetry/data_feature_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func TestTablePartition(t *testing.T) {
require.Equal(t, int64(0), usage.TablePartition.TablePartitionCreateIntervalPartitionsCnt)
require.Equal(t, int64(0), usage.TablePartition.TablePartitionAddIntervalPartitionsCnt)
require.Equal(t, int64(0), usage.TablePartition.TablePartitionDropIntervalPartitionsCnt)
require.Equal(t, int64(0), usage.TablePartition.TablePartitionReorganizePartitionCnt)

telemetry.PostReportTelemetryDataForTest()
tk.MustExec("drop table if exists pt1")
Expand All @@ -251,6 +252,7 @@ func TestTablePartition(t *testing.T) {
"partition p4 values less than (15))")
tk.MustExec("alter table pt1 first partition less than (9)")
tk.MustExec("alter table pt1 last partition less than (21)")
tk.MustExec("alter table pt1 reorganize partition p4 into (partition p4 values less than (13), partition p5 values less than (15))")
tk.MustExec("drop table if exists pt1")
tk.MustExec("create table pt1 (d datetime primary key, v varchar(255)) partition by range columns(d)" +
" interval (1 day) first partition less than ('2022-01-01') last partition less than ('2022-02-22')")
Expand All @@ -275,6 +277,7 @@ func TestTablePartition(t *testing.T) {
require.Equal(t, int64(1), usage.TablePartition.TablePartitionCreateIntervalPartitionsCnt)
require.Equal(t, int64(1), usage.TablePartition.TablePartitionAddIntervalPartitionsCnt)
require.Equal(t, int64(1), usage.TablePartition.TablePartitionDropIntervalPartitionsCnt)
require.Equal(t, int64(1), usage.TablePartition.TablePartitionReorganizePartitionCnt)

tk.MustExec("drop table if exists pt2")
tk.MustExec("create table pt2 (a int,b int) partition by range(a) (" +
Expand Down

0 comments on commit 8db6a00

Please sign in to comment.