diff --git a/config/config.go b/config/config.go index f7b4dd197833c..fa348a8a6fe6d 100644 --- a/config/config.go +++ b/config/config.go @@ -138,6 +138,8 @@ type Config struct { Experimental Experimental `toml:"experimental" json:"experimental"` // EnableCollectExecutionInfo enables the TiDB to collect execution info. EnableCollectExecutionInfo bool `toml:"enable-collect-execution-info" json:"enable-collect-execution-info"` + // SkipRegisterToDashboard tells TiDB don't register itself to the dashboard. + SkipRegisterToDashboard bool `toml:"skip-register-to-dashboard" json:"skip-register-to-dashboard"` // EnableTelemetry enables the usage data report to PingCAP. EnableTelemetry bool `toml:"enable-telemetry" json:"enable-telemetry"` } diff --git a/config/config.toml.example b/config/config.toml.example index 6e125497a76a8..e531a4a5627e9 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -106,6 +106,11 @@ max-server-connections = 0 # Whether new collations are enabled, as indicated by its name, this configuration entry take effect ONLY when a TiDB cluster bootstraps for the first time. new_collations_enabled_on_first_bootstrap = false +# Don't register information of this TiDB to etcd, so this instance of TiDB won't appear in the services like dashboard. +# This option is useful when you want to embed TiDB into your service(i.e. use TiDB as a library). +# *If you want to start a TiDB service, NEVER enable this.* +skip-register-to-dashboard = false + # When enabled, usage data (for example, instance versions) will be reported to PingCAP periodically for user experience analytics. # If this config is set to `false` on all TiDB servers, telemetry will be always disabled regardless of the value of the global variable `tidb_enable_telemetry`. # See PingCAP privacy policy for details: https://pingcap.com/en/privacy-policy/ diff --git a/config/config_test.go b/config/config_test.go index 39fdda99f72e2..c56affa2c43f1 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -189,6 +189,7 @@ repair-mode = true max-server-connections = 200 mem-quota-query = 10000 max-index-length = 3080 +skip-register-to-dashboard = true [performance] txn-total-size-limit=2000 [tikv-client] @@ -247,6 +248,7 @@ engines = ["tiflash"] c.Assert(conf.Experimental.AllowAutoRandom, IsTrue) c.Assert(conf.IsolationRead.Engines, DeepEquals, []string{"tiflash"}) c.Assert(conf.MaxIndexLength, Equals, 3080) + c.Assert(conf.SkipRegisterToDashboard, Equals, true) _, err = f.WriteString(` [log.file] diff --git a/domain/domain.go b/domain/domain.go index 06cf347c93697..44d11e2c874e9 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -713,11 +713,12 @@ func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.R } }) + skipRegisterToDashboard := config.GetGlobalConfig().SkipRegisterToDashboard err = do.ddl.SchemaSyncer().Init(ctx) if err != nil { return err } - do.info, err = infosync.GlobalInfoSyncerInit(ctx, do.ddl.GetID(), do.etcdClient) + do.info, err = infosync.GlobalInfoSyncerInit(ctx, do.ddl.GetID(), do.etcdClient, skipRegisterToDashboard) if err != nil { return err } @@ -739,8 +740,10 @@ func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.R do.wg.Add(1) go do.infoSyncerKeeper() - do.wg.Add(1) - go do.topologySyncerKeeper() + if !skipRegisterToDashboard { + do.wg.Add(1) + go do.topologySyncerKeeper() + } return nil } diff --git a/domain/infosync/info.go b/domain/infosync/info.go index 9fc07fbf80ffe..0eb6eca2eb888 100644 --- a/domain/infosync/info.go +++ b/domain/infosync/info.go @@ -128,14 +128,14 @@ func setGlobalInfoSyncer(is *InfoSyncer) { } // GlobalInfoSyncerInit return a new InfoSyncer. It is exported for testing. -func GlobalInfoSyncerInit(ctx context.Context, id string, etcdCli *clientv3.Client) (*InfoSyncer, error) { +func GlobalInfoSyncerInit(ctx context.Context, id string, etcdCli *clientv3.Client, skipRegisterToDashBoard bool) (*InfoSyncer, error) { is := &InfoSyncer{ etcdCli: etcdCli, info: getServerInfo(id), serverInfoPath: fmt.Sprintf("%s/%s", ServerInformationPath, id), minStartTSPath: fmt.Sprintf("%s/%s", ServerMinStartTSPath, id), } - err := is.init(ctx) + err := is.init(ctx, skipRegisterToDashBoard) if err != nil { return nil, err } @@ -144,11 +144,14 @@ func GlobalInfoSyncerInit(ctx context.Context, id string, etcdCli *clientv3.Clie } // Init creates a new etcd session and stores server info to etcd. -func (is *InfoSyncer) init(ctx context.Context) error { +func (is *InfoSyncer) init(ctx context.Context, skipRegisterToDashboard bool) error { err := is.newSessionAndStoreServerInfo(ctx, owner.NewSessionDefaultRetryCnt) if err != nil { return err } + if skipRegisterToDashboard { + return nil + } return is.newTopologySessionAndStoreServerInfo(ctx, owner.NewSessionDefaultRetryCnt) } diff --git a/domain/infosync/info_test.go b/domain/infosync/info_test.go index 278b8291d1d52..ad4d271a330e3 100644 --- a/domain/infosync/info_test.go +++ b/domain/infosync/info_test.go @@ -86,7 +86,7 @@ func TestTopology(t *testing.T) { failpoint.Enable("github.com/pingcap/tidb/domain/infosync/mockServerInfo", "return(true)") defer failpoint.Disable("github.com/pingcap/tidb/domain/infosync/mockServerInfo") - info, err := GlobalInfoSyncerInit(ctx, currentID, cli) + info, err := GlobalInfoSyncerInit(ctx, currentID, cli, false) if err != nil { t.Fatal(err) }