From e7d6abf6ed42483722d1895f83e907e300bafba4 Mon Sep 17 00:00:00 2001 From: littlelittlehorse Date: Mon, 11 Jul 2022 22:59:11 +0800 Subject: [PATCH 1/7] location mark --- ddl/partition.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ddl/partition.go b/ddl/partition.go index 3ab281c7f1afc..9b6212ad4da39 100644 --- a/ddl/partition.go +++ b/ddl/partition.go @@ -416,6 +416,9 @@ func buildTablePartitionInfo(ctx sessionctx.Context, s *ast.PartitionOptions, tb return nil } + // telemetry for partition table. + // partition table total number and different type of partition table number. + var enable bool switch s.Tp { case model.PartitionTypeRange: From 88f9d89a1838d537c9d43ac24db868470974ac68 Mon Sep 17 00:00:00 2001 From: littlelittlehorse Date: Thu, 14 Jul 2022 10:06:49 +0800 Subject: [PATCH 2/7] add telemetry --- ddl/partition.go | 4 -- executor/adapter.go | 11 +++ executor/builder.go | 46 ++++++++++++ executor/compiler.go | 2 +- executor/prepared.go | 2 +- metrics/telemetry.go | 100 +++++++++++++++++++++++++++ session/session.go | 33 ++++++++- telemetry/data.go | 5 ++ telemetry/data_feature_usage.go | 14 ++++ telemetry/data_feature_usage_test.go | 45 ++++++++++++ 10 files changed, 253 insertions(+), 9 deletions(-) diff --git a/ddl/partition.go b/ddl/partition.go index 9b6212ad4da39..c32f47b88a525 100644 --- a/ddl/partition.go +++ b/ddl/partition.go @@ -415,10 +415,6 @@ func buildTablePartitionInfo(ctx sessionctx.Context, s *ast.PartitionOptions, tb ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ErrTablePartitionDisabled) return nil } - - // telemetry for partition table. - // partition table total number and different type of partition table number. - var enable bool switch s.Tp { case model.PartitionTypeRange: diff --git a/executor/adapter.go b/executor/adapter.go index b1a759cc1be27..a33ab762b5398 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -192,6 +192,17 @@ type TelemetryInfo struct { UseNonRecursive bool UseRecursive bool UseMultiSchemaChange bool + PartitionTelemetry *PartitionTelemetryInfo +} + +type PartitionTelemetryInfo struct { + UseTablePartition bool + UseTablePartitionList bool + UseTablePartitionRange bool + UseTablePartitionHash bool + UseTablePartitionRangeColumns bool + UseTablePartitionListColumns bool + UseTablePartitionMaxPartition int64 } // ExecStmt implements the sqlexec.Statement interface, it builds a planner.Plan to an sqlexec.Statement. diff --git a/executor/builder.go b/executor/builder.go index 64eef464bd384..0cf1a48757049 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -60,6 +60,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/collate" "github.com/pingcap/tidb/util/cteutil" + "github.com/pingcap/tidb/util/dbterror" "github.com/pingcap/tidb/util/execdetails" "github.com/pingcap/tidb/util/mathutil" "github.com/pingcap/tidb/util/memory" @@ -988,7 +989,52 @@ func (b *executorBuilder) buildDDL(v *plannercore.DDL) Executor { if len(v.Statement.(*ast.AlterTableStmt).Specs) > 1 && b.Ti != nil { b.Ti.UseMultiSchemaChange = true } + case *ast.CreateTableStmt: + stmt := v.Statement.(*ast.CreateTableStmt) + if stmt != nil && stmt.Partition != nil { + if strings.EqualFold(b.ctx.GetSessionVars().EnableTablePartition, "OFF") { + b.ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ErrTablePartitionDisabled) + break + } + + s := stmt.Partition + b.Ti.PartitionTelemetry.UseTablePartitionMaxPartition = int64(s.Num) + b.Ti.PartitionTelemetry.UseTablePartition = true + switch s.Tp { + case model.PartitionTypeRange: + if s.Sub == nil { + if s.ColumnNames == nil { + b.Ti.PartitionTelemetry.UseTablePartitionRange = true + } + if len(s.ColumnNames) == 1 { + b.Ti.PartitionTelemetry.UseTablePartitionRange = true + } + if len(s.ColumnNames) > 1 { + b.Ti.PartitionTelemetry.UseTablePartitionRangeColumns = true + } + } + case model.PartitionTypeHash: + if !s.Linear && s.Sub == nil { + b.Ti.PartitionTelemetry.UseTablePartitionHash = true + } + case model.PartitionTypeList: + enable := b.ctx.GetSessionVars().EnableListTablePartition + if s.Sub == nil && enable { + if s.ColumnNames == nil { + b.Ti.PartitionTelemetry.UseTablePartitionList = true + } + if len(s.ColumnNames) == 1 { + b.Ti.PartitionTelemetry.UseTablePartitionList = true + } + if len(s.ColumnNames) > 1 { + b.Ti.PartitionTelemetry.UseTablePartitionListColumns = true + } + } + + } + } } + e := &DDLExec{ baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ID()), stmt: v.Statement, diff --git a/executor/compiler.go b/executor/compiler.go index f4633c85f70c6..79be41f384963 100644 --- a/executor/compiler.go +++ b/executor/compiler.go @@ -99,7 +99,7 @@ func (c *Compiler) Compile(ctx context.Context, stmtNode ast.StmtNode) (*ExecStm StmtNode: stmtNode, Ctx: c.Ctx, OutputNames: names, - Ti: &TelemetryInfo{}, + Ti: &TelemetryInfo{PartitionTelemetry: &PartitionTelemetryInfo{}}, }, nil } diff --git a/executor/prepared.go b/executor/prepared.go index dcfe727d6b024..5b9142ddfa73e 100644 --- a/executor/prepared.go +++ b/executor/prepared.go @@ -339,7 +339,7 @@ func CompileExecutePreparedStmt(ctx context.Context, sctx sessionctx.Context, StmtNode: execStmt, Ctx: sctx, OutputNames: names, - Ti: &TelemetryInfo{}, + Ti: &TelemetryInfo{PartitionTelemetry: &PartitionTelemetryInfo{}}, } if preparedPointer, ok := sctx.GetSessionVars().PreparedStmts[execStmt.ExecID]; ok { preparedObj, ok := preparedPointer.(*plannercore.CachedPrepareStmt) diff --git a/metrics/telemetry.go b/metrics/telemetry.go index 79bcbf7c9f9a1..75d13302656bb 100644 --- a/metrics/telemetry.go +++ b/metrics/telemetry.go @@ -15,6 +15,7 @@ package metrics import ( + "github.com/pingcap/tidb/util/mathutil" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" ) @@ -35,6 +36,55 @@ var ( Name: "multi_schema_change_usage", Help: "Counter of usage of multi-schema change", }) + TelemetryTablePartitionCnt = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: "tidb", + Subsystem: "telemetry", + Name: "table_partition_usage", + Help: "Counter of usage of table partition", + }) + TelemetryTablePartitionListCnt = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: "tidb", + Subsystem: "telemetry", + Name: "table_partition_list_usage", + Help: "Counter of usage of table partition list", + }) + TelemetryTablePartitionRangeCnt = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: "tidb", + Subsystem: "telemetry", + Name: "table_partition_range_usage", + Help: "Counter of usage of table partition range", + }) + TelemetryTablePartitionHashCnt = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: "tidb", + Subsystem: "telemetry", + Name: "table_partition_hash_usage", + Help: "Counter of usage of table partition hash", + }) + TelemetryTablePartitionRangeColumnsCnt = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: "tidb", + Subsystem: "telemetry", + Name: "table_partition_range_columns_usage", + Help: "Counter of usage of table partition range columns", + }) + TelemetryTablePartitionListColumnsCnt = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: "tidb", + Subsystem: "telemetry", + Name: "table_partition_list_columns_usage", + Help: "Counter of usage of table list columns partition list columns", + }) + TelemetryTablePartitionMaxPartition = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: "tidb", + Subsystem: "telemetry", + Name: "table_partition_max_partition_usage", + Help: "Counter of usage of table partition max partition", + }) ) // readCounter reads the value of a prometheus.Counter. @@ -94,6 +144,56 @@ func GetMultiSchemaCounter() MultiSchemaChangeUsageCounter { } } +// TablePartitionUsageCounter records the usages of table partition. +type TablePartitionUsageCounter struct { + TablePartitionUsed int64 `json:"table_partition_used"` + TablePartitionListUsed int64 `json:"table_partition_list_used"` + TablePartitionRangeUsed int64 `json:"table_partition_range_used"` + TablePartitionHashUsed int64 `json:"table_partition_hash_used"` + TablePartitionRangeColumnsUsed int64 `json:"table_partition_range_columns_used"` + TablePartitionListColumnsUsed int64 `json:"table_partition_list_columns_used"` + TablePartitionMaxPartitionUsed int64 `json:"table_partition_max_partition_used"` +} + +// Cal returns the difference of two counters. +func (c TablePartitionUsageCounter) Cal(rhs TablePartitionUsageCounter) TablePartitionUsageCounter { + return TablePartitionUsageCounter{ + TablePartitionUsed: c.TablePartitionUsed - rhs.TablePartitionUsed, + TablePartitionListUsed: c.TablePartitionListUsed - rhs.TablePartitionListUsed, + TablePartitionRangeUsed: c.TablePartitionRangeUsed - rhs.TablePartitionRangeUsed, + TablePartitionHashUsed: c.TablePartitionHashUsed - rhs.TablePartitionHashUsed, + TablePartitionRangeColumnsUsed: c.TablePartitionRangeColumnsUsed - rhs.TablePartitionRangeColumnsUsed, + TablePartitionListColumnsUsed: c.TablePartitionListColumnsUsed - rhs.TablePartitionListColumnsUsed, + TablePartitionMaxPartitionUsed: mathutil.Max(c.TablePartitionMaxPartitionUsed-rhs.TablePartitionMaxPartitionUsed, rhs.TablePartitionMaxPartitionUsed), + } +} + +// ResetTablePartitionCounter gets the TxnCommitCounter. +func ResetTablePartitionCounter(pre TablePartitionUsageCounter) TablePartitionUsageCounter { + return TablePartitionUsageCounter{ + TablePartitionUsed: readCounter(TelemetryTablePartitionCnt), + TablePartitionListUsed: readCounter(TelemetryTablePartitionListCnt), + TablePartitionRangeUsed: readCounter(TelemetryTablePartitionRangeCnt), + TablePartitionHashUsed: readCounter(TelemetryTablePartitionHashCnt), + TablePartitionRangeColumnsUsed: readCounter(TelemetryTablePartitionRangeColumnsCnt), + TablePartitionListColumnsUsed: readCounter(TelemetryTablePartitionListColumnsCnt), + TablePartitionMaxPartitionUsed: mathutil.Max(readCounter(TelemetryTablePartitionMaxPartition)-pre.TablePartitionMaxPartitionUsed, pre.TablePartitionMaxPartitionUsed), + } +} + +// GetTablePartitionCounter gets the TxnCommitCounter. +func GetTablePartitionCounter() TablePartitionUsageCounter { + return TablePartitionUsageCounter{ + TablePartitionUsed: readCounter(TelemetryTablePartitionCnt), + TablePartitionListUsed: readCounter(TelemetryTablePartitionListCnt), + TablePartitionRangeUsed: readCounter(TelemetryTablePartitionRangeCnt), + TablePartitionHashUsed: readCounter(TelemetryTablePartitionHashCnt), + TablePartitionRangeColumnsUsed: readCounter(TelemetryTablePartitionRangeColumnsCnt), + TablePartitionListColumnsUsed: readCounter(TelemetryTablePartitionListColumnsCnt), + TablePartitionMaxPartitionUsed: readCounter(TelemetryTablePartitionMaxPartition), + } +} + // NonTransactionalStmtCounter records the usages of non-transactional statements. type NonTransactionalStmtCounter struct { DeleteCount int64 `json:"delete"` diff --git a/session/session.go b/session/session.go index 91c38e8322e43..ee44fbf5eab65 100644 --- a/session/session.go +++ b/session/session.go @@ -121,8 +121,15 @@ var ( sessionExecuteParseDurationInternal = metrics.SessionExecuteParseDuration.WithLabelValues(metrics.LblInternal) sessionExecuteParseDurationGeneral = metrics.SessionExecuteParseDuration.WithLabelValues(metrics.LblGeneral) - telemetryCTEUsage = metrics.TelemetrySQLCTECnt - telemetryMultiSchemaChangeUsage = metrics.TelemetryMultiSchemaChangeCnt + telemetryCTEUsage = metrics.TelemetrySQLCTECnt + telemetryMultiSchemaChangeUsage = metrics.TelemetryMultiSchemaChangeCnt + telemetryTablePartitionUsage = metrics.TelemetryTablePartitionCnt + telemetryTablePartitionListUsage = metrics.TelemetryTablePartitionListCnt + telemetryTablePartitionRangeUsage = metrics.TelemetryTablePartitionRangeCnt + telemetryTablePartitionHashUsage = metrics.TelemetryTablePartitionHashCnt + telemetryTablePartitionRangeColumnsUsage = metrics.TelemetryTablePartitionRangeColumnsCnt + telemetryTablePartitionListColumnsUsage = metrics.TelemetryTablePartitionListColumnsCnt + telemetryTablePartitionMaxPartitionUsage = metrics.TelemetryTablePartitionMaxPartition ) // Session context, it is consistent with the lifecycle of a client connection. @@ -2301,7 +2308,7 @@ func (s *session) cachedPointPlanExec(ctx context.Context, Ctx: s, OutputNames: execPlan.OutputNames(), PsStmt: prepareStmt, - Ti: &executor.TelemetryInfo{}, + Ti: &executor.TelemetryInfo{PartitionTelemetry: &executor.PartitionTelemetryInfo{}}, } compileDuration := time.Since(s.sessionVars.StartTime) sessionExecuteCompileDurationGeneral.Observe(compileDuration.Seconds()) @@ -3336,6 +3343,26 @@ func (s *session) updateTelemetryMetric(es *executor.ExecStmt) { if ti.UseMultiSchemaChange { telemetryMultiSchemaChangeUsage.Inc() } + + if ti.PartitionTelemetry.UseTablePartition { + telemetryTablePartitionUsage.Inc() + telemetryTablePartitionMaxPartitionUsage.Add(float64(ti.PartitionTelemetry.UseTablePartitionMaxPartition)) + } + if ti.PartitionTelemetry.UseTablePartitionList { + telemetryTablePartitionListUsage.Inc() + } + if ti.PartitionTelemetry.UseTablePartitionRange { + telemetryTablePartitionRangeUsage.Inc() + } + if ti.PartitionTelemetry.UseTablePartitionHash { + telemetryTablePartitionHashUsage.Inc() + } + if ti.PartitionTelemetry.UseTablePartitionRangeColumns { + telemetryTablePartitionRangeUsage.Inc() + } + if ti.PartitionTelemetry.UseTablePartitionListColumns { + telemetryTablePartitionListColumnsUsage.Inc() + } } // GetBuiltinFunctionUsage returns the replica of counting of builtin function usage diff --git a/telemetry/data.go b/telemetry/data.go index 49bac14ce69f8..61d9fc9a6dff1 100644 --- a/telemetry/data.go +++ b/telemetry/data.go @@ -61,6 +61,11 @@ func postReportTelemetryData() { postReportTxnUsage() postReportCTEUsage() postReportMultiSchemaChangeUsage() + postReportTablePartitionUsage() postReportSlowQueryStats() postReportNonTransactionalCounter() } + +func PostReportTelemetryDataForTest() { + postReportTablePartitionUsage() +} diff --git a/telemetry/data_feature_usage.go b/telemetry/data_feature_usage.go index bc73153a84e15..8301f5661e018 100644 --- a/telemetry/data_feature_usage.go +++ b/telemetry/data_feature_usage.go @@ -47,6 +47,7 @@ type featureUsage struct { NonTransactionalUsage *m.NonTransactionalStmtCounter `json:"nonTransactional"` GlobalKill bool `json:"globalKill"` MultiSchemaChange *m.MultiSchemaChangeUsageCounter `json:"multiSchemaChange"` + TablePartition *m.TablePartitionUsageCounter `json:"tablePartition"` } type placementPolicyUsage struct { @@ -73,6 +74,8 @@ func getFeatureUsage(ctx context.Context, sctx sessionctx.Context) (*featureUsag usage.MultiSchemaChange = getMultiSchemaChangeUsageInfo() + usage.TablePartition = getTablePartitionUsageInfo() + usage.AutoCapture = getAutoCaptureUsageInfo(sctx) collectFeatureUsageFromInfoschema(sctx, &usage) @@ -205,6 +208,7 @@ var initialTxnCommitCounter metrics.TxnCommitCounter var initialCTECounter m.CTEUsageCounter var initialNonTransactionalCounter m.NonTransactionalStmtCounter var initialMultiSchemaChangeCounter m.MultiSchemaChangeUsageCounter +var initialTablePartitionCounter m.TablePartitionUsageCounter // getTxnUsageInfo gets the usage info of transaction related features. It's exported for tests. func getTxnUsageInfo(ctx sessionctx.Context) *TxnUsage { @@ -258,6 +262,16 @@ func getMultiSchemaChangeUsageInfo() *m.MultiSchemaChangeUsageCounter { return &diff } +func postReportTablePartitionUsage() { + initialTablePartitionCounter = m.ResetTablePartitionCounter(initialTablePartitionCounter) +} + +func getTablePartitionUsageInfo() *m.TablePartitionUsageCounter { + curr := m.GetTablePartitionCounter() + diff := curr.Cal(initialTablePartitionCounter) + return &diff +} + // getAutoCaptureUsageInfo gets the 'Auto Capture' usage func getAutoCaptureUsageInfo(ctx sessionctx.Context) bool { if val, err := variable.GetGlobalSystemVar(ctx.GetSessionVars(), variable.TiDBCapturePlanBaseline); err == nil { diff --git a/telemetry/data_feature_usage_test.go b/telemetry/data_feature_usage_test.go index d89928bbcc19d..120708ea135ee 100644 --- a/telemetry/data_feature_usage_test.go +++ b/telemetry/data_feature_usage_test.go @@ -161,6 +161,51 @@ func TestMultiSchemaChange(t *testing.T) { require.Equal(t, int64(2), usage.MultiSchemaChange.MultiSchemaChangeUsed) } +func TestTablePartition(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + + usage, err := telemetry.GetFeatureUsage(tk.Session()) + require.NoError(t, err) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionMaxPartitionUsed) + + tk.MustExec("drop table if exists pt") + tk.MustExec("create table pt (a int,b int) partition by hash(a) partitions 4;") + + usage, err = telemetry.GetFeatureUsage(tk.Session()) + require.NoError(t, err) + require.Equal(t, int64(1), usage.TablePartition.TablePartitionUsed) + require.Equal(t, int64(1), usage.TablePartition.TablePartitionHashUsed) + require.Equal(t, int64(4), usage.TablePartition.TablePartitionMaxPartitionUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeColumnsUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListColumnsUsed) + + telemetry.PostReportTelemetryDataForTest() + tk.MustExec("drop table if exists pt1") + tk.MustExec("create table pt1 (a int,b int) partition by range(a) (" + + "partition p0 values less than (3)," + + "partition p1 values less than (6), " + + "partition p2 values less than (9)," + + "partition p3 values less than (12)," + + "partition p4 values less than (15));") + usage, err = telemetry.GetFeatureUsage(tk.Session()) + require.NoError(t, err) + require.Equal(t, int64(1), usage.TablePartition.TablePartitionUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionHashUsed) + require.Equal(t, int64(5), usage.TablePartition.TablePartitionMaxPartitionUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListUsed) + require.Equal(t, int64(1), usage.TablePartition.TablePartitionRangeUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeColumnsUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListColumnsUsed) +} + func TestPlacementPolicies(t *testing.T) { store, clean := testkit.CreateMockStore(t) defer clean() From 0ad20dc63083c5ecce584aac8cb369470ab347ea Mon Sep 17 00:00:00 2001 From: littlelittlehorse Date: Thu, 14 Jul 2022 10:09:28 +0800 Subject: [PATCH 3/7] fix --- ddl/partition.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ddl/partition.go b/ddl/partition.go index c32f47b88a525..3ab281c7f1afc 100644 --- a/ddl/partition.go +++ b/ddl/partition.go @@ -415,6 +415,7 @@ func buildTablePartitionInfo(ctx sessionctx.Context, s *ast.PartitionOptions, tb ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ErrTablePartitionDisabled) return nil } + var enable bool switch s.Tp { case model.PartitionTypeRange: From f088b2141baad612944e7fb86f52790b0d4669b4 Mon Sep 17 00:00:00 2001 From: littlelittlehorse Date: Fri, 15 Jul 2022 11:54:56 +0800 Subject: [PATCH 4/7] address comment --- executor/adapter.go | 1 + executor/builder.go | 12 +++--------- telemetry/data.go | 1 + 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/executor/adapter.go b/executor/adapter.go index 99be61e635efd..a89c8f1556822 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -195,6 +195,7 @@ type TelemetryInfo struct { PartitionTelemetry *PartitionTelemetryInfo } +// PartitionTelemetryInfo records table partition telemetry information during execution. type PartitionTelemetryInfo struct { UseTablePartition bool UseTablePartitionList bool diff --git a/executor/builder.go b/executor/builder.go index 0cf1a48757049..b0cc403674442 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -60,7 +60,6 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/collate" "github.com/pingcap/tidb/util/cteutil" - "github.com/pingcap/tidb/util/dbterror" "github.com/pingcap/tidb/util/execdetails" "github.com/pingcap/tidb/util/mathutil" "github.com/pingcap/tidb/util/memory" @@ -993,7 +992,6 @@ func (b *executorBuilder) buildDDL(v *plannercore.DDL) Executor { stmt := v.Statement.(*ast.CreateTableStmt) if stmt != nil && stmt.Partition != nil { if strings.EqualFold(b.ctx.GetSessionVars().EnableTablePartition, "OFF") { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ErrTablePartitionDisabled) break } @@ -1003,14 +1001,10 @@ func (b *executorBuilder) buildDDL(v *plannercore.DDL) Executor { switch s.Tp { case model.PartitionTypeRange: if s.Sub == nil { - if s.ColumnNames == nil { - b.Ti.PartitionTelemetry.UseTablePartitionRange = true - } - if len(s.ColumnNames) == 1 { - b.Ti.PartitionTelemetry.UseTablePartitionRange = true - } - if len(s.ColumnNames) > 1 { + if len(s.ColumnNames) > 0 { b.Ti.PartitionTelemetry.UseTablePartitionRangeColumns = true + } else { + b.Ti.PartitionTelemetry.UseTablePartitionRange = true } } case model.PartitionTypeHash: diff --git a/telemetry/data.go b/telemetry/data.go index 61d9fc9a6dff1..e9156635d657e 100644 --- a/telemetry/data.go +++ b/telemetry/data.go @@ -66,6 +66,7 @@ func postReportTelemetryData() { postReportNonTransactionalCounter() } +// PostReportTelemetryDataForTest is for test. func PostReportTelemetryDataForTest() { postReportTablePartitionUsage() } From c5878d301d5d1bdefda43be40255db33660a8b76 Mon Sep 17 00:00:00 2001 From: littlelittlehorse Date: Fri, 15 Jul 2022 14:55:47 +0800 Subject: [PATCH 5/7] fix --- executor/adapter.go | 14 +++++----- executor/builder.go | 21 ++++++++------ executor/compiler.go | 2 +- executor/prepared.go | 2 +- metrics/telemetry.go | 24 ++++++++-------- session/session.go | 42 +++++++++++++++------------- telemetry/data_feature_usage_test.go | 10 +++---- 7 files changed, 61 insertions(+), 54 deletions(-) diff --git a/executor/adapter.go b/executor/adapter.go index a89c8f1556822..947c733cf77a2 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -197,13 +197,13 @@ type TelemetryInfo struct { // PartitionTelemetryInfo records table partition telemetry information during execution. type PartitionTelemetryInfo struct { - UseTablePartition bool - UseTablePartitionList bool - UseTablePartitionRange bool - UseTablePartitionHash bool - UseTablePartitionRangeColumns bool - UseTablePartitionListColumns bool - UseTablePartitionMaxPartition int64 + UseTablePartition bool + UseTablePartitionList bool + UseTablePartitionRange bool + UseTablePartitionHash bool + UseTablePartitionRangeColumns bool + UseTablePartitionListColumns bool + TablePartitionMaxPartitionsNum int64 } // ExecStmt implements the sqlexec.Statement interface, it builds a planner.Plan to an sqlexec.Statement. diff --git a/executor/builder.go b/executor/builder.go index b0cc403674442..12e065a032b7a 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -996,7 +996,16 @@ func (b *executorBuilder) buildDDL(v *plannercore.DDL) Executor { } s := stmt.Partition - b.Ti.PartitionTelemetry.UseTablePartitionMaxPartition = int64(s.Num) + + if b.Ti.PartitionTelemetry == nil { + b.Ti.PartitionTelemetry = &PartitionTelemetryInfo{} + } + if s.Num > 0 { + b.Ti.PartitionTelemetry.TablePartitionMaxPartitionsNum = int64(s.Num) + } else { + b.Ti.PartitionTelemetry.TablePartitionMaxPartitionsNum = int64(len(s.Definitions)) + } + b.Ti.PartitionTelemetry.UseTablePartition = true switch s.Tp { case model.PartitionTypeRange: @@ -1014,14 +1023,10 @@ func (b *executorBuilder) buildDDL(v *plannercore.DDL) Executor { case model.PartitionTypeList: enable := b.ctx.GetSessionVars().EnableListTablePartition if s.Sub == nil && enable { - if s.ColumnNames == nil { - b.Ti.PartitionTelemetry.UseTablePartitionList = true - } - if len(s.ColumnNames) == 1 { - b.Ti.PartitionTelemetry.UseTablePartitionList = true - } - if len(s.ColumnNames) > 1 { + if len(s.ColumnNames) > 0 { b.Ti.PartitionTelemetry.UseTablePartitionListColumns = true + } else { + b.Ti.PartitionTelemetry.UseTablePartitionList = true } } diff --git a/executor/compiler.go b/executor/compiler.go index 79be41f384963..f4633c85f70c6 100644 --- a/executor/compiler.go +++ b/executor/compiler.go @@ -99,7 +99,7 @@ func (c *Compiler) Compile(ctx context.Context, stmtNode ast.StmtNode) (*ExecStm StmtNode: stmtNode, Ctx: c.Ctx, OutputNames: names, - Ti: &TelemetryInfo{PartitionTelemetry: &PartitionTelemetryInfo{}}, + Ti: &TelemetryInfo{}, }, nil } diff --git a/executor/prepared.go b/executor/prepared.go index 5b9142ddfa73e..dcfe727d6b024 100644 --- a/executor/prepared.go +++ b/executor/prepared.go @@ -339,7 +339,7 @@ func CompileExecutePreparedStmt(ctx context.Context, sctx sessionctx.Context, StmtNode: execStmt, Ctx: sctx, OutputNames: names, - Ti: &TelemetryInfo{PartitionTelemetry: &PartitionTelemetryInfo{}}, + Ti: &TelemetryInfo{}, } if preparedPointer, ok := sctx.GetSessionVars().PreparedStmts[execStmt.ExecID]; ok { preparedObj, ok := preparedPointer.(*plannercore.CachedPrepareStmt) diff --git a/metrics/telemetry.go b/metrics/telemetry.go index 75d13302656bb..152c346597cb9 100644 --- a/metrics/telemetry.go +++ b/metrics/telemetry.go @@ -41,49 +41,49 @@ var ( Namespace: "tidb", Subsystem: "telemetry", Name: "table_partition_usage", - Help: "Counter of usage of table partition", + Help: "Counter of CREATE TABLE which includes of table partitioning", }) TelemetryTablePartitionListCnt = prometheus.NewCounter( prometheus.CounterOpts{ Namespace: "tidb", Subsystem: "telemetry", Name: "table_partition_list_usage", - Help: "Counter of usage of table partition list", + Help: "Counter of CREATE TABLE which includes LIST partitioning", }) TelemetryTablePartitionRangeCnt = prometheus.NewCounter( prometheus.CounterOpts{ Namespace: "tidb", Subsystem: "telemetry", Name: "table_partition_range_usage", - Help: "Counter of usage of table partition range", + Help: "Counter of CREATE TABLE which includes RANGE partitioning", }) TelemetryTablePartitionHashCnt = prometheus.NewCounter( prometheus.CounterOpts{ Namespace: "tidb", Subsystem: "telemetry", Name: "table_partition_hash_usage", - Help: "Counter of usage of table partition hash", + Help: "Counter of CREATE TABLE which includes HASH partitioning", }) TelemetryTablePartitionRangeColumnsCnt = prometheus.NewCounter( prometheus.CounterOpts{ Namespace: "tidb", Subsystem: "telemetry", Name: "table_partition_range_columns_usage", - Help: "Counter of usage of table partition range columns", + Help: "Counter of CREATE TABLE which includes RANGE COLUMNS partitioning", }) TelemetryTablePartitionListColumnsCnt = prometheus.NewCounter( prometheus.CounterOpts{ Namespace: "tidb", Subsystem: "telemetry", Name: "table_partition_list_columns_usage", - Help: "Counter of usage of table list columns partition list columns", + Help: "Counter of CREATE TABLE which includes LIST COLUMNS partitioning", }) - TelemetryTablePartitionMaxPartition = prometheus.NewCounter( + TelemetryTablePartitionMaxPartitionsCnt = prometheus.NewCounter( prometheus.CounterOpts{ Namespace: "tidb", Subsystem: "telemetry", Name: "table_partition_max_partition_usage", - Help: "Counter of usage of table partition max partition", + Help: "Counter of partitions created by CREATE TABLE statements", }) ) @@ -152,7 +152,7 @@ type TablePartitionUsageCounter struct { TablePartitionHashUsed int64 `json:"table_partition_hash_used"` TablePartitionRangeColumnsUsed int64 `json:"table_partition_range_columns_used"` TablePartitionListColumnsUsed int64 `json:"table_partition_list_columns_used"` - TablePartitionMaxPartitionUsed int64 `json:"table_partition_max_partition_used"` + TablePartitionMaxPartitionsNum int64 `json:"table_partition_max_partitions_num"` } // Cal returns the difference of two counters. @@ -164,7 +164,7 @@ func (c TablePartitionUsageCounter) Cal(rhs TablePartitionUsageCounter) TablePar TablePartitionHashUsed: c.TablePartitionHashUsed - rhs.TablePartitionHashUsed, TablePartitionRangeColumnsUsed: c.TablePartitionRangeColumnsUsed - rhs.TablePartitionRangeColumnsUsed, TablePartitionListColumnsUsed: c.TablePartitionListColumnsUsed - rhs.TablePartitionListColumnsUsed, - TablePartitionMaxPartitionUsed: mathutil.Max(c.TablePartitionMaxPartitionUsed-rhs.TablePartitionMaxPartitionUsed, rhs.TablePartitionMaxPartitionUsed), + TablePartitionMaxPartitionsNum: mathutil.Max(c.TablePartitionMaxPartitionsNum-rhs.TablePartitionMaxPartitionsNum, rhs.TablePartitionMaxPartitionsNum), } } @@ -177,7 +177,7 @@ func ResetTablePartitionCounter(pre TablePartitionUsageCounter) TablePartitionUs TablePartitionHashUsed: readCounter(TelemetryTablePartitionHashCnt), TablePartitionRangeColumnsUsed: readCounter(TelemetryTablePartitionRangeColumnsCnt), TablePartitionListColumnsUsed: readCounter(TelemetryTablePartitionListColumnsCnt), - TablePartitionMaxPartitionUsed: mathutil.Max(readCounter(TelemetryTablePartitionMaxPartition)-pre.TablePartitionMaxPartitionUsed, pre.TablePartitionMaxPartitionUsed), + TablePartitionMaxPartitionsNum: mathutil.Max(readCounter(TelemetryTablePartitionMaxPartitionsCnt)-pre.TablePartitionMaxPartitionsNum, pre.TablePartitionMaxPartitionsNum), } } @@ -190,7 +190,7 @@ func GetTablePartitionCounter() TablePartitionUsageCounter { TablePartitionHashUsed: readCounter(TelemetryTablePartitionHashCnt), TablePartitionRangeColumnsUsed: readCounter(TelemetryTablePartitionRangeColumnsCnt), TablePartitionListColumnsUsed: readCounter(TelemetryTablePartitionListColumnsCnt), - TablePartitionMaxPartitionUsed: readCounter(TelemetryTablePartitionMaxPartition), + TablePartitionMaxPartitionsNum: readCounter(TelemetryTablePartitionMaxPartitionsCnt), } } diff --git a/session/session.go b/session/session.go index e4fa46402380c..b30b594b5d5e3 100644 --- a/session/session.go +++ b/session/session.go @@ -129,7 +129,7 @@ var ( telemetryTablePartitionHashUsage = metrics.TelemetryTablePartitionHashCnt telemetryTablePartitionRangeColumnsUsage = metrics.TelemetryTablePartitionRangeColumnsCnt telemetryTablePartitionListColumnsUsage = metrics.TelemetryTablePartitionListColumnsCnt - telemetryTablePartitionMaxPartitionUsage = metrics.TelemetryTablePartitionMaxPartition + telemetryTablePartitionMaxPartitionUsage = metrics.TelemetryTablePartitionMaxPartitionsCnt ) // Session context, it is consistent with the lifecycle of a client connection. @@ -2311,7 +2311,7 @@ func (s *session) cachedPointPlanExec(ctx context.Context, Ctx: s, OutputNames: execPlan.OutputNames(), PsStmt: prepareStmt, - Ti: &executor.TelemetryInfo{PartitionTelemetry: &executor.PartitionTelemetryInfo{}}, + Ti: &executor.TelemetryInfo{}, } compileDuration := time.Since(s.sessionVars.StartTime) sessionExecuteCompileDurationGeneral.Observe(compileDuration.Seconds()) @@ -3347,24 +3347,26 @@ func (s *session) updateTelemetryMetric(es *executor.ExecStmt) { telemetryMultiSchemaChangeUsage.Inc() } - if ti.PartitionTelemetry.UseTablePartition { - telemetryTablePartitionUsage.Inc() - telemetryTablePartitionMaxPartitionUsage.Add(float64(ti.PartitionTelemetry.UseTablePartitionMaxPartition)) - } - if ti.PartitionTelemetry.UseTablePartitionList { - telemetryTablePartitionListUsage.Inc() - } - if ti.PartitionTelemetry.UseTablePartitionRange { - telemetryTablePartitionRangeUsage.Inc() - } - if ti.PartitionTelemetry.UseTablePartitionHash { - telemetryTablePartitionHashUsage.Inc() - } - if ti.PartitionTelemetry.UseTablePartitionRangeColumns { - telemetryTablePartitionRangeUsage.Inc() - } - if ti.PartitionTelemetry.UseTablePartitionListColumns { - telemetryTablePartitionListColumnsUsage.Inc() + if ti.PartitionTelemetry != nil { + if ti.PartitionTelemetry.UseTablePartition { + telemetryTablePartitionUsage.Inc() + telemetryTablePartitionMaxPartitionUsage.Add(float64(ti.PartitionTelemetry.TablePartitionMaxPartitionsNum)) + } + if ti.PartitionTelemetry.UseTablePartitionList { + telemetryTablePartitionListUsage.Inc() + } + if ti.PartitionTelemetry.UseTablePartitionRange { + telemetryTablePartitionRangeUsage.Inc() + } + if ti.PartitionTelemetry.UseTablePartitionHash { + telemetryTablePartitionHashUsage.Inc() + } + if ti.PartitionTelemetry.UseTablePartitionRangeColumns { + telemetryTablePartitionRangeUsage.Inc() + } + if ti.PartitionTelemetry.UseTablePartitionListColumns { + telemetryTablePartitionListColumnsUsage.Inc() + } } } diff --git a/telemetry/data_feature_usage_test.go b/telemetry/data_feature_usage_test.go index 120708ea135ee..f281b37ea035f 100644 --- a/telemetry/data_feature_usage_test.go +++ b/telemetry/data_feature_usage_test.go @@ -172,16 +172,16 @@ func TestTablePartition(t *testing.T) { require.NoError(t, err) require.Equal(t, int64(0), usage.TablePartition.TablePartitionUsed) require.Equal(t, int64(0), usage.TablePartition.TablePartitionListUsed) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionMaxPartitionUsed) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionMaxPartitionsNum) tk.MustExec("drop table if exists pt") - tk.MustExec("create table pt (a int,b int) partition by hash(a) partitions 4;") + tk.MustExec("create table pt (a int,b int) partition by hash(a) partitions 4") usage, err = telemetry.GetFeatureUsage(tk.Session()) require.NoError(t, err) require.Equal(t, int64(1), usage.TablePartition.TablePartitionUsed) require.Equal(t, int64(1), usage.TablePartition.TablePartitionHashUsed) - require.Equal(t, int64(4), usage.TablePartition.TablePartitionMaxPartitionUsed) + require.Equal(t, int64(4), usage.TablePartition.TablePartitionMaxPartitionsNum) require.Equal(t, int64(0), usage.TablePartition.TablePartitionListUsed) require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeUsed) require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeColumnsUsed) @@ -194,12 +194,12 @@ func TestTablePartition(t *testing.T) { "partition p1 values less than (6), " + "partition p2 values less than (9)," + "partition p3 values less than (12)," + - "partition p4 values less than (15));") + "partition p4 values less than (15))") usage, err = telemetry.GetFeatureUsage(tk.Session()) require.NoError(t, err) require.Equal(t, int64(1), usage.TablePartition.TablePartitionUsed) require.Equal(t, int64(0), usage.TablePartition.TablePartitionHashUsed) - require.Equal(t, int64(5), usage.TablePartition.TablePartitionMaxPartitionUsed) + require.Equal(t, int64(5), usage.TablePartition.TablePartitionMaxPartitionsNum) require.Equal(t, int64(0), usage.TablePartition.TablePartitionListUsed) require.Equal(t, int64(1), usage.TablePartition.TablePartitionRangeUsed) require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeColumnsUsed) From bdf2a7010d8cc1dec475efdf602b8a5597992c0b Mon Sep 17 00:00:00 2001 From: littlelittlehorse Date: Fri, 15 Jul 2022 22:56:36 +0800 Subject: [PATCH 6/7] fix --- executor/adapter.go | 2 +- executor/builder.go | 9 +---- metrics/telemetry.go | 56 ++++++++++++++-------------- session/session.go | 2 +- telemetry/data_feature_usage_test.go | 34 ++++++++--------- 5 files changed, 49 insertions(+), 54 deletions(-) diff --git a/executor/adapter.go b/executor/adapter.go index b03a0f8cdcbfb..e4f0a3fbcdda5 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -203,7 +203,7 @@ type PartitionTelemetryInfo struct { UseTablePartitionHash bool UseTablePartitionRangeColumns bool UseTablePartitionListColumns bool - TablePartitionMaxPartitionsNum int64 + TablePartitionMaxPartitionsNum uint64 } // ExecStmt implements the sqlexec.Statement interface, it builds a planner.Plan to an sqlexec.Statement. diff --git a/executor/builder.go b/executor/builder.go index 12e065a032b7a..f52f82a268dbc 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -996,17 +996,12 @@ func (b *executorBuilder) buildDDL(v *plannercore.DDL) Executor { } s := stmt.Partition - if b.Ti.PartitionTelemetry == nil { b.Ti.PartitionTelemetry = &PartitionTelemetryInfo{} } - if s.Num > 0 { - b.Ti.PartitionTelemetry.TablePartitionMaxPartitionsNum = int64(s.Num) - } else { - b.Ti.PartitionTelemetry.TablePartitionMaxPartitionsNum = int64(len(s.Definitions)) - } - + b.Ti.PartitionTelemetry.TablePartitionMaxPartitionsNum = mathutil.Max(s.Num, uint64(len(s.Definitions))) b.Ti.PartitionTelemetry.UseTablePartition = true + switch s.Tp { case model.PartitionTypeRange: if s.Sub == nil { diff --git a/metrics/telemetry.go b/metrics/telemetry.go index 152c346597cb9..53b42e46be851 100644 --- a/metrics/telemetry.go +++ b/metrics/telemetry.go @@ -146,51 +146,51 @@ func GetMultiSchemaCounter() MultiSchemaChangeUsageCounter { // TablePartitionUsageCounter records the usages of table partition. type TablePartitionUsageCounter struct { - TablePartitionUsed int64 `json:"table_partition_used"` - TablePartitionListUsed int64 `json:"table_partition_list_used"` - TablePartitionRangeUsed int64 `json:"table_partition_range_used"` - TablePartitionHashUsed int64 `json:"table_partition_hash_used"` - TablePartitionRangeColumnsUsed int64 `json:"table_partition_range_columns_used"` - TablePartitionListColumnsUsed int64 `json:"table_partition_list_columns_used"` - TablePartitionMaxPartitionsNum int64 `json:"table_partition_max_partitions_num"` + TablePartitionCnt int64 `json:"table_partition_cnt"` + TablePartitionListCnt int64 `json:"table_partition_list_cnt"` + TablePartitionRangeCnt int64 `json:"table_partition_range_cnt"` + TablePartitionHashCnt int64 `json:"table_partition_hash_cnt"` + TablePartitionRangeColumnsCnt int64 `json:"table_partition_range_columns_cnt"` + TablePartitionListColumnsCnt int64 `json:"table_partition_list_columns_cnt"` + TablePartitionMaxPartitionsCnt int64 `json:"table_partition_max_partitions_cnt"` } // Cal returns the difference of two counters. func (c TablePartitionUsageCounter) Cal(rhs TablePartitionUsageCounter) TablePartitionUsageCounter { return TablePartitionUsageCounter{ - TablePartitionUsed: c.TablePartitionUsed - rhs.TablePartitionUsed, - TablePartitionListUsed: c.TablePartitionListUsed - rhs.TablePartitionListUsed, - TablePartitionRangeUsed: c.TablePartitionRangeUsed - rhs.TablePartitionRangeUsed, - TablePartitionHashUsed: c.TablePartitionHashUsed - rhs.TablePartitionHashUsed, - TablePartitionRangeColumnsUsed: c.TablePartitionRangeColumnsUsed - rhs.TablePartitionRangeColumnsUsed, - TablePartitionListColumnsUsed: c.TablePartitionListColumnsUsed - rhs.TablePartitionListColumnsUsed, - TablePartitionMaxPartitionsNum: mathutil.Max(c.TablePartitionMaxPartitionsNum-rhs.TablePartitionMaxPartitionsNum, rhs.TablePartitionMaxPartitionsNum), + TablePartitionCnt: c.TablePartitionCnt - rhs.TablePartitionCnt, + TablePartitionListCnt: c.TablePartitionListCnt - rhs.TablePartitionListCnt, + TablePartitionRangeCnt: c.TablePartitionRangeCnt - rhs.TablePartitionRangeCnt, + TablePartitionHashCnt: c.TablePartitionHashCnt - rhs.TablePartitionHashCnt, + TablePartitionRangeColumnsCnt: c.TablePartitionRangeColumnsCnt - rhs.TablePartitionRangeColumnsCnt, + TablePartitionListColumnsCnt: c.TablePartitionListColumnsCnt - rhs.TablePartitionListColumnsCnt, + TablePartitionMaxPartitionsCnt: mathutil.Max(c.TablePartitionMaxPartitionsCnt-rhs.TablePartitionMaxPartitionsCnt, rhs.TablePartitionMaxPartitionsCnt), } } // ResetTablePartitionCounter gets the TxnCommitCounter. func ResetTablePartitionCounter(pre TablePartitionUsageCounter) TablePartitionUsageCounter { return TablePartitionUsageCounter{ - TablePartitionUsed: readCounter(TelemetryTablePartitionCnt), - TablePartitionListUsed: readCounter(TelemetryTablePartitionListCnt), - TablePartitionRangeUsed: readCounter(TelemetryTablePartitionRangeCnt), - TablePartitionHashUsed: readCounter(TelemetryTablePartitionHashCnt), - TablePartitionRangeColumnsUsed: readCounter(TelemetryTablePartitionRangeColumnsCnt), - TablePartitionListColumnsUsed: readCounter(TelemetryTablePartitionListColumnsCnt), - TablePartitionMaxPartitionsNum: mathutil.Max(readCounter(TelemetryTablePartitionMaxPartitionsCnt)-pre.TablePartitionMaxPartitionsNum, pre.TablePartitionMaxPartitionsNum), + TablePartitionCnt: readCounter(TelemetryTablePartitionCnt), + TablePartitionListCnt: readCounter(TelemetryTablePartitionListCnt), + TablePartitionRangeCnt: readCounter(TelemetryTablePartitionRangeCnt), + TablePartitionHashCnt: readCounter(TelemetryTablePartitionHashCnt), + TablePartitionRangeColumnsCnt: readCounter(TelemetryTablePartitionRangeColumnsCnt), + TablePartitionListColumnsCnt: readCounter(TelemetryTablePartitionListColumnsCnt), + TablePartitionMaxPartitionsCnt: mathutil.Max(readCounter(TelemetryTablePartitionMaxPartitionsCnt)-pre.TablePartitionMaxPartitionsCnt, pre.TablePartitionMaxPartitionsCnt), } } // GetTablePartitionCounter gets the TxnCommitCounter. func GetTablePartitionCounter() TablePartitionUsageCounter { return TablePartitionUsageCounter{ - TablePartitionUsed: readCounter(TelemetryTablePartitionCnt), - TablePartitionListUsed: readCounter(TelemetryTablePartitionListCnt), - TablePartitionRangeUsed: readCounter(TelemetryTablePartitionRangeCnt), - TablePartitionHashUsed: readCounter(TelemetryTablePartitionHashCnt), - TablePartitionRangeColumnsUsed: readCounter(TelemetryTablePartitionRangeColumnsCnt), - TablePartitionListColumnsUsed: readCounter(TelemetryTablePartitionListColumnsCnt), - TablePartitionMaxPartitionsNum: readCounter(TelemetryTablePartitionMaxPartitionsCnt), + TablePartitionCnt: readCounter(TelemetryTablePartitionCnt), + TablePartitionListCnt: readCounter(TelemetryTablePartitionListCnt), + TablePartitionRangeCnt: readCounter(TelemetryTablePartitionRangeCnt), + TablePartitionHashCnt: readCounter(TelemetryTablePartitionHashCnt), + TablePartitionRangeColumnsCnt: readCounter(TelemetryTablePartitionRangeColumnsCnt), + TablePartitionListColumnsCnt: readCounter(TelemetryTablePartitionListColumnsCnt), + TablePartitionMaxPartitionsCnt: readCounter(TelemetryTablePartitionMaxPartitionsCnt), } } diff --git a/session/session.go b/session/session.go index 15f4964f2fa3f..d8932b84d4887 100644 --- a/session/session.go +++ b/session/session.go @@ -3364,7 +3364,7 @@ func (s *session) updateTelemetryMetric(es *executor.ExecStmt) { telemetryTablePartitionHashUsage.Inc() } if ti.PartitionTelemetry.UseTablePartitionRangeColumns { - telemetryTablePartitionRangeUsage.Inc() + telemetryTablePartitionRangeColumnsUsage.Inc() } if ti.PartitionTelemetry.UseTablePartitionListColumns { telemetryTablePartitionListColumnsUsage.Inc() diff --git a/telemetry/data_feature_usage_test.go b/telemetry/data_feature_usage_test.go index f281b37ea035f..6eb46a13b881b 100644 --- a/telemetry/data_feature_usage_test.go +++ b/telemetry/data_feature_usage_test.go @@ -170,22 +170,22 @@ func TestTablePartition(t *testing.T) { usage, err := telemetry.GetFeatureUsage(tk.Session()) require.NoError(t, err) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionUsed) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionListUsed) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionMaxPartitionsNum) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionMaxPartitionsCnt) tk.MustExec("drop table if exists pt") tk.MustExec("create table pt (a int,b int) partition by hash(a) partitions 4") usage, err = telemetry.GetFeatureUsage(tk.Session()) require.NoError(t, err) - require.Equal(t, int64(1), usage.TablePartition.TablePartitionUsed) - require.Equal(t, int64(1), usage.TablePartition.TablePartitionHashUsed) - require.Equal(t, int64(4), usage.TablePartition.TablePartitionMaxPartitionsNum) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionListUsed) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeUsed) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeColumnsUsed) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionListColumnsUsed) + require.Equal(t, int64(1), usage.TablePartition.TablePartitionCnt) + require.Equal(t, int64(1), usage.TablePartition.TablePartitionHashCnt) + require.Equal(t, int64(4), usage.TablePartition.TablePartitionMaxPartitionsCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeColumnsCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListColumnsCnt) telemetry.PostReportTelemetryDataForTest() tk.MustExec("drop table if exists pt1") @@ -197,13 +197,13 @@ func TestTablePartition(t *testing.T) { "partition p4 values less than (15))") usage, err = telemetry.GetFeatureUsage(tk.Session()) require.NoError(t, err) - require.Equal(t, int64(1), usage.TablePartition.TablePartitionUsed) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionHashUsed) - require.Equal(t, int64(5), usage.TablePartition.TablePartitionMaxPartitionsNum) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionListUsed) - require.Equal(t, int64(1), usage.TablePartition.TablePartitionRangeUsed) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeColumnsUsed) - require.Equal(t, int64(0), usage.TablePartition.TablePartitionListColumnsUsed) + require.Equal(t, int64(1), usage.TablePartition.TablePartitionCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionHashCnt) + require.Equal(t, int64(5), usage.TablePartition.TablePartitionMaxPartitionsCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListCnt) + require.Equal(t, int64(1), usage.TablePartition.TablePartitionRangeCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionRangeColumnsCnt) + require.Equal(t, int64(0), usage.TablePartition.TablePartitionListColumnsCnt) } func TestPlacementPolicies(t *testing.T) { From 733c646f024888b8638b149c21bffba447c2cd67 Mon Sep 17 00:00:00 2001 From: littlelittlehorse Date: Fri, 15 Jul 2022 22:59:37 +0800 Subject: [PATCH 7/7] fix --- session/session.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/session/session.go b/session/session.go index d8932b84d4887..a1941eb0990b6 100644 --- a/session/session.go +++ b/session/session.go @@ -121,15 +121,15 @@ var ( sessionExecuteParseDurationInternal = metrics.SessionExecuteParseDuration.WithLabelValues(metrics.LblInternal) sessionExecuteParseDurationGeneral = metrics.SessionExecuteParseDuration.WithLabelValues(metrics.LblGeneral) - telemetryCTEUsage = metrics.TelemetrySQLCTECnt - telemetryMultiSchemaChangeUsage = metrics.TelemetryMultiSchemaChangeCnt - telemetryTablePartitionUsage = metrics.TelemetryTablePartitionCnt - telemetryTablePartitionListUsage = metrics.TelemetryTablePartitionListCnt - telemetryTablePartitionRangeUsage = metrics.TelemetryTablePartitionRangeCnt - telemetryTablePartitionHashUsage = metrics.TelemetryTablePartitionHashCnt - telemetryTablePartitionRangeColumnsUsage = metrics.TelemetryTablePartitionRangeColumnsCnt - telemetryTablePartitionListColumnsUsage = metrics.TelemetryTablePartitionListColumnsCnt - telemetryTablePartitionMaxPartitionUsage = metrics.TelemetryTablePartitionMaxPartitionsCnt + telemetryCTEUsage = metrics.TelemetrySQLCTECnt + telemetryMultiSchemaChangeUsage = metrics.TelemetryMultiSchemaChangeCnt + telemetryTablePartitionUsage = metrics.TelemetryTablePartitionCnt + telemetryTablePartitionListUsage = metrics.TelemetryTablePartitionListCnt + telemetryTablePartitionRangeUsage = metrics.TelemetryTablePartitionRangeCnt + telemetryTablePartitionHashUsage = metrics.TelemetryTablePartitionHashCnt + telemetryTablePartitionRangeColumnsUsage = metrics.TelemetryTablePartitionRangeColumnsCnt + telemetryTablePartitionListColumnsUsage = metrics.TelemetryTablePartitionListColumnsCnt + telemetryTablePartitionMaxPartitionsUsage = metrics.TelemetryTablePartitionMaxPartitionsCnt ) // Session context, it is consistent with the lifecycle of a client connection. @@ -3352,7 +3352,7 @@ func (s *session) updateTelemetryMetric(es *executor.ExecStmt) { if ti.PartitionTelemetry != nil { if ti.PartitionTelemetry.UseTablePartition { telemetryTablePartitionUsage.Inc() - telemetryTablePartitionMaxPartitionUsage.Add(float64(ti.PartitionTelemetry.TablePartitionMaxPartitionsNum)) + telemetryTablePartitionMaxPartitionsUsage.Add(float64(ti.PartitionTelemetry.TablePartitionMaxPartitionsNum)) } if ti.PartitionTelemetry.UseTablePartitionList { telemetryTablePartitionListUsage.Inc()