diff --git a/pkg/api/http/server.go b/pkg/api/http/server.go index de4f0953..cb76a32d 100644 --- a/pkg/api/http/server.go +++ b/pkg/api/http/server.go @@ -5,6 +5,9 @@ import ( "fmt" "time" + "glide/pkg/pools" + "glide/pkg/telemetry" + "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/app/server" "github.com/cloudwego/hertz/pkg/common/utils" @@ -12,12 +15,16 @@ import ( ) type Server struct { - server *server.Hertz + telemetry *telemetry.Telemetry + router *pools.Router + server *server.Hertz } -func NewServer(config *ServerConfig) (*Server, error) { +func NewServer(config *ServerConfig, tel *telemetry.Telemetry, router *pools.Router) (*Server, error) { return &Server{ - server: config.ToServer(), + telemetry: tel, + router: router, + server: config.ToServer(), }, nil } @@ -32,7 +39,9 @@ func (srv *Server) Run() error { func (srv *Server) Shutdown(_ context.Context) error { exitWaitTime := srv.server.GetOptions().ExitWaitTimeout - println(fmt.Sprintf("Begin graceful shutdown, wait at most %d seconds...", exitWaitTime/time.Second)) + srv.telemetry.Logger().Info( + fmt.Sprintf("Begin graceful shutdown, wait at most %d seconds...", exitWaitTime/time.Second), + ) ctx, cancel := context.WithTimeout(context.Background(), exitWaitTime) defer cancel() diff --git a/pkg/api/servers.go b/pkg/api/servers.go index bdc2152b..0e68211e 100644 --- a/pkg/api/servers.go +++ b/pkg/api/servers.go @@ -4,6 +4,9 @@ import ( "context" "sync" + "glide/pkg/pools" + "glide/pkg/telemetry" + "glide/pkg/api/http" ) @@ -12,13 +15,14 @@ type ServerManager struct { shutdownWG *sync.WaitGroup } -func NewServerManager(httpConfig *http.ServerConfig) (*ServerManager, error) { - httpServer, err := http.NewServer(httpConfig) - // TODO: init other servers like gRPC in future +func NewServerManager(httpConfig *http.ServerConfig, tel *telemetry.Telemetry, router *pools.Router) (*ServerManager, error) { + httpServer, err := http.NewServer(httpConfig, tel, router) if err != nil { return nil, err } + // TODO: init other servers like gRPC in future + return &ServerManager{ httpServer: httpServer, shutdownWG: &sync.WaitGroup{}, diff --git a/pkg/gateway.go b/pkg/gateway.go index 9e97c749..94c6f03c 100644 --- a/pkg/gateway.go +++ b/pkg/gateway.go @@ -7,6 +7,8 @@ import ( "os/signal" "syscall" + "glide/pkg/pools" + "glide/pkg/telemetry" "go.uber.org/zap" @@ -40,7 +42,12 @@ func NewGateway() (*Gateway, error) { return nil, err } - serverManager, err := api.NewServerManager(&http.ServerConfig{}) + router, err := pools.NewRouter(tel) + if err != nil { + return nil, err + } + + serverManager, err := api.NewServerManager(&http.ServerConfig{}, tel, router) if err != nil { return nil, err } diff --git a/pkg/pools/router.go b/pkg/pools/router.go new file mode 100644 index 00000000..27b829bf --- /dev/null +++ b/pkg/pools/router.go @@ -0,0 +1,13 @@ +package pools + +import "glide/pkg/telemetry" + +type Router struct { + telemetry *telemetry.Telemetry +} + +func NewRouter(tel *telemetry.Telemetry) (*Router, error) { + return &Router{ + telemetry: tel, + }, nil +}