Skip to content

Commit

Permalink
fix bug with metrics server not starting
Browse files Browse the repository at this point in the history
  • Loading branch information
MakMuftic committed Mar 13, 2024
1 parent ac07bc2 commit 71caed2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 3 additions & 4 deletions internal/rpcgateway/rpcgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/carlmjohnson/flowmatic"
"github.com/go-chi/chi/v5"
"github.com/pkg/errors"
"github.com/sygmaprotocol/rpc-gateway/internal/metrics"
"github.com/sygmaprotocol/rpc-gateway/internal/proxy"
)

Expand All @@ -37,7 +36,7 @@ func (r *RPCGateway) Stop(c context.Context) error {
)
}

func NewRPCGateway(config RPCGatewayConfig, router *chi.Mux, metricsServer *metrics.Server) (*RPCGateway, error) {
func NewRPCGateway(config RPCGatewayConfig, router *chi.Mux) (*RPCGateway, error) {
logLevel := slog.LevelWarn
if os.Getenv("DEBUG") == "true" {
logLevel = slog.LevelDebug
Expand Down Expand Up @@ -80,7 +79,7 @@ func NewRPCGateway(config RPCGatewayConfig, router *chi.Mux, metricsServer *metr

// NewRPCGatewayFromConfigFile creates an instance of RPCGateway from provided
// configuration file.
func NewRPCGatewayFromConfigFile(fileOrUrl string, router *chi.Mux, metricsServer *metrics.Server) (*RPCGateway, error) {
func NewRPCGatewayFromConfigFile(fileOrUrl string, router *chi.Mux) (*RPCGateway, error) {

Check warning on line 82 in internal/rpcgateway/rpcgateway.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func parameter fileOrUrl should be fileOrURL (revive)
config, err := util.LoadYamlFile[RPCGatewayConfig](fileOrUrl)
if err != nil {
return nil, errors.Wrap(err, "failed to load config")
Expand All @@ -89,5 +88,5 @@ func NewRPCGatewayFromConfigFile(fileOrUrl string, router *chi.Mux, metricsServe
fmt.Println("Starting RPC Gateway for " + config.Name + " on path: /" + config.Proxy.Path)

// Pass the metrics router as an argument to NewRPCGateway.
return NewRPCGateway(*config, router, metricsServer)
return NewRPCGateway(*config, router)
}
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func main() {
})

metricsServer := metrics.NewServer(metrics.Config{Port: uint(config.Metrics.Port)})
go func() {
err = metricsServer.Start()
defer metricsServer.Stop()

Check failure on line 76 in main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `metricsServer.Stop` is not checked (errcheck)
if err != nil {
fmt.Fprintf(os.Stderr, "error starting metrics server: %v\n", err)
}
}()

r := chi.NewRouter()
r.Use(httplog.RequestLogger(logger))
Expand All @@ -89,7 +96,7 @@ func main() {
wg.Add(1)
go func(gwConfig GatewayConfig) {
defer wg.Done()
err := startGateway(c, gwConfig, r, metricsServer)
err := startGateway(c, gwConfig, r)
if err != nil {
fmt.Fprintf(os.Stderr, "error starting gateway '%s': %v\n", gwConfig.Name, err)
}
Expand All @@ -113,8 +120,8 @@ func main() {
}
}

func startGateway(ctx context.Context, config GatewayConfig, router *chi.Mux, metricsServer *metrics.Server) error {
service, err := rpcgateway.NewRPCGatewayFromConfigFile(config.ConfigFile, router, metricsServer)
func startGateway(ctx context.Context, config GatewayConfig, router *chi.Mux) error {
service, err := rpcgateway.NewRPCGatewayFromConfigFile(config.ConfigFile, router)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("%s rpc-gateway failed", config.Name))
}
Expand Down

0 comments on commit 71caed2

Please sign in to comment.