Skip to content

Commit

Permalink
Moved prometheus initialization logic to node/node.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jul 18, 2023
1 parent 20f2da8 commit ed406d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 11 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"sync"

"github.com/libp2p/go-libp2p/core/crypto"
Expand Down Expand Up @@ -263,6 +264,7 @@ func (n *Node) OnStart() error {
if err != nil {
return fmt.Errorf("error while starting settlement layer client: %w", err)
}
n.startPrometheusServer()
n.baseLayersHealthStatus = BaseLayersHealthStatus{
settlementHealthy: true,
daHealthy: true,
Expand Down Expand Up @@ -402,3 +404,12 @@ func (n *Node) healthStatusHandler(err error) {
}
}
}

func (n *Node) startPrometheusServer() {
go func() {
if err := http.ListenAndServe(":2112", nil); err != nil {

Check failure on line 410 in node/node.go

View workflow job for this annotation

GitHub Actions / lint

G114: Use of net/http serve function that has no support for setting timeouts (gosec)
// Error starting or closing listener:
n.Logger.Error("Prometheus HTTP server ListenAndServe", "err", err)
}
}()
}
8 changes: 0 additions & 8 deletions rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rpc
import (
"context"
"errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -85,13 +84,6 @@ func (s *Server) PubSubServer() *pubsub.Server {
// OnStart is called when Server is started (see service.BaseService for details).
func (s *Server) OnStart() error {
go s.eventListener()
go func() {
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":2112", nil)
if err != nil {
s.Logger.Error("error while running metrics server", "error", err)
}
}()
return s.startRPC()
}

Expand Down

0 comments on commit ed406d9

Please sign in to comment.