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

ddl: Add telementry for distributed reorg tasks. #41201

Merged
merged 14 commits into from
Feb 10, 2023
Merged
9 changes: 8 additions & 1 deletion ddl/dist_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/sessionctx"
Expand All @@ -33,7 +34,10 @@ import (
)

// CheckBackfillJobFinishInterval is export for test.
var CheckBackfillJobFinishInterval = 300 * time.Millisecond
var (
CheckBackfillJobFinishInterval = 300 * time.Millisecond
telemetryDistReorgUsage = metrics.TelemetryDistReorgCnt
)

func initDistReorg(reorgMeta *model.DDLReorgMeta, store kv.Storage, schemaID int64, tblInfo *model.TableInfo) error {
tbl, err := getTable(store, schemaID, tblInfo)
Expand All @@ -47,6 +51,9 @@ func initDistReorg(reorgMeta *model.DDLReorgMeta, store kv.Storage, schemaID int
isDistReorg = false
}
reorgMeta.IsDistReorg = isDistReorg
if isDistReorg {
metrics.TelemetryDistReorgCnt.Inc()
}
return nil
}

Expand Down
10 changes: 10 additions & 0 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",
})
TelemetryDistReorgCnt = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "telemetry",
Name: "Distributed_reorg_count",
Benjamin2037 marked this conversation as resolved.
Show resolved Hide resolved
Help: "Counter of usage of distributed reorg DDL tasks count",
})
)

// readCounter reads the value of a prometheus.Counter.
Expand Down Expand Up @@ -386,13 +393,15 @@ type DDLUsageCounter struct {
AddIndexIngestUsed int64 `json:"add_index_ingest_used"`
MetadataLockUsed bool `json:"metadata_lock_used"`
FlashbackClusterUsed int64 `json:"flashback_cluster_used"`
DistReorgUsed int64 `json:"dist_reorg_used"`
}

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

Expand All @@ -401,6 +410,7 @@ func GetDDLUsageCounter() DDLUsageCounter {
return DDLUsageCounter{
AddIndexIngestUsed: readCounter(TelemetryAddIndexIngestCnt),
FlashbackClusterUsed: readCounter(TelemetryFlashbackClusterCnt),
DistReorgUsed: readCounter(TelemetryDistReorgCnt),
}
}

Expand Down
31 changes: 31 additions & 0 deletions telemetry/data_feature_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,37 @@ func TestAddIndexAccelerationAndMDL(t *testing.T) {
require.Equal(t, true, usage.DDLUsageCounter.MetadataLockUsed)
}

func TestDistReorgUsage(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
usage, err := telemetry.GetFeatureUsage(tk.Session())
require.Equal(t, int64(0), usage.DDLUsageCounter.DistReorgUsed)
require.NoError(t, err)

tk.MustExec("set @@global.tidb_ddl_distribute_reorg = off")
allow := variable.DDLEnableDistributeReorg.Load()
require.Equal(t, false, allow)
Benjamin2037 marked this conversation as resolved.
Show resolved Hide resolved
tk.MustExec("use test")
tk.MustExec("drop table if exists tele_t")
tk.MustExec("create table tele_t(id int, b int)")
tk.MustExec("insert into tele_t values(1,1),(2,2);")
tk.MustExec("alter table tele_t add index idx_org(b)")
usage, err = telemetry.GetFeatureUsage(tk.Session())
require.NoError(t, err)
require.Equal(t, int64(0), usage.DDLUsageCounter.DistReorgUsed)

tk.MustExec("set @@global.tidb_ddl_distribute_reorg = on")
allow = variable.DDLEnableDistributeReorg.Load()
require.Equal(t, true, allow)
usage, err = telemetry.GetFeatureUsage(tk.Session())
require.NoError(t, err)
require.Equal(t, int64(0), usage.DDLUsageCounter.DistReorgUsed)
tk.MustExec("alter table tele_t add index idx_new(b)")
usage, err = telemetry.GetFeatureUsage(tk.Session())
require.NoError(t, err)
require.Equal(t, int64(1), usage.DDLUsageCounter.DistReorgUsed)
}

func TestGlobalMemoryControl(t *testing.T) {
store := testkit.CreateMockStore(t)

Expand Down