Skip to content

Commit

Permalink
Merge branch 'master' into prune_pd_info
Browse files Browse the repository at this point in the history
  • Loading branch information
srstack authored Nov 19, 2022
2 parents 967c4ce + 63d509b commit 786e033
Show file tree
Hide file tree
Showing 48 changed files with 593 additions and 1,283 deletions.
5 changes: 3 additions & 2 deletions components/playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,9 @@ func (p *Playground) bootCluster(ctx context.Context, env *environment.Environme

p.bootOptions = options

if options.PD.Num < 1 || options.TiKV.Num < 1 {
return fmt.Errorf("all components count must be great than 0 (tikv=%v, pd=%v)", options.TiKV.Num, options.PD.Num)
// All others components depend on the pd, we just ensure the pd count must be great than 0
if options.PD.Num < 1 {
return fmt.Errorf("all components count must be great than 0 (pd=%v)", options.PD.Num)
}

if !utils.Version(options.Version).IsNightly() {
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 @@ -330,6 +330,8 @@ monitoring_servers:
# log_dir: "/tidb-deploy/prometheus-8249/log"
# prometheus rule dir on TiUP machine
# rule_dir: /home/tidb/prometheus_rule
# scrape_interval: 15s
# scrape_timeout: 10s
# # Server configs are used to specify the configuration of Grafana Servers.
grafana_servers:
# # The ip address of the Grafana Server.
Expand Down
10 changes: 8 additions & 2 deletions embed/templates/config/prometheus.yml.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
---
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
{{- if .ScrapeInterval}}
scrape_interval: {{.ScrapeInterval}}
{{- else}}
scrape_interval: 15s # By default, scrape targets every 15 seconds.
{{- end}}
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout is set to the global default (10s).
{{- if .ScrapeTimeout}}
scrape_timeout: {{.ScrapeTimeout}}
{{- end}}
external_labels:
cluster: '{{.ClusterName}}'
monitor: "prometheus"
Expand Down
12 changes: 6 additions & 6 deletions embed/templates/scripts/run_alertmanager.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ exec bin/alertmanager/alertmanager \
--storage.path="{{.DataDir}}" \
--data.retention=120h \
--log.level="info" \
--web.listen-address="{{.ListenHost}}:{{.WebPort}}" \
--web.external-url="http://{{.IP}}:{{.WebPort}}" \
{{- if .EndPoints}}
{{- range $idx, $am := .EndPoints}}
--cluster.peer="{{$am.IP}}:{{$am.ClusterPort}}" \
--web.listen-address="{{.WebListenAddr}}" \
--web.external-url="{{.WebExternalURL}}" \
{{- if .ClusterPeers}}
{{- range $idx, $am := .ClusterPeers}}
--cluster.peer="{{$am}}" \
{{- end}}
{{- end}}
--cluster.listen-address="{{.ListenHost}}:{{.ClusterPort}}"
--cluster.listen-address="{{.ClusterListenAddr}}"
16 changes: 3 additions & 13 deletions embed/templates/scripts/run_cdc.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@ set -e
DEPLOY_DIR={{.DeployDir}}
cd "${DEPLOY_DIR}" || exit 1

{{- define "PDList"}}
{{- range $idx, $pd := .}}
{{- if eq $idx 0}}
{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- else -}}
,{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- end}}
{{- end}}
{{- end}}

{{- if .NumaNode}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} bin/cdc server \
{{- else}}
exec bin/cdc server \
{{- end}}
--addr "0.0.0.0:{{.Port}}" \
--advertise-addr "{{.IP}}:{{.Port}}" \
--pd "{{template "PDList" .Endpoints}}" \
--addr "{{.Addr}}" \
--advertise-addr "{{.AdvertiseAddr}}" \
--pd "{{.PD}}" \
{{- if .DataDir}}
{{- if .DataDirEnabled}}
--data-dir="{{.DataDir}}" \
Expand Down
14 changes: 2 additions & 12 deletions embed/templates/scripts/run_drainer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ DEPLOY_DIR={{.DeployDir}}

cd "${DEPLOY_DIR}" || exit 1

{{- define "PDList"}}
{{- range $idx, $pd := .}}
{{- if eq $idx 0}}
{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- else -}}
,{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- end}}
{{- end}}
{{- end}}

{{- if .NumaNode}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} bin/drainer \
{{- else}}
Expand All @@ -25,8 +15,8 @@ exec bin/drainer \
{{- if .NodeID}}
--node-id="{{.NodeID}}" \
{{- end}}
--addr="{{.IP}}:{{.Port}}" \
--pd-urls="{{template "PDList" .Endpoints}}" \
--addr="{{.Addr}}" \
--pd-urls="{{.PD}}" \
--data-dir="{{.DataDir}}" \
--log-file="{{.LogDir}}/drainer.log" \
--config=conf/drainer.toml 2>> "{{.LogDir}}/drainer_stderr.log"
4 changes: 0 additions & 4 deletions embed/templates/scripts/run_grafana.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ DEPLOY_DIR={{.DeployDir}}
cd "${DEPLOY_DIR}" || exit 1

LANG=en_US.UTF-8 \
{{- if .NumaNode}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} bin/bin/grafana-server \
{{- else}}
exec bin/bin/grafana-server \
{{- end}}
--homepath="{{.DeployDir}}/bin" \
--config="{{.DeployDir}}/conf/grafana.ini"
20 changes: 5 additions & 15 deletions embed/templates/scripts/run_pd.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,17 @@ DEPLOY_DIR={{.DeployDir}}

cd "${DEPLOY_DIR}" || exit 1

{{- define "PDList"}}
{{- range $idx, $pd := .}}
{{- if eq $idx 0}}
{{- $pd.Name}}={{$pd.AdvertisePeerAddr}}
{{- else -}}
,{{- $pd.Name}}={{$pd.AdvertisePeerAddr}}
{{- end}}
{{- end}}
{{- end}}

{{- if .NumaNode}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} env GODEBUG=madvdontneed=1 bin/pd-server \
{{- else}}
exec env GODEBUG=madvdontneed=1 bin/pd-server \
{{- end}}
--name="{{.Name}}" \
--client-urls="{{.Scheme}}://{{.ListenHost}}:{{.ClientPort}}" \
--advertise-client-urls="{{.AdvertiseClientAddr}}" \
--peer-urls="{{.Scheme}}://{{.ListenHost}}:{{.PeerPort}}" \
--advertise-peer-urls="{{.AdvertisePeerAddr}}" \
--client-urls="{{.ClientURL}}" \
--advertise-client-urls="{{.AdvertiseClientURL}}" \
--peer-urls="{{.PeerURL}}" \
--advertise-peer-urls="{{.AdvertisePeerURL}}" \
--data-dir="{{.DataDir}}" \
--initial-cluster="{{template "PDList" .Endpoints}}" \
--initial-cluster="{{.InitialCluster}}" \
--config=conf/pd.toml \
--log-file="{{.LogDir}}/pd.log" 2>> "{{.LogDir}}/pd_stderr.log"
20 changes: 5 additions & 15 deletions embed/templates/scripts/run_pd_scale.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,18 @@ DEPLOY_DIR={{.DeployDir}}

cd "${DEPLOY_DIR}" || exit 1

{{- define "PDList"}}
{{- range $idx, $pd := .}}
{{- if eq $idx 0}}
{{- $pd.AdvertiseClientAddr}}
{{- else -}}
,{{- $pd.AdvertiseClientAddr}}
{{- end}}
{{- end}}
{{- end}}

{{- if .NumaNode}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} env GODEBUG=madvdontneed=1 bin/pd-server \
{{- else}}
exec env GODEBUG=madvdontneed=1 bin/pd-server \
{{- end}}
--name="{{.Name}}" \
--client-urls="{{.Scheme}}://{{.ListenHost}}:{{.ClientPort}}" \
--advertise-client-urls="{{.AdvertiseClientAddr}}" \
--peer-urls="{{.Scheme}}://{{.ListenHost}}:{{.PeerPort}}" \
--advertise-peer-urls="{{.AdvertisePeerAddr}}" \
--client-urls="{{.ClientURL}}" \
--advertise-client-urls="{{.AdvertiseClientURL}}" \
--peer-urls="{{.PeerURL}}" \
--advertise-peer-urls="{{.AdvertisePeerURL}}" \
--data-dir="{{.DataDir}}" \
--join="{{template "PDList" .Endpoints}}" \
--join="{{.Join}}" \
--config=conf/pd.toml \
--log-file="{{.LogDir}}/pd.log" 2>> "{{.LogDir}}/pd_stderr.log"

2 changes: 1 addition & 1 deletion embed/templates/scripts/run_prometheus.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exec bin/prometheus/prometheus \
{{- end}}
--config.file="{{.DeployDir}}/conf/prometheus.yml" \
--web.listen-address=":{{.Port}}" \
--web.external-url="http://{{.IP}}:{{.Port}}/" \
--web.external-url="{{.WebExternalURL}}/" \
--web.enable-admin-api \
--log.level="info" \
--storage.tsdb.path="{{.DataDir}}" \
Expand Down
16 changes: 3 additions & 13 deletions embed/templates/scripts/run_pump.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ DEPLOY_DIR={{.DeployDir}}

cd "${DEPLOY_DIR}" || exit 1

{{- define "PDList"}}
{{- range $idx, $pd := .}}
{{- if eq $idx 0}}
{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- else -}}
,{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- end}}
{{- end}}
{{- end}}

{{- if .NumaNode}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} bin/pump \
{{- else}}
Expand All @@ -25,9 +15,9 @@ exec bin/pump \
{{- if .NodeID}}
--node-id="{{.NodeID}}" \
{{- end}}
--addr="0.0.0.0:{{.Port}}" \
--advertise-addr="{{.Host}}:{{.Port}}" \
--pd-urls="{{template "PDList" .Endpoints}}" \
--addr="{{.Addr}}" \
--advertise-addr="{{.AdvertiseAddr}}" \
--pd-urls="{{.PD}}" \
--data-dir="{{.DataDir}}" \
--log-file="{{.LogDir}}/pump.log" \
--config=conf/pump.toml 2>> "{{.LogDir}}/pump_stderr.log"
12 changes: 1 addition & 11 deletions embed/templates/scripts/run_tidb-dashboard.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ DEPLOY_DIR={{.DeployDir}}

cd "${DEPLOY_DIR}" || exit 1

{{- define "PDList"}}
{{- range $idx, $pd := .}}
{{- if eq $idx 0}}
{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- else -}}
,{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- end}}
{{- end}}
{{- end}}

{{- if .NumaNode}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} bin/tidb-dashboard \
{{- else}}
Expand All @@ -25,7 +15,7 @@ exec bin/tidb-dashboard \
--feature-version="{{.TidbVersion}}" \
--host="{{.IP}}" \
--port="{{.Port}}" \
--pd="{{template "PDList" .Endpoints}}" \
--pd="{{.PD}}" \
--data-dir="{{.DataDir}}" \
{{- if .TLSEnabled}}
--tidb-ca tls/ca.crt \
Expand Down
12 changes: 1 addition & 11 deletions embed/templates/scripts/run_tidb.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ DEPLOY_DIR={{.DeployDir}}

cd "${DEPLOY_DIR}" || exit 1

{{- define "PDList"}}
{{- range $idx, $pd := .}}
{{- if eq $idx 0}}
{{- $pd.IP}}:{{$pd.ClientPort}}
{{- else -}}
,{{$pd.IP}}:{{$pd.ClientPort}}
{{- end}}
{{- end}}
{{- end}}

{{- if and .NumaNode .NumaCores}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} -C {{.NumaCores}} env GODEBUG=madvdontneed=1 bin/tidb-server \
{{- else if .NumaNode}}
Expand All @@ -32,7 +22,7 @@ exec env GODEBUG=madvdontneed=1 bin/tidb-server \
{{- if .SupportSecboot}}
--initialize-insecure \
{{- end}}
--path="{{template "PDList" .Endpoints}}" \
--path="{{.PD}}" \
--log-slow-query="{{.LogDir}}/tidb_slow_query.log" \
--config=conf/tidb.toml \
--log-file="{{.LogDir}}/tidb.log" 2>> "{{.LogDir}}/tidb_stderr.log"
16 changes: 3 additions & 13 deletions embed/templates/scripts/run_tikv-cdc.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@ set -e
DEPLOY_DIR={{.DeployDir}}
cd "${DEPLOY_DIR}" || exit 1

{{- define "PDList"}}
{{- range $idx, $pd := .}}
{{- if eq $idx 0}}
{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- else -}}
,{{- $pd.Scheme}}://{{$pd.IP}}:{{$pd.ClientPort}}
{{- end}}
{{- end}}
{{- end}}

{{- if .NumaNode}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} bin/tikv-cdc server \
{{- else}}
exec bin/tikv-cdc server \
{{- end}}
--addr "0.0.0.0:{{.Port}}" \
--advertise-addr "{{.IP}}:{{.Port}}" \
--pd "{{template "PDList" .Endpoints}}" \
--addr "{{.Addr}}" \
--advertise-addr "{{.AdvertiseAddr}}" \
--pd "{{.PD}}" \
{{- if .DataDir}}
--data-dir="{{.DataDir}}" \
{{- end}}
Expand Down
16 changes: 3 additions & 13 deletions embed/templates/scripts/run_tikv.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ stat=$(time sync || sync)
echo ok
echo $stat

{{- define "PDList"}}
{{- range $idx, $pd := .}}
{{- if eq $idx 0}}
{{- $pd.IP}}:{{$pd.ClientPort}}
{{- else -}}
,{{$pd.IP}}:{{$pd.ClientPort}}
{{- end}}
{{- end}}
{{- end}}

export MALLOC_CONF="prof:true,prof_active:false"

{{- if and .NumaNode .NumaCores}}
Expand All @@ -29,13 +19,13 @@ exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} bin/tikv-server
{{- else}}
exec bin/tikv-server \
{{- end}}
--addr "{{.ListenHost}}:{{.Port}}" \
--addr "{{.Addr}}" \
--advertise-addr "{{.AdvertiseAddr}}" \
--status-addr "{{.ListenHost}}:{{.StatusPort}}" \
--status-addr "{{.StatusAddr}}" \
{{- if .SupportAdvertiseStatusAddr}}
--advertise-status-addr "{{.AdvertiseStatusAddr}}" \
{{- end}}
--pd "{{template "PDList" .Endpoints}}" \
--pd "{{.PD}}" \
--data-dir "{{.DataDir}}" \
--config conf/tikv.toml \
--log-file "{{.LogDir}}/tikv.log" 2>> "{{.LogDir}}/tikv_stderr.log"
25 changes: 19 additions & 6 deletions pkg/cluster/spec/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tiup/pkg/cluster/template/config"
"github.com/pingcap/tiup/pkg/cluster/template/scripts"
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/utils"
)

// AlertmanagerSpec represents the AlertManager topology specification in topology.yaml
Expand Down Expand Up @@ -97,6 +98,7 @@ func (c *AlertManagerComponent) Instances() []Instance {
InstanceSpec: s,
Name: c.Name(),
Host: s.Host,
ListenHost: s.ListenHost,
Port: s.WebPort,
SSHP: s.SSHPort,

Expand Down Expand Up @@ -141,14 +143,25 @@ func (i *AlertManagerInstance) InitConfig(
return err
}

alertmanagers := i.topo.BaseTopo().Alertmanagers

enableTLS := gOpts.TLSEnabled
// Transfer start script
spec := i.InstanceSpec.(*AlertmanagerSpec)
cfg := scripts.NewAlertManagerScript(spec.Host, spec.ListenHost, paths.Deploy, paths.Data[0], paths.Log, enableTLS).
WithWebPort(spec.WebPort).WithClusterPort(spec.ClusterPort).WithNumaNode(spec.NumaNode).
AppendEndpoints(AlertManagerEndpoints(alertmanagers, deployUser, enableTLS))

peers := []string{}
for _, amspec := range i.topo.BaseTopo().Alertmanagers {
peers = append(peers, utils.JoinHostPort(amspec.Host, amspec.ClusterPort))
}
cfg := &scripts.AlertManagerScript{
WebListenAddr: utils.JoinHostPort(i.GetListenHost(), spec.WebPort),
WebExternalURL: fmt.Sprintf("http://%s", utils.JoinHostPort(spec.Host, spec.WebPort)),
ClusterPeers: peers,
ClusterListenAddr: utils.JoinHostPort(i.GetListenHost(), spec.ClusterPort),

DeployDir: paths.Deploy,
LogDir: paths.Log,
DataDir: paths.Data[0],

NumaNode: spec.NumaNode,
}

// doesn't work
if _, err := i.setTLSConfig(ctx, false, nil, paths); err != nil {
Expand Down
Loading

0 comments on commit 786e033

Please sign in to comment.