Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server/v2): avoid server stop get call before start for multi components #22811

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions server/v2/api/grpcgateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ func New[T transaction.Tx](

s.logger = logger.With(log.ModuleKey, s.Name())
s.config = serverCfg
mux := http.NewServeMux()
mux.Handle("/", s.GRPCGatewayRouter)

s.server = &http.Server{
Addr: s.config.Address,
Handler: mux,
}
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
return s, nil
}

Expand Down Expand Up @@ -110,14 +116,6 @@ func (s *Server[T]) Start(ctx context.Context) error {
return nil
}

mux := http.NewServeMux()
mux.Handle("/", s.GRPCGatewayRouter)

s.server = &http.Server{
Addr: s.config.Address,
Handler: mux,
}

s.logger.Info("starting gRPC-Gateway server...", "address", s.config.Address)
if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return fmt.Errorf("failed to start gRPC-Gateway server: %w", err)
Expand Down
10 changes: 4 additions & 6 deletions server/v2/api/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func New[T transaction.Tx](
}
}
srv.config = serverCfg

srv.httpServer = &http.Server{
Addr: srv.config.Address,
Handler: srv.router,
}
return srv, nil
}

Expand All @@ -69,11 +72,6 @@ func (s *Server[T]) Start(ctx context.Context) error {
return nil
}

s.httpServer = &http.Server{
Addr: s.config.Address,
Handler: s.router,
}

s.logger.Info("starting HTTP server", "address", s.config.Address)
if err := s.httpServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
s.logger.Error("failed to start HTTP server", "error", err)
Expand Down
23 changes: 11 additions & 12 deletions server/v2/api/telemetry/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ func New[T transaction.Tx](cfg server.ConfigMap, logger log.Logger, enableTeleme
return nil, fmt.Errorf("failed to initialize metrics: %w", err)
}
srv.metrics = metrics
mux := http.NewServeMux()
// /metrics is the default standard path for Prometheus metrics.
mux.HandleFunc("/metrics", srv.metricsHandler)
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/metrics", http.StatusMovedPermanently)
})

srv.server = &http.Server{
Addr: srv.config.Address,
Handler: mux,
}
return srv, nil
}

Expand All @@ -74,18 +85,6 @@ func (s *Server[T]) Start(ctx context.Context) error {
return nil
}

mux := http.NewServeMux()
// /metrics is the default standard path for Prometheus metrics.
mux.HandleFunc("/metrics", s.metricsHandler)
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/metrics", http.StatusMovedPermanently)
})

s.server = &http.Server{
Addr: s.config.Address,
Handler: mux,
}

s.logger.Info("starting telemetry server...", "address", s.config.Address)
if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return fmt.Errorf("failed to start telemetry server: %w", err)
Expand Down
1 change: 1 addition & 0 deletions systemtests/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, beforeStart ...func(nodeNumb
if tomlFile == "app.toml" && IsV2() {
file := filepath.Join(WorkDir, s.nodePath(nodeNumber), "config", tomlFile)
EditToml(file, func(doc *tomledit.Document) {
SetValue(doc, fmt.Sprintf("%s:%d", node.IP, DefaultApiPort+nodeNumber), "grpc-gateway", "address")
SetValue(doc, fmt.Sprintf("%s:%d", node.IP, DefaultRestPort+nodeNumber), "rest", "address")
})
}
Expand Down
Loading