Skip to content

Commit

Permalink
perf: optimize communication exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DokiDoki1103 committed Jan 9, 2024
1 parent 39d22ce commit 709ec77
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 28 deletions.
6 changes: 3 additions & 3 deletions cmd/monitor/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func NewConfig() *Config {
host, _ := os.Hostname()

config := &Config{
EtcdEndpointsLine: "http://127.0.0.1:2379",
EtcdEndpointsLine: "http://rbd-etcd:2379",
EtcdEndpoints: []string{},
AdvertiseAddr: host + ":9999",
BindIP: host,
Expand Down Expand Up @@ -134,7 +134,7 @@ func NewConfig() *Config {
return config
}

//AddFlag monitor flag
// AddFlag monitor flag
func (c *Config) AddFlag(cmd *pflag.FlagSet) {
cmd.StringVar(&c.EtcdEndpointsLine, "etcd-endpoints", c.EtcdEndpointsLine, "etcd endpoints list.")
cmd.StringVar(&c.EtcdCaFile, "etcd-ca", "", "etcd tls ca file ")
Expand All @@ -148,7 +148,7 @@ func (c *Config) AddFlag(cmd *pflag.FlagSet) {
cmd.StringVar(&c.KubeConfig, "kube-config", "", "kubernetes api server config file")
}

//AddPrometheusFlag prometheus flag
// AddPrometheusFlag prometheus flag
func (c *Config) AddPrometheusFlag(cmd *pflag.FlagSet) {
cmd.StringVar(&c.ConfigFile, "config.file", c.ConfigFile, "Prometheus configuration file path.")

Expand Down
14 changes: 8 additions & 6 deletions cmd/mq/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import "github.com/spf13/pflag"
import "github.com/sirupsen/logrus"
import "fmt"

//Config config server
// Config config server
type Config struct {
EtcdEndPoints []string
EtcdCaFile string
Expand All @@ -38,21 +38,20 @@ type Config struct {
HostName string
}

//MQServer lb worker server
// MQServer lb worker server
type MQServer struct {
Config
LogLevel string
}

//NewMQServer new server
// NewMQServer new server
func NewMQServer() *MQServer {
return &MQServer{}
}

//AddFlags config
// AddFlags config
func (a *MQServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.LogLevel, "log-level", "info", "the mq log level")
fs.StringSliceVar(&a.EtcdEndPoints, "etcd-endpoints", []string{"http://127.0.0.1:2379"}, "etcd v3 cluster endpoints.")
fs.IntVar(&a.EtcdTimeout, "etcd-timeout", 10, "etcd http timeout seconds")
fs.StringVar(&a.EtcdCaFile, "etcd-ca", "", "etcd tls ca file ")
fs.StringVar(&a.EtcdCertFile, "etcd-cert", "", "etcd tls cert file")
Expand All @@ -63,9 +62,12 @@ func (a *MQServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.PrometheusMetricPath, "metric", "/metrics", "prometheus metrics path")
fs.StringVar(&a.HostIP, "hostIP", "", "Current node Intranet IP")
fs.StringVar(&a.HostName, "hostName", "", "Current node host name")

fs.StringSliceVar(&a.EtcdEndPoints, "etcd-endpoints", []string{"http://rbd-etcd:2379"}, "etcd v3 cluster endpoints.")

}

//SetLog 设置log
// SetLog 设置log
func (a *MQServer) SetLog() {
level, err := logrus.ParseLevel(a.LogLevel)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mqcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func main() {

// AddFlags -
func AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&server, "server", "127.0.0.1:6300", "mq server")
fs.StringVar(&server, "server", "rbd-mq:6300", "mq server")
fs.StringVar(&topic, "topic", "builder", "mq topic")
fs.StringVar(&taskbody, "task-body", "", "mq task body")
fs.StringVar(&taskfile, "task-file", "", "mq task body file")
Expand Down
8 changes: 5 additions & 3 deletions cmd/node/option/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,12 @@ type UDPMonitorConfig struct {
func (a *Conf) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.LogLevel, "log-level", "info", "the log level")
fs.StringVar(&a.LogFile, "log-file", "", "the log file path that log output")
fs.StringVar(&a.PrometheusAPI, "prometheus", "http://rbd-monitor:9999", "the prometheus server address")
fs.StringVar(&a.NodePath, "nodePath", "/rainbond/nodes", "the path of node in etcd")
fs.StringVar(&a.HostID, "nodeid", "", "the unique ID for this node. Just specify, don't modify")
fs.StringVar(&a.HostIP, "hostIP", "", "the host ip you can define. default get ip from eth0")
fs.StringVar(&a.PodIP, "podIP", "", "The pod ip of node.")
fs.StringSliceVar(&a.EventLogServer, "event-log-server", []string{"127.0.0.1:6366"}, "host:port slice of event log server")
fs.StringVar(&a.ConfigStoragePath, "config-path", "/rainbond/acp_configs", "the path of config to store(new)")
fs.StringVar(&a.Service, "servicePath", "/traefik/backends", "the path of service info to store")
fs.StringSliceVar(&a.EtcdEndpoints, "etcd", []string{"http://127.0.0.1:2379"}, "the path of node in etcd")
fs.StringVar(&a.EtcdCaFile, "etcd-ca", "", "verify etcd certificates of TLS-enabled secure servers using this CA bundle")
fs.StringVar(&a.EtcdCertFile, "etcd-cert", "", "identify secure etcd client using this TLS certificate file")
fs.StringVar(&a.EtcdKeyFile, "etcd-key", "", "identify secure etcd client using this TLS key file")
Expand Down Expand Up @@ -199,6 +196,11 @@ func (a *Conf) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.HostsFile, "hostsfile", "/newetc/hosts", "/etc/hosts mapped path in the container. eg. /etc/hosts:/tmp/hosts. Do not set hostsfile to /etc/hosts")
fs.StringVar(&a.ContainerRuntime, "container-runtime", sources.ContainerRuntimeContainerd, "container runtime, support docker and containerd")
fs.StringVar(&a.RuntimeEndpoint, "runtime-endpoint", sources.RuntimeEndpointContainerd, "container runtime endpoint")

fs.StringSliceVar(&a.EventLogServer, "event-log-server", []string{"rbd-eventlog:6366"}, "host:port slice of event log server")
fs.StringSliceVar(&a.EtcdEndpoints, "etcd", []string{"http://rbd-etcd:2379"}, "the path of node in etcd")
fs.StringVar(&a.PrometheusAPI, "prometheus", "http://rbd-monitor:9999", "the prometheus server address")

}

// SetLog 设置log
Expand Down
12 changes: 6 additions & 6 deletions cmd/webcli/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/spf13/pflag"
)

//Config config server
// Config config server
type Config struct {
EtcdEndPoints []string
EtcdCaFile string
Expand All @@ -40,21 +40,21 @@ type Config struct {
K8SConfPath string
}

//WebCliServer container webcli server
// WebCliServer container webcli server
type WebCliServer struct {
Config
LogLevel string
}

//NewWebCliServer new server
// NewWebCliServer new server
func NewWebCliServer() *WebCliServer {
return &WebCliServer{}
}

//AddFlags config
// AddFlags config
func (a *WebCliServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.LogLevel, "log-level", "info", "the webcli log level")
fs.StringSliceVar(&a.EtcdEndPoints, "etcd-endpoints", []string{"http://127.0.0.1:2379"}, "etcd v3 cluster endpoints.")
fs.StringSliceVar(&a.EtcdEndPoints, "etcd-endpoints", []string{"http://rbd-etcd:2379"}, "etcd v3 cluster endpoints.")
fs.StringVar(&a.EtcdCaFile, "etcd-ca", "", "etcd tls ca file ")
fs.StringVar(&a.EtcdCertFile, "etcd-cert", "", "etcd tls cert file")
fs.StringVar(&a.EtcdKeyFile, "etcd-key", "", "etcd http tls cert key file")
Expand All @@ -66,7 +66,7 @@ func (a *WebCliServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.PrometheusMetricPath, "metric", "/metrics", "prometheus metrics path")
}

//SetLog 设置log
// SetLog 设置log
func (a *WebCliServer) SetLog() {
level, err := logrus.ParseLevel(a.LogLevel)
if err != nil {
Expand Down
20 changes: 11 additions & 9 deletions cmd/worker/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"k8s.io/client-go/kubernetes"
)

//Config config server
// Config config server
type Config struct {
EtcdEndPoints []string
EtcdCaFile string
Expand Down Expand Up @@ -67,22 +67,21 @@ type Helm struct {
ChartCache string
}

//Worker worker server
// Worker worker server
type Worker struct {
Config
LogLevel string
RunMode string //default,sync
}

//NewWorker new server
// NewWorker new server
func NewWorker() *Worker {
return &Worker{}
}

//AddFlags config
// AddFlags config
func (a *Worker) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.LogLevel, "log-level", "info", "the worker log level")
fs.StringSliceVar(&a.EtcdEndPoints, "etcd-endpoints", []string{"http://127.0.0.1:2379"}, "etcd v3 cluster endpoints.")
fs.StringVar(&a.EtcdCaFile, "etcd-ca", "", "")
fs.StringVar(&a.EtcdCertFile, "etcd-cert", "", "")
fs.StringVar(&a.EtcdKeyFile, "etcd-key", "", "")
Expand All @@ -92,12 +91,10 @@ func (a *Worker) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.Listen, "listen", ":6369", "prometheus listen host and port")
fs.StringVar(&a.DBType, "db-type", "mysql", "db type mysql or etcd")
fs.StringVar(&a.MysqlConnectionInfo, "mysql", "root:admin@tcp(127.0.0.1:3306)/region", "mysql db connection info")
fs.StringSliceVar(&a.EventLogServers, "event-servers", []string{"127.0.0.1:6366"}, "event log server address. simple lb")
fs.StringVar(&a.KubeConfig, "kube-config", "", "kubernetes api server config file")
fs.IntVar(&a.KubeAPIQPS, "kube-api-qps", 50, "kube client qps")
fs.IntVar(&a.KubeAPIBurst, "kube-api-burst", 10, "kube clint burst")
fs.IntVar(&a.MaxTasks, "max-tasks", 50, "the max tasks for per node")
fs.StringVar(&a.MQAPI, "mq-api", "127.0.0.1:6300", "acp_mq api")
fs.StringVar(&a.RunMode, "run", "sync", "sync data when worker start")
fs.StringVar(&a.NodeName, "node-name", "", "the name of this worker,it must be global unique name")
fs.StringVar(&a.HostIP, "host-ip", "", "the ip of this worker,it must be global connected ip")
Expand All @@ -108,12 +105,17 @@ func (a *Worker) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.GrdataPVCName, "grdata-pvc-name", "rbd-cpt-grdata", "The name of grdata persistent volume claim")
fs.StringVar(&a.Helm.DataDir, "/grdata/helm", "/grdata/helm", "The data directory of Helm.")
fs.StringVar(&a.SharedStorageClass, "shared-storageclass", "", "custom shared storage class.use the specified storageclass to create shared storage, if this parameter is not specified, it will use rainbondsssc by default")

fs.StringSliceVar(&a.EtcdEndPoints, "etcd-endpoints", []string{"http://rbd-etcd:2379"}, "etcd v3 cluster endpoints.")
fs.StringVar(&a.MQAPI, "mq-api", "rbd-mq:6300", "acp_mq api")
fs.StringSliceVar(&a.EventLogServers, "event-servers", []string{"rbd-eventlog:6366"}, "event log server address. simple lb")

a.Helm.RepoFile = path.Join(a.Helm.DataDir, "repo/repositories.yaml")
a.Helm.RepoCache = path.Join(a.Helm.DataDir, "cache")
a.Helm.ChartCache = path.Join(a.Helm.DataDir, "chart")
}

//SetLog 设置log
// SetLog 设置log
func (a *Worker) SetLog() {
level, err := logrus.ParseLevel(a.LogLevel)
if err != nil {
Expand All @@ -123,7 +125,7 @@ func (a *Worker) SetLog() {
logrus.SetLevel(level)
}

//CheckEnv 检测环境变量
// CheckEnv 检测环境变量
func (a *Worker) CheckEnv() error {
if err := os.Setenv("GRDATA_PVC_NAME", a.Config.GrdataPVCName); err != nil {
return fmt.Errorf("set env 'GRDATA_PVC_NAME': %v", err)
Expand Down

0 comments on commit 709ec77

Please sign in to comment.