You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
// When executing MustNewServer, the dev HTTP server starts
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
// Sleeping for 100 seconds is used to simulate scenarios like loading cache data
// During this 100-second sleep, if you curl http://xx.xxx.xx:xxx/ready, it will return 200 OK
// However, at this point, the REST server is not fully ready,
// as health.AddProbe(healthManager) has not been executed
time.Sleep(100 * time.Second)
ctx := svc.NewServiceContext(&c)
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
// health.AddProbe(healthManager) is executed only in start()
// I think health.AddProbe(healthManager) should be moved into NewServer
server.Start()
}
I think health.AddProbe should be added in NewServer, and then the server should be marked as ready in Start.
Otherwise, the /ping endpoint of the devserver will be ready even when the rest service is not ready.
A typical case is when we use the devserver /ping endpoint as the readiness probe for Kubernetes pods.
If the rest server is not actually ready, traffic will be routed to the service prematurely.
eg:
I think
health.AddProbe
should be added inNewServer
, and then the server should be marked as ready inStart
.Otherwise, the /ping endpoint of the
devserver
will be ready even when the rest service is not ready.A typical case is when we use the
devserver
/ping endpoint as the readiness probe for Kubernetes pods.If the rest server is not actually ready, traffic will be routed to the service prematurely.
ref:
go-zero/zrpc/internal/rpcserver.go
Line 66 in 4ac8b49
go-zero/rest/internal/starter.go
Line 59 in 4ac8b49
The text was updated successfully, but these errors were encountered: