github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/chaos/cases/config.go (about) 1 // Copyright 2020 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package main 15 16 import ( 17 "flag" 18 "time" 19 20 "github.com/pingcap/tiflow/dm/config/dbconfig" 21 ) 22 23 // config is used to run chaos tests. 24 type config struct { 25 *flag.FlagSet `toml:"-" yaml:"-" json:"-"` 26 27 ConfigDir string `toml:"config-dir" yaml:"config-dir" json:"config-dir"` 28 MasterAddr string `toml:"master-addr" yaml:"master-addr" json:"master-addr"` 29 Duration time.Duration `toml:"duration" yaml:"duration" json:"duration"` 30 31 MasterCount int `toml:"master-count" yaml:"master-count" json:"master-count"` 32 WorkerCount int `toml:"worker-count" yaml:"worker-count" json:"worker-count"` 33 34 Source1 dbconfig.DBConfig `toml:"source-1" yaml:"source-1" json:"source-1"` 35 Source2 dbconfig.DBConfig `toml:"source-2" yaml:"source-2" json:"source-2"` 36 Source3 dbconfig.DBConfig `toml:"source-3" yaml:"source-3" json:"source-3"` 37 Target dbconfig.DBConfig `toml:"target" yaml:"target" json:"target"` 38 } 39 40 // newConfig creates a config for this chaos testing suite. 41 func newConfig() *config { 42 cfg := &config{} 43 cfg.FlagSet = flag.NewFlagSet("chaos-case", flag.ContinueOnError) 44 fs := cfg.FlagSet 45 46 fs.StringVar(&cfg.ConfigDir, "config-dir", "/", "path of the source and task config files") 47 fs.StringVar(&cfg.MasterAddr, "master-addr", "dm-master:8261", "address of dm-master") 48 fs.DurationVar(&cfg.Duration, "duration", 20*time.Minute, "duration of cases running") 49 50 fs.IntVar(&cfg.MasterCount, "master-count", 3, "expect count of dm-master") 51 fs.IntVar(&cfg.WorkerCount, "worker-count", 3, "expect count of dm-worker") 52 53 fs.StringVar(&cfg.Source1.Host, "source1.host", "mysql57-0.sources", "host of the first upstream source") 54 fs.IntVar(&cfg.Source1.Port, "source1.port", 3306, "port of the first upstream source") 55 fs.StringVar(&cfg.Source1.User, "source1.user", "root", "user of the first upstream source") 56 fs.StringVar(&cfg.Source1.Password, "source1.password", "", "password of the first upstream source") 57 58 fs.StringVar(&cfg.Source2.Host, "source2.host", "mysql8-0.sources", "host of the second upstream source") 59 fs.IntVar(&cfg.Source2.Port, "source2.port", 3306, "port of the second upstream source") 60 fs.StringVar(&cfg.Source2.User, "source2.user", "root", "user of the second upstream source") 61 fs.StringVar(&cfg.Source2.Password, "source2.password", "", "password of the second upstream source") 62 63 fs.StringVar(&cfg.Source3.Host, "source3.host", "mariadb-0.sources", "host of the third upstream source") 64 fs.IntVar(&cfg.Source3.Port, "source3.port", 3306, "port of the third upstream source") 65 fs.StringVar(&cfg.Source3.User, "source3.user", "root", "user of the third upstream source") 66 fs.StringVar(&cfg.Source3.Password, "source3.password", "", "password of the third upstream source") 67 68 fs.StringVar(&cfg.Target.Host, "target.host", "tidb-0.tidb", "host of the downstream target") 69 fs.IntVar(&cfg.Target.Port, "target.port", 4000, "port of the downstream target") 70 fs.StringVar(&cfg.Target.User, "target.user", "root", "user of the downstream target") 71 fs.StringVar(&cfg.Target.Password, "target.password", "", "password of the downstream target") 72 73 return cfg 74 } 75 76 // parse parses flag definitions from the argument list. 77 func (c *config) parse(args []string) error { 78 if err := c.FlagSet.Parse(args); err != nil { 79 return err 80 } 81 82 c.adjust() 83 return nil 84 } 85 86 func (c *config) adjust() { 87 // `go-sqlsmith` may generate ZERO time data, so we simply clear `sql_mode` now. 88 // mysql:5.7 `explicit_defaults_for_timestamp`: OFF 89 // tidb `explicit_defaults_for_timestamp`: ON 90 // `ALTER TABLE .* ADD COLUMN (.* TIMESTAMP)` will have different default value 91 c.Source1.Session = map[string]string{"sql_mode": "", "explicit_defaults_for_timestamp": "on"} 92 c.Source2.Session = map[string]string{"sql_mode": "", "explicit_defaults_for_timestamp": "on"} 93 c.Source3.Session = map[string]string{"sql_mode": ""} // explicit_defaults_for_timestamp enabled when deploy it 94 95 c.Source1.Adjust() 96 c.Source2.Adjust() 97 c.Source3.Adjust() 98 c.Target.Adjust() 99 }