Skip to content

Support specify configuration file of TiDB/TiKV/PD when starting playground#80

Merged
lonng merged 8 commits into
pingcap:masterfrom
chenlx0:master
Mar 29, 2020
Merged

Support specify configuration file of TiDB/TiKV/PD when starting playground#80
lonng merged 8 commits into
pingcap:masterfrom
chenlx0:master

Conversation

@chenlx0
Copy link
Copy Markdown
Contributor

@chenlx0 chenlx0 commented Mar 24, 2020

UCP #64

What problem does this PR solve?

Support specify configuration file of TiDB/TiKV/PD when starting playground. for #64

What is changed and how it works?

Add flags db.config pd.config kv.config for playground, and pass their values to TiKV/TiDB/pd command as configuration file path when starting playground. If these flags are not specified, use default config.

Check List

Tests

  • No code

@sre-bot
Copy link
Copy Markdown
Contributor

sre-bot commented Mar 24, 2020

Thanks for your contribution. If your PR get merged, you will be rewarded 100 points.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Mar 25, 2020

Codecov Report

Merging #80 into master will increase coverage by 3.48%.
The diff coverage is 18.80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #80      +/-   ##
==========================================
+ Coverage   29.33%   32.81%   +3.48%     
==========================================
  Files          17       18       +1     
  Lines         958      902      -56     
==========================================
+ Hits          281      296      +15     
+ Misses        625      557      -68     
+ Partials       52       49       -3     
Impacted Files Coverage Δ
cmd/help.go 6.12% <0.00%> (-4.05%) ⬇️
cmd/run.go 0.00% <0.00%> (ø)
cmd/uninstall.go 38.18% <0.00%> (-7.48%) ⬇️
pkg/repository/component.go 0.00% <ø> (ø)
pkg/repository/mirror.go 8.19% <ø> (ø)
pkg/repository/version.go 78.26% <ø> (ø)
cmd/status.go 11.90% <20.00%> (ø)
cmd/update.go 32.35% <20.00%> (+1.76%) ⬆️
pkg/repository/repository.go 37.11% <30.76%> (ø)
cmd/clean.go 18.91% <33.33%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a74e523...2922ccd. Read the comment docs.

@chenlx0
Copy link
Copy Markdown
Contributor Author

chenlx0 commented Mar 25, 2020

PTAL @lonng

Comment thread components/playground/main.go Outdated
$ tiup playground nightly # Start a TiDB nightly version local cluster
$ tiup playground v3.0.10 --db 3 --pd 3 --kv 3 # Start a local cluster with 10 nodes
$ tiup playground nightly --monitor # Start a local cluster with monitor system
$ tiup playground --pd.config ./pd.toml --db.config ./db.toml --kv.config ./kv.toml # Start a local cluster with specified configuration file`,
Copy link
Copy Markdown
Contributor

@lonng lonng Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to pass all config flags in examples. e.g

tiup playground --pd.config ./pd.tom

And the playground component has a different work directory with the tiup. So I think the example won't work properly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

fmt.Sprintf("--advertise-client-urls=http://%s:%d", inst.Host, inst.StatusPort),
fmt.Sprintf("--log-file=%s", filepath.Join(inst.Dir, "pd.log")),
}
if inst.ConfigPath != "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove other flags even if we specify a configuration file. We should keep the original flags and append --config if the config flag exists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Fixed.

fmt.Sprintf("--path=%s", strings.Join(endpoints, ",")),
fmt.Sprintf("--log-file=%s", filepath.Join(inst.Dir, "tidb.log")),
}
if inst.ConfigPath != "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread components/playground/main.go Outdated
version = args[0]
}
return bootCluster(version, pdNum, tidbNum, tikvNum, host, monitor)
return bootCluster(version, pdConfigPath, dbConfigPath, kvConfigPath, pdNum, tidbNum, tikvNum, host, monitor)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature of function bootCluster too complex to hard to maintain, you can define a struct, eg.

type bootOptions {
    version...
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, bootOptions added.

Comment thread components/playground/main.go Outdated
}

func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monitor bool) error {
func bootCluster(version, pdConfigPath, dbConfigPath, kvConfigPath string, pdNum, tidbNum, tikvNum int, host string, monitor bool) error {
Copy link
Copy Markdown
Contributor

@lonng lonng Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make further handling for the pdConfigPath/dbConfigPath/kvConfigPath and convert it to an absolute path.
According to https://github.com/pingcap-incubator/tiup/blob/e08d28e360c6aee5044a9308c74eb994281be4e4/cmd/run.go#L198. Them will be related to the playground work directory, which is not same as the working directory of the user running tiup playground.

We can achieve our intention via the following code snippet.

if !strings.HasPrefix(pdConfigPath, "/") && !strings.HasPrefix(pdConfigPath, "~") {
    pdConfigPath = filepath.Join(os.Getenv(localdata.EnvNameWorkDir), pdConfigPath)
}

Copy link
Copy Markdown
Contributor Author

@chenlx0 chenlx0 Mar 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fredchenbj define a method getAbsolutePath in #82 , i think i can reuse that method here. But redefine that method in my pr seems redundant and could cause conflicts. Maybe it is better to fix this problem after #82 merged so that i can use getAbsolutePath here. Is that OK?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, merge #82 first.

@chenlx0
Copy link
Copy Markdown
Contributor Author

chenlx0 commented Mar 29, 2020

All fixed, @lonng PTAL

Copy link
Copy Markdown
Contributor

@lonng lonng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lonng lonng merged commit f19d61d into pingcap:master Mar 29, 2020
@sre-bot
Copy link
Copy Markdown
Contributor

sre-bot commented Mar 29, 2020

Team blueshit complete task #64 and get 100 score, currerent score 450

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants