Skip to content

Commit

Permalink
playground: fix can not set runtime config in config file & set TiFla…
Browse files Browse the repository at this point in the history
…sh logger level to debug (#2346)
  • Loading branch information
Lloyd-Pottiger authored Jan 11, 2024
1 parent 0c6dda9 commit 77e0b53
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
64 changes: 46 additions & 18 deletions components/playground/instance/tiflash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions components/playground/instance/tiflash_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 77e0b53

Please sign in to comment.