From 7d3f82556a5375421753bba34dbbea6d0f4a6a13 Mon Sep 17 00:00:00 2001 From: aajkl Date: Tue, 9 Jul 2024 16:09:49 +0800 Subject: [PATCH] remove prof and quit channel --- configs/config.go | 1 - configs/config_test.go | 1 - internal/rpc/grpc_server.go | 4 +--- yavirtd.go | 32 +++++++------------------------- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/configs/config.go b/configs/config.go index d9a6366..118babd 100644 --- a/configs/config.go +++ b/configs/config.go @@ -219,7 +219,6 @@ type Config struct { CertPath string `toml:"cert_path" default:"/etc/eru/tls"` MaxConcurrency int `toml:"max_concurrency" default:"100000"` - ProfHTTPPort int `toml:"prof_http_port" default:"9999"` BindHTTPAddr string `toml:"bind_http_addr" default:"0.0.0.0:9696"` BindGRPCAddr string `toml:"bind_grpc_addr" default:"0.0.0.0:9697"` SkipGuestReportRegexps []string `toml:"skip_guest_report_regexps"` diff --git a/configs/config_test.go b/configs/config_test.go index 2437597..c64739b 100644 --- a/configs/config_test.go +++ b/configs/config_test.go @@ -65,7 +65,6 @@ func TestDefault(t *testing.T) { cfg := newDefault() assert.Equal(t, cfg.BindHTTPAddr, "0.0.0.0:9696") assert.Equal(t, cfg.BindGRPCAddr, "0.0.0.0:9697") - assert.Equal(t, cfg.ProfHTTPPort, 9999) assert.Equal(t, cfg.Resource.MinCPU, 1) assert.Equal(t, cfg.Resource.MaxCPU, 112) assert.Equal(t, cfg.MemStatsPeriod, 10) diff --git a/internal/rpc/grpc_server.go b/internal/rpc/grpc_server.go index b5d2cb6..ad63929 100644 --- a/internal/rpc/grpc_server.go +++ b/internal/rpc/grpc_server.go @@ -23,7 +23,6 @@ import ( type GRPCServer struct { server *grpc.Server app pb.YavirtdRPCServer - quit chan struct{} } func loadTLSCredentials(dir string) (credentials.TransportCredentials, error) { @@ -48,7 +47,7 @@ func loadTLSCredentials(dir string) (credentials.TransportCredentials, error) { return credentials.NewTLS(config), nil } -func New(cfg *configs.Config, svc service.Service, quit chan struct{}) (*GRPCServer, error) { +func New(cfg *configs.Config, svc service.Service) (*GRPCServer, error) { logger := log.WithFunc("rpc.New") opts := []grpc.ServerOption{} certDir := filepath.Join(cfg.CertPath, "yavirt") @@ -70,7 +69,6 @@ func New(cfg *configs.Config, svc service.Service, quit chan struct{}) (*GRPCSer srv := &GRPCServer{ server: grpc.NewServer(opts...), app: &GRPCYavirtd{service: svc}, - quit: quit, } reflection.Register(srv.server) diff --git a/yavirtd.go b/yavirtd.go index e5cf5fe..f29331b 100644 --- a/yavirtd.go +++ b/yavirtd.go @@ -8,7 +8,6 @@ import ( "os" "os/signal" "runtime" - "strings" "syscall" "time" @@ -96,11 +95,11 @@ func initConfig(c *cli.Context) error { return cfg.Prepare(c) } -func startHTTPServer(cfg *configs.Config) { +func startHTTPServer(addr string) { http.Handle("/metrics", metrics.Handler()) - http.HandleFunc("/debug", debug.Handler) + http.HandleFunc("/debug/custom", debug.Handler) server := &http.Server{ - Addr: cfg.BindHTTPAddr, + Addr: addr, ReadHeaderTimeout: 5 * time.Second, } if err := server.ListenAndServe(); err != nil { @@ -149,16 +148,16 @@ func Run(c *cli.Context) error { return errors.Wrap(err, "") } - quit := make(chan struct{}) - grpcSrv, err := grpcserver.New(&configs.Conf, br, quit) + grpcSrv, err := grpcserver.New(&configs.Conf, br) if err != nil { log.Error(c.Context, err, "failed to create grpc server") return err } errExitCh := make(chan struct{}) - go prof(configs.Conf.ProfHTTPPort) - go startHTTPServer(&configs.Conf) + if configs.Conf.BindHTTPAddr != "" { + go startHTTPServer(configs.Conf.BindHTTPAddr) + } go func() { defer close(errExitCh) if err := grpcSrv.Serve(); err != nil { @@ -174,25 +173,8 @@ func Run(c *cli.Context) error { case <-errExitCh: log.Warn(c.Context, "[main] server exit abnormally.") } - close(quit) grpcSrv.Stop(false) return nil } - -func prof(port int) { - var enable = strings.ToLower(os.Getenv("YAVIRTD_PPROF")) - switch enable { - case "": - fallthrough - case "0": - fallthrough - case "false": - fallthrough - case "off": - http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", port), nil) //nolint - default: - return - } -}