Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Mar 12, 2024
2 parents 3cb74e7 + 9e11d0e commit b9c705d
Show file tree
Hide file tree
Showing 56 changed files with 558 additions and 217 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
TiUP Changelog

## [1.14.1] 2024-01-12

### Fixes

- Fix tiproxy will restart even if version is the same in `tiup-cluster` (#2358, @xhebox)
- Fix that empty label is not allowed in Prometheus in `tiup-cluster` (#2349, @borissavelev)
- Fix can not set runtime config in config file & set TiFlash logger level to debug in `tiup-playground` (#2346, @Lloyd-Pottiger)
- Fix TLS configs for tiproxy in `tiup-cluster` (#2356, @xhebox)
- Fix cannot clone without global version in `tiup` (#2359, @nexustar)
- Fix tiproxy config and version in `tiup-cluster` (#2354, @xhebox)
- TiProxy needs to override usercfg in `tiup-playground` (#2342, @xhebox)
- Fix the start script for alertmanager when enabling numa in `tiup-cluster` and `tiup-dm` (#2337, @KanShiori)
- Fix metric targets will be overrided in `tiup-playground` (#2324, @xhebox)

### Improvements

- Change typo waitting to waiting in output messages for pdapi.go in `tiup-cluster` (#2330, @guangleibao)
- Add check for rocky linux in `tiup-cluster` (#2333, @dveeden)
- Fallback to default version when componen specific version is empty in `tiup-playground` (#2344, @xhebox)

## [1.14.0] 2023-11-17

### New Features
Expand Down
2 changes: 2 additions & 0 deletions components/cluster/command/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type TemplateOptions struct {
type LocalTemplate struct {
GlobalUser string // global.user in yaml template
GlobalGroup string // global.group in yaml template
GlobalSystemdMode string // global.systemd_mode in yaml template
GlobalSSHPort int // global.ssh_port in yaml template
GlobalDeployDir string // global.deploy_dir in yaml template
GlobalDataDir string // global.data_dir in yaml template
Expand Down Expand Up @@ -122,6 +123,7 @@ func newTemplateCmd() *cobra.Command {
// template values for rendering
cmd.Flags().StringVar(&localOpt.GlobalUser, "user", "tidb", "The user who runs the tidb cluster.")
cmd.Flags().StringVar(&localOpt.GlobalGroup, "group", "", "group is used to specify the group name the user belong to if it's not the same as user.")
cmd.Flags().StringVar(&localOpt.GlobalSystemdMode, "systemd_mode", "system", "systemd_mode is used to select whether to use sudo permissions.")
cmd.Flags().IntVar(&localOpt.GlobalSSHPort, "ssh-port", 22, "SSH port of servers in the managed cluster.")
cmd.Flags().StringVar(&localOpt.GlobalDeployDir, "deploy-dir", "/tidb-deploy", "Storage directory for cluster deployment files, startup scripts, and configuration files.")
cmd.Flags().StringVar(&localOpt.GlobalDataDir, "data-dir", "/tidb-data", "TiDB Cluster data storage directory.")
Expand Down
2 changes: 2 additions & 0 deletions components/dm/command/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type TemplateOptions struct {
type LocalTemplate struct {
GlobalUser string // global.user in yaml template
GlobalGroup string // global.group in yaml template
GlobalSystemdMode string // global.systemd_mode in yaml template
GlobalSSHPort int // global.ssh_port in yaml template
GlobalDeployDir string // global.deploy_dir in yaml template
GlobalDataDir string // global.data_dir in yaml template
Expand Down Expand Up @@ -113,6 +114,7 @@ func newTemplateCmd() *cobra.Command {
// template values for rendering
cmd.Flags().StringVar(&localOpt.GlobalUser, "user", "tidb", "The user who runs the tidb cluster.")
cmd.Flags().StringVar(&localOpt.GlobalGroup, "group", "", "group is used to specify the group name the user belong to if it's not the same as user.")
cmd.Flags().StringVar(&localOpt.GlobalSystemdMode, "systemd_mode", "system", "systemd_mode is used to select whether to use sudo permissions.")
cmd.Flags().IntVar(&localOpt.GlobalSSHPort, "ssh-port", 22, "SSH port of servers in the managed cluster.")
cmd.Flags().StringVar(&localOpt.GlobalDeployDir, "deploy-dir", "/tidb-deploy", "Storage directory for cluster deployment files, startup scripts, and configuration files.")
cmd.Flags().StringVar(&localOpt.GlobalDataDir, "data-dir", "/tidb-data", "TiDB Cluster data storage directory.")
Expand Down
67 changes: 48 additions & 19 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"
"github.com/pingcap/tiup/pkg/tidbver"
"github.com/pingcap/tiup/pkg/utils"
)
Expand Down Expand Up @@ -103,9 +104,9 @@ func (inst *TiFlashInstance) StatusAddrs() (addrs []string) {
}

// Start calls set inst.cmd and Start
func (inst *TiFlashInstance) Start(ctx context.Context) error {
if !tidbver.TiFlashPlaygroundNewStartMode(inst.Version.String()) {
return inst.startOld(ctx, inst.Version)
func (inst *TiFlashInstance) Start(ctx context.Context, version utils.Version) error {
if !tidbver.TiFlashPlaygroundNewStartMode(version.String()) {
return inst.startOld(ctx, version)
}

proxyConfigPath := filepath.Join(inst.Dir, "tiflash_proxy.toml")
Expand All @@ -130,31 +131,59 @@ func (inst *TiFlashInstance) Start(ctx context.Context) error {

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")),
)
}
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]))
}
}

inst.Process = &process{cmd: PrepareCommand(ctx, inst.BinPath, args, nil, inst.Dir)}

logIfErr(inst.Process.SetOutputFile(inst.LogFile()))
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
6 changes: 5 additions & 1 deletion components/playground/instance/tiproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c *TiProxy) MetricAddr() (r MetricAddr) {

// Start implements Instance interface.
func (c *TiProxy) Start(ctx context.Context) error {
endpoints := pdEndpoints(c.pds, true)
endpoints := pdEndpoints(c.pds, false)

configPath := filepath.Join(c.Dir, "config", "proxy.toml")
dir := filepath.Dir(configPath)
Expand Down Expand Up @@ -101,6 +101,10 @@ func (c *TiProxy) Start(ctx context.Context) error {
fmt.Sprintf("--config=%s", configPath),
}

if c.BinPath, err = tiupexec.PrepareBinary("tiproxy", version, c.BinPath); err != nil {

Check failure on line 104 in components/playground/instance/tiproxy.go

View workflow job for this annotation

GitHub Actions / reprotest (1.21.x)

undefined: tiupexec

Check failure on line 104 in components/playground/instance/tiproxy.go

View workflow job for this annotation

GitHub Actions / reprotest (1.21.x)

undefined: version
return err
}

c.Process = &process{cmd: PrepareCommand(ctx, c.BinPath, args, nil, c.Dir)}

logIfErr(c.Process.SetOutputFile(c.LogFile()))
Expand Down
12 changes: 11 additions & 1 deletion components/playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ func (p *Playground) handleScaleIn(w io.Writer, pid int) error {
p.ticdcs = append(p.ticdcs[:i], p.ticdcs[i+1:]...)
}
}
case spec.ComponentTiProxy:
for i := 0; i < len(p.tiproxys); i++ {
if p.tiproxys[i].Pid() == pid {
p.tiproxys = append(p.tiproxys[:i], p.tiproxys[i+1:]...)
}
}
case spec.ComponentTiKVCDC:
for i := 0; i < len(p.tikvCdcs); i++ {
if p.tikvCdcs[i].Pid() == pid {
Expand Down Expand Up @@ -428,6 +434,8 @@ func (p *Playground) sanitizeComponentConfig(cid string, cfg *instance.Config) e
return p.sanitizeConfig(p.bootOptions.Pump, cfg)
case spec.ComponentDrainer:
return p.sanitizeConfig(p.bootOptions.Drainer, cfg)
case spec.ComponentTiProxy:
return p.sanitizeConfig(p.bootOptions.TiProxy, cfg)
default:
return fmt.Errorf("unknown %s in sanitizeConfig", cid)
}
Expand Down Expand Up @@ -895,7 +903,9 @@ func (p *Playground) bindVersion(comp string, version string) (bindVersion strin
default:
}
if bindVersion == "" {
bindVersion = version
if version == "nightly" {
bindVersion = version
}
}
return
}
Expand Down
6 changes: 5 additions & 1 deletion embed/examples/cluster/local.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ global:
# group is used to specify the group name the user belong to if it's not the same as user.
group: "{{ .GlobalGroup }}"
{{- end }}
{{- if .GlobalSystemdMode }}
# # systemd_mode is used to select whether to use sudo permissions.
systemd_mode: "{{ .GlobalSystemdMode }}"
{{- end }}
# # SSH port of servers in the managed cluster.
ssh_port: {{ .GlobalSSHPort }}
# # Storage directory for cluster deployment files, startup scripts, and configuration files.
Expand Down Expand Up @@ -62,4 +66,4 @@ alertmanager_servers:
{{- range .AlertManagerServers }}
- host: {{ . }}
{{- end }}
{{ end }}
{{ end }}
2 changes: 2 additions & 0 deletions embed/examples/cluster/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ global:
user: "tidb"
# # group is used to specify the group name the user belong to if it's not the same as user.
# group: "tidb"
# # systemd_mode is used to select whether to use sudo permissions. When its value is set to user, there is no need to add global.user to sudoers. The default value is system.
# systemd_mode: "system"
# # SSH port of servers in the managed cluster.
ssh_port: 22
# # Storage directory for cluster deployment files, startup scripts, and configuration files.
Expand Down
2 changes: 2 additions & 0 deletions embed/examples/cluster/multi-dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ global:
# # group is used to specify the group name the user belong to,if it's not the same as user.
# group: "tidb"
# # SSH port of servers in the managed cluster.
# # systemd_mode is used to select whether to use sudo permissions. When its value is set to user, there is no need to add global.user to sudoers. The default value is system.
# systemd_mode: "system"
ssh_port: 22
# # Storage directory for cluster deployment files, startup scripts, and configuration files.
deploy_dir: "/tidb-deploy"
Expand Down
2 changes: 2 additions & 0 deletions embed/examples/cluster/topology.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ global:
# # group is used to specify the group name the user belong to,if it's not the same as user.
# group: "tidb"
# # SSH port of servers in the managed cluster.
# # systemd_mode is used to select whether to use sudo permissions. When its value is set to user, there is no need to add global.user to sudoers. The default value is system.
# systemd_mode: "system"
ssh_port: 22
# # Storage directory for cluster deployment files, startup scripts, and configuration files.
deploy_dir: "/tidb-deploy"
Expand Down
6 changes: 5 additions & 1 deletion embed/examples/dm/local.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ global:
# group is used to specify the group name the user belong to if it's not the same as user.
group: "{{ .GlobalGroup }}"
{{- end }}
{{- if .GlobalSystemdMode }}
# # systemd_mode is used to select whether to use sudo permissions.
systemd_mode: "{{ .GlobalSystemdMode }}"
{{- end }}
# # SSH port of servers in the managed cluster.
ssh_port: {{ .GlobalSSHPort }}
# # Storage directory for cluster deployment files, startup scripts, and configuration files.
Expand Down Expand Up @@ -51,4 +55,4 @@ alertmanager_servers:
{{- range .AlertManagerServers }}
- host: {{ . }}
{{- end }}
{{ end }}
{{ end }}
1 change: 1 addition & 0 deletions embed/examples/dm/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
---
global:
user: "tidb"
# systemd_mode: "system"
ssh_port: 22
deploy_dir: "/home/tidb/dm/deploy"
data_dir: "/home/tidb/dm/data"
Expand Down
1 change: 1 addition & 0 deletions embed/examples/dm/topology.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# them if the specific deployment value missing.
global:
user: "tidb"
# systemd_mode: "system"
ssh_port: 22
deploy_dir: "/dm-deploy"
data_dir: "/dm-data"
Expand Down
2 changes: 2 additions & 0 deletions embed/templates/config/prometheus.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@ scrape_configs:
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
{{- if .BlackboxAddr}}
- target_label: __address__
replacement: '{{.BlackboxAddr}}'
{{- end}}
{{- range $addr := .BlackboxExporterAddrs}}
- job_name: "blackbox_exporter_{{$addr}}_icmp"
scrape_interval: 6s
Expand Down
4 changes: 3 additions & 1 deletion embed/templates/systemd/system.service.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ LimitCORE={{.LimitCORE}}
LimitNOFILE=1000000
LimitSTACK=10485760

{{- if .GrantCapNetRaw}}
{{- if and .GrantCapNetRaw (eq .SystemdMode "system")}}
AmbientCapabilities=CAP_NET_RAW
{{- end}}
{{- if eq .SystemdMode "system"}}
User={{.User}}
{{- end}}
ExecStart=/bin/bash -c '{{.DeployDir}}/scripts/run_{{.ServiceName}}.sh'
{{- if eq .ServiceName "prometheus"}}
ExecReload=/bin/bash -c 'kill -HUP $MAINPID $(pidof {{.DeployDir}}/bin/ng-monitoring-server)'
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/ctxt/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const (

type (
// Executor is the executor interface for TiUP, all tasks will in the end
// be passed to a executor and then be actually performed.
// be passed to an executor and then be actually performed.
Executor interface {
// Execute run the command, then return it's stdout and stderr
// Execute run the command, then return its stdout and stderr
// NOTE: stdin is not supported as it seems we don't need it (for now). If
// at some point in the future we need to pass stdin to a command, we'll
// need to refactor this function and its implementations.
Expand Down
5 changes: 3 additions & 2 deletions pkg/cluster/executor/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func (e *EasySSHExecutor) Execute(ctx context.Context, cmd string, sudo bool, ti
}

// set a basic PATH in case it's empty on login
cmd = fmt.Sprintf("PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin %s", cmd)

cmd = fmt.Sprintf("PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin; %s", cmd)
if e.Locale != "" {
cmd = fmt.Sprintf("export LANG=%s; %s", e.Locale, cmd)
}
Expand Down Expand Up @@ -182,6 +182,7 @@ func (e *EasySSHExecutor) Execute(ctx context.Context, cmd string, sudo bool, ti
e.Config.Server,
color.YellowString(output)))
}

return []byte(stdout), []byte(stderr), baseErr
}

Expand Down
Loading

0 comments on commit b9c705d

Please sign in to comment.