-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
345 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# WARNING: This file was auto-generated. Do not edit! | ||
# All your edit might be overwritten! | ||
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}} | ||
exec bin/tidb-dashboard \ | ||
{{- end}} | ||
--feature-version="{{.TidbVersion}}" \ | ||
--host="{{.IP}}" \ | ||
--port="{{.Port}}" \ | ||
--pd="{{template "PDList" .Endpoints}}" \ | ||
--data-dir="{{.DataDir}}" \ | ||
{{- if .TLSEnabled}} | ||
--tidb-ca tls/ca.crt \ | ||
--tidb-cert tls/tidb-dashboard.crt \ | ||
--tidb-key tls/tidb-dasboard.pem \ | ||
{{- end}} | ||
1>> "{{.LogDir}}/tidb-dashboard.log" \ | ||
2>> "{{.LogDir}}/tidb-dashboard_stderr.log" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
// Copyright 2020 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package spec | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"fmt" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/pingcap/tiup/pkg/cluster/ctxt" | ||
"github.com/pingcap/tiup/pkg/cluster/template/scripts" | ||
"github.com/pingcap/tiup/pkg/meta" | ||
) | ||
|
||
// DashboardSpec represents the Dashboard topology specification in topology.yaml | ||
type DashboardSpec struct { | ||
Host string `yaml:"host"` | ||
SSHPort int `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"` | ||
Version string `yaml:"version,omitempty"` | ||
Patched bool `yaml:"patched,omitempty"` | ||
IgnoreExporter bool `yaml:"ignore_exporter,omitempty"` | ||
Port int `yaml:"port" default:"23333"` | ||
DeployDir string `yaml:"deploy_dir,omitempty"` | ||
DataDir string `yaml:"data_dir,omitempty"` | ||
LogDir string `yaml:"log_dir,omitempty"` | ||
NumaNode string `yaml:"numa_node,omitempty" validate:"numa_node:editable"` | ||
Config map[string]interface{} `yaml:"config,omitempty" validate:"config:ignore"` | ||
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control:editable"` | ||
Arch string `yaml:"arch,omitempty"` | ||
OS string `yaml:"os,omitempty"` | ||
} | ||
|
||
// Status queries current status of the instance | ||
func (s *DashboardSpec) Status(ctx context.Context, timeout time.Duration, tlsCfg *tls.Config, pdList ...string) string { | ||
if timeout < time.Second { | ||
timeout = statusQueryTimeout | ||
} | ||
|
||
state := statusByHost(s.Host, s.Port, "/status", timeout, tlsCfg) | ||
|
||
return state | ||
} | ||
|
||
// Role returns the component role of the instance | ||
func (s *DashboardSpec) Role() string { | ||
return ComponentDashboard | ||
} | ||
|
||
// SSH returns the host and SSH port of the instance | ||
func (s *DashboardSpec) SSH() (string, int) { | ||
return s.Host, s.SSHPort | ||
} | ||
|
||
// GetMainPort returns the main port of the instance | ||
func (s *DashboardSpec) GetMainPort() int { | ||
return s.Port | ||
} | ||
|
||
// IsImported returns if the node is imported from TiDB-Ansible | ||
func (s *DashboardSpec) IsImported() bool { | ||
// TiDB-Ansible do not support dashboard | ||
return false | ||
} | ||
|
||
// IgnoreMonitorAgent returns if the node does not have monitor agents available | ||
func (s *DashboardSpec) IgnoreMonitorAgent() bool { | ||
return s.IgnoreExporter | ||
} | ||
|
||
// DashboardComponent represents Drainer component. | ||
type DashboardComponent struct{ Topology *Specification } | ||
|
||
// Name implements Component interface. | ||
func (c *DashboardComponent) Name() string { | ||
return ComponentDashboard | ||
} | ||
|
||
// Role implements Component interface. | ||
func (c *DashboardComponent) Role() string { | ||
return ComponentDashboard | ||
} | ||
|
||
// Instances implements Component interface. | ||
func (c *DashboardComponent) Instances() []Instance { | ||
ins := make([]Instance, 0, len(c.Topology.Drainers)) | ||
for _, s := range c.Topology.DashboardServers { | ||
s := s | ||
ins = append(ins, &DashboardInstance{BaseInstance{ | ||
InstanceSpec: s, | ||
Name: c.Name(), | ||
Host: s.Host, | ||
Port: s.Port, | ||
SSHP: s.SSHPort, | ||
|
||
Ports: []int{ | ||
s.Port, | ||
}, | ||
Dirs: []string{ | ||
s.DeployDir, | ||
s.DataDir, | ||
}, | ||
StatusFn: s.Status, | ||
UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { | ||
return UptimeByHost(s.Host, s.Port, timeout, tlsCfg) | ||
}, | ||
}, c.Topology}) | ||
} | ||
return ins | ||
} | ||
|
||
// DashboardInstance represent the Ddashboard instance. | ||
type DashboardInstance struct { | ||
BaseInstance | ||
topo Topology | ||
} | ||
|
||
// ScaleConfig deploy temporary config on scaling | ||
func (i *DashboardInstance) ScaleConfig( | ||
ctx context.Context, | ||
e ctxt.Executor, | ||
topo Topology, | ||
clusterName, | ||
clusterVersion, | ||
user string, | ||
paths meta.DirPaths, | ||
) error { | ||
s := i.topo | ||
defer func() { | ||
i.topo = s | ||
}() | ||
i.topo = mustBeClusterTopo(topo) | ||
|
||
return i.InitConfig(ctx, e, clusterName, clusterVersion, user, paths) | ||
} | ||
|
||
// InitConfig implements Instance interface. | ||
func (i *DashboardInstance) InitConfig( | ||
ctx context.Context, | ||
e ctxt.Executor, | ||
clusterName, | ||
clusterVersion, | ||
deployUser string, | ||
paths meta.DirPaths, | ||
) error { | ||
topo := i.topo.(*Specification) | ||
if err := i.BaseInstance.InitConfig(ctx, e, topo.GlobalOptions, deployUser, paths); err != nil { | ||
return err | ||
} | ||
enableTLS := topo.GlobalOptions.TLSEnabled | ||
spec := i.InstanceSpec.(*DashboardSpec) | ||
|
||
cfg := &scripts.DashboardScript{ | ||
TidbVersion: clusterVersion, | ||
IP: i.GetHost(), | ||
DeployDir: paths.Deploy, | ||
DataDir: paths.Data[0], | ||
LogDir: paths.Log, | ||
Port: spec.Port, | ||
NumaNode: spec.NumaNode, | ||
Endpoints: topo.Endpoints(deployUser), | ||
} | ||
|
||
fp := filepath.Join(paths.Cache, fmt.Sprintf("run_tidb-dashboard_%s_%d.sh", i.GetHost(), i.GetPort())) | ||
|
||
if err := cfg.ConfigToFile(fp); err != nil { | ||
return err | ||
} | ||
dst := filepath.Join(paths.Deploy, "scripts", "run_tidb-dashboard.sh") | ||
if err := e.Transfer(ctx, fp, dst, false, 0, false); err != nil { | ||
return err | ||
} | ||
|
||
_, _, err := e.Execute(ctx, "chmod +x "+dst, false) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
globalConfig := topo.ServerConfigs.Dashboard | ||
|
||
// set TLS configs | ||
spec.Config, err = i.setTLSConfig(ctx, enableTLS, spec.Config, paths) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := i.MergeServerConfig(ctx, e, globalConfig, spec.Config, paths); err != nil { | ||
return err | ||
} | ||
|
||
return checkConfig(ctx, e, i.ComponentName(), clusterVersion, i.OS(), i.Arch(), i.ComponentName()+".toml", paths, nil) | ||
} | ||
|
||
// setTLSConfig set TLS Config to support enable/disable TLS | ||
func (i *DashboardInstance) setTLSConfig(ctx context.Context, enableTLS bool, configs map[string]interface{}, paths meta.DirPaths) (map[string]interface{}, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.