app/server: make sure if metrics server goroutine executed (#17323)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9897d4651a
Коммит
ff980266ac
@@ -1521,8 +1521,7 @@ func (s *Server) StopMetricsServer() {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
s.metricsServer.Shutdown(ctx)
|
s.metricsServer.Shutdown(ctx)
|
||||||
s.Log.Info("Metrics and profiling server is stopping", mlog.String("address", *s.Config().MetricsSettings.ListenAddress))
|
s.Log.Info("Metrics and profiling server is stopping")
|
||||||
s.metricsServer = nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1581,27 +1580,36 @@ func (s *Server) InitMetricsRouter() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) startMetricsServer() {
|
func (s *Server) startMetricsServer() {
|
||||||
|
var notify chan struct{}
|
||||||
s.metricsLock.Lock()
|
s.metricsLock.Lock()
|
||||||
defer s.metricsLock.Unlock()
|
defer func() {
|
||||||
|
if notify != nil {
|
||||||
|
<-notify
|
||||||
|
}
|
||||||
|
s.metricsLock.Unlock()
|
||||||
|
}()
|
||||||
|
|
||||||
if s.metricsServer != nil {
|
l, err := net.Listen("tcp", *s.Config().MetricsSettings.ListenAddress)
|
||||||
|
if err != nil {
|
||||||
|
mlog.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notify = make(chan struct{})
|
||||||
s.metricsServer = &http.Server{
|
s.metricsServer = &http.Server{
|
||||||
Addr: *s.Config().MetricsSettings.ListenAddress,
|
|
||||||
Handler: handlers.RecoveryHandler(handlers.PrintRecoveryStack(true))(s.metricsRouter),
|
Handler: handlers.RecoveryHandler(handlers.PrintRecoveryStack(true))(s.metricsRouter),
|
||||||
ReadTimeout: time.Duration(*s.Config().ServiceSettings.ReadTimeout) * time.Second,
|
ReadTimeout: time.Duration(*s.Config().ServiceSettings.ReadTimeout) * time.Second,
|
||||||
WriteTimeout: time.Duration(*s.Config().ServiceSettings.WriteTimeout) * time.Second,
|
WriteTimeout: time.Duration(*s.Config().ServiceSettings.WriteTimeout) * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := s.metricsServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
close(notify)
|
||||||
|
if err := s.metricsServer.Serve(l); err != nil && err != http.ErrServerClosed {
|
||||||
mlog.Critical(err.Error())
|
mlog.Critical(err.Error())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
s.Log.Info("Metrics and profiling server is started", mlog.String("address", *s.Config().MetricsSettings.ListenAddress))
|
s.Log.Info("Metrics and profiling server is started", mlog.String("address", l.Addr().String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func doLicenseExpirationCheck(a *App) {
|
func doLicenseExpirationCheck(a *App) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user