Skip to content

Commit

Permalink
remove prof and quit channel
Browse files Browse the repository at this point in the history
  • Loading branch information
aajkl committed Jul 9, 2024
1 parent dfbff01 commit 7d3f825
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
1 change: 0 additions & 1 deletion configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 0 additions & 1 deletion configs/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions internal/rpc/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
type GRPCServer struct {
server *grpc.Server
app pb.YavirtdRPCServer
quit chan struct{}
}

func loadTLSCredentials(dir string) (credentials.TransportCredentials, error) {
Expand All @@ -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")
Expand All @@ -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)

Expand Down
32 changes: 7 additions & 25 deletions yavirtd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
}

0 comments on commit 7d3f825

Please sign in to comment.