diff --git a/components/playground/instance/tiflash.go b/components/playground/instance/tiflash.go index cb73f2d722..84175b3ab1 100644 --- a/components/playground/instance/tiflash.go +++ b/components/playground/instance/tiflash.go @@ -20,6 +20,7 @@ import ( "path/filepath" "strings" + "github.com/pingcap/errors" tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" @@ -131,26 +132,35 @@ func (inst *TiFlashInstance) Start(ctx context.Context, version utils.Version) e args := []string{ "server", - } - args = append(args, fmt.Sprintf("--config-file=%s", configPath), "--", - fmt.Sprintf("--tmp_path=%s", filepath.Join(inst.Dir, "tmp")), - fmt.Sprintf("--path=%s", filepath.Join(inst.Dir, "data")), - fmt.Sprintf("--listen_host=%s", inst.Host), - fmt.Sprintf("--logger.log=%s", inst.LogFile()), - fmt.Sprintf("--logger.errorlog=%s", filepath.Join(inst.Dir, "tiflash_error.log")), - fmt.Sprintf("--status.metrics_port=%d", inst.StatusPort), - fmt.Sprintf("--flash.service_addr=%s", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.ServicePort)), - fmt.Sprintf("--raft.pd_addr=%s", strings.Join(endpoints, ",")), - fmt.Sprintf("--flash.proxy.addr=%s", utils.JoinHostPort(inst.Host, inst.ProxyPort)), - fmt.Sprintf("--flash.proxy.advertise-addr=%s", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.ProxyPort)), - fmt.Sprintf("--flash.proxy.status-addr=%s", utils.JoinHostPort(inst.Host, inst.ProxyStatusPort)), - fmt.Sprintf("--flash.proxy.data-dir=%s", filepath.Join(inst.Dir, "proxy_data")), - fmt.Sprintf("--flash.proxy.log-file=%s", filepath.Join(inst.Dir, "tiflash_tikv.log")), - ) - - var err error + } + runtimeConfig := [][]string{ + {"path", filepath.Join(inst.Dir, "data")}, + {"listen_host", inst.Host}, + {"logger.log", inst.LogFile()}, + {"logger.errorlog", filepath.Join(inst.Dir, "tiflash_error.log")}, + {"status.metrics_port", fmt.Sprintf("%d", inst.StatusPort)}, + {"flash.service_addr", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.ServicePort)}, + {"raft.pd_addr", strings.Join(endpoints, ",")}, + {"flash.proxy.addr", utils.JoinHostPort(inst.Host, inst.ProxyPort)}, + {"flash.proxy.advertise-addr", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.ProxyPort)}, + {"flash.proxy.status-addr", utils.JoinHostPort(inst.Host, inst.ProxyStatusPort)}, + {"flash.proxy.data-dir", filepath.Join(inst.Dir, "proxy_data")}, + {"flash.proxy.log-file", filepath.Join(inst.Dir, "tiflash_tikv.log")}, + } + userConfig, err := unmarshalConfig(configPath) + if err != nil { + return errors.Trace(err) + } + fmt.Println("userConfig", userConfig) + for _, arg := range runtimeConfig { + // if user has set the config, skip it + if !isKeyPresentInMap(userConfig, arg[0]) { + args = append(args, fmt.Sprintf("--%s=%s", arg[0], arg[1])) + } + } + if inst.BinPath, err = tiupexec.PrepareBinary("tiflash", version, inst.BinPath); err != nil { return err } @@ -160,6 +170,24 @@ func (inst *TiFlashInstance) Start(ctx context.Context, version utils.Version) e return inst.Process.Start() } +func isKeyPresentInMap(m map[string]any, key string) bool { + keys := strings.Split(key, ".") + currentMap := m + + for i := 0; i < len(keys); i++ { + if _, ok := currentMap[keys[i]]; !ok { + return false + } + + // If the current value is a nested map, update the current map to the nested map + if innerMap, ok := currentMap[keys[i]].(map[string]any); ok { + currentMap = innerMap + } + } + + return true +} + // Component return the component name. func (inst *TiFlashInstance) Component() string { return "tiflash" diff --git a/components/playground/instance/tiflash_config.go b/components/playground/instance/tiflash_config.go index 077d65375b..15c8870653 100644 --- a/components/playground/instance/tiflash_config.go +++ b/components/playground/instance/tiflash_config.go @@ -28,6 +28,7 @@ func (inst *TiFlashInstance) getConfig() map[string]any { config := make(map[string]any) config["flash.proxy.config"] = filepath.Join(inst.Dir, "tiflash_proxy.toml") + config["logger.level"] = "debug" if inst.Role == TiFlashRoleDisaggWrite { config["storage.s3.endpoint"] = inst.DisaggOpts.S3Endpoint