This commit is contained in:
Felipe Andrade 2023-07-18 10:51:22 -07:00
parent 4a3850c179
commit 322db48820
5 changed files with 14 additions and 13 deletions

@ -16,7 +16,7 @@ enabled = true
# Host for the healthz endpoint to listen on # Host for the healthz endpoint to listen on
host = "0.0.0.0" host = "0.0.0.0"
# Port for the above. # Port for the above.
port = 8080 port = "8080"
[metrics] [metrics]
# Whether or not to enable Prometheus metrics # Whether or not to enable Prometheus metrics
@ -24,7 +24,7 @@ enabled = true
# Host for the Prometheus metrics endpoint to listen on. # Host for the Prometheus metrics endpoint to listen on.
host = "0.0.0.0" host = "0.0.0.0"
# Port for the above. # Port for the above.
port = 9761 port = "9761"
[wallets.default] [wallets.default]
# OP Stack Chain ID # OP Stack Chain ID

@ -29,13 +29,13 @@ type MetricsConfig struct {
Enabled bool `toml:"enabled"` Enabled bool `toml:"enabled"`
Debug bool `toml:"debug"` Debug bool `toml:"debug"`
Host string `toml:"host"` Host string `toml:"host"`
Port int `toml:"port"` Port string `toml:"port"`
} }
type HealthzConfig struct { type HealthzConfig struct {
Enabled bool `toml:"enabled"` Enabled bool `toml:"enabled"`
Host string `toml:"host"` Host string `toml:"host"`
Port int `toml:"port"` Port string `toml:"port"`
} }
type WalletConfig struct { type WalletConfig struct {
@ -80,12 +80,12 @@ func New(file string) (*Config, error) {
func (c *Config) Validate() error { func (c *Config) Validate() error {
if c.Metrics.Enabled { if c.Metrics.Enabled {
if c.Metrics.Host == "" || c.Metrics.Port == 0 { if c.Metrics.Host == "" || c.Metrics.Port == "" {
return errors.New("metrics is enabled but host or port are missing") return errors.New("metrics is enabled but host or port are missing")
} }
} }
if c.Healthz.Enabled { if c.Healthz.Enabled {
if c.Healthz.Host == "" || c.Healthz.Port == 0 { if c.Healthz.Host == "" || c.Healthz.Port == "" {
return errors.New("healthz is enabled but host or port are missing") return errors.New("healthz is enabled but host or port are missing")
} }
} }

@ -5,6 +5,7 @@ import (
"time" "time"
"github.com/ethereum-optimism/optimism/op-ufm/pkg/metrics" "github.com/ethereum-optimism/optimism/op-ufm/pkg/metrics"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -32,7 +33,9 @@ func Dial(providerName string, url string) (*InstrumentedEthClient, error) {
func (i *InstrumentedEthClient) TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error) { func (i *InstrumentedEthClient) TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error) {
start := time.Now() start := time.Now()
log.Debug(">> TransactionByHash", "hash", hash, "provider", i.providerName)
tx, isPending, err := i.c.TransactionByHash(ctx, hash) tx, isPending, err := i.c.TransactionByHash(ctx, hash)
log.Debug("<< TransactionByHash", "tx", tx, "isPending", isPending, "err", err, "hash", hash, "provider", i.providerName)
if err != nil { if err != nil {
if !i.ignorableErrors(err) { if !i.ignorableErrors(err) {
metrics.RecordError(i.providerName, "ethclient.TransactionByHash") metrics.RecordError(i.providerName, "ethclient.TransactionByHash")

@ -2,7 +2,6 @@ package service
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -14,10 +13,9 @@ type HealthzServer struct {
server *http.Server server *http.Server
} }
func (h *HealthzServer) Start(ctx context.Context, host string, port int) error { func (h *HealthzServer) Start(ctx context.Context, addr string) error {
hdlr := mux.NewRouter() hdlr := mux.NewRouter()
hdlr.HandleFunc("/healthz", h.Handle).Methods("GET") hdlr.HandleFunc("/healthz", h.Handle).Methods("GET")
addr := fmt.Sprintf("%s:%d", host, port)
c := cors.New(cors.Options{ c := cors.New(cors.Options{
AllowedOrigins: []string{"*"}, AllowedOrigins: []string{"*"},
}) })

@ -2,7 +2,7 @@ package service
import ( import (
"context" "context"
"fmt" "net"
"github.com/ethereum-optimism/optimism/op-ufm/pkg/config" "github.com/ethereum-optimism/optimism/op-ufm/pkg/config"
"github.com/ethereum-optimism/optimism/op-ufm/pkg/metrics" "github.com/ethereum-optimism/optimism/op-ufm/pkg/metrics"
@ -31,10 +31,10 @@ func New(cfg *config.Config) *Service {
func (s *Service) Start(ctx context.Context) { func (s *Service) Start(ctx context.Context) {
log.Info("service starting") log.Info("service starting")
if s.Config.Healthz.Enabled { if s.Config.Healthz.Enabled {
addr := fmt.Sprintf("%s:%d", s.Config.Healthz.Host, s.Config.Healthz.Port) addr := net.JoinHostPort(s.Config.Healthz.Host, s.Config.Healthz.Port)
log.Info("starting healthz server", "addr", addr) log.Info("starting healthz server", "addr", addr)
go func() { go func() {
if err := s.Healthz.Start(ctx, s.Config.Healthz.Host, s.Config.Healthz.Port); err != nil { if err := s.Healthz.Start(ctx, addr); err != nil {
log.Error("error starting healthz server", "err", err) log.Error("error starting healthz server", "err", err)
} }
}() }()
@ -42,7 +42,7 @@ func (s *Service) Start(ctx context.Context) {
metrics.Debug = s.Config.Metrics.Debug metrics.Debug = s.Config.Metrics.Debug
if s.Config.Metrics.Enabled { if s.Config.Metrics.Enabled {
addr := fmt.Sprintf("%s:%d", s.Config.Metrics.Host, s.Config.Metrics.Port) addr := net.JoinHostPort(s.Config.Metrics.Host, s.Config.Metrics.Port)
log.Info("starting metrics server", "addr", addr) log.Info("starting metrics server", "addr", addr)
go func() { go func() {
if err := s.Metrics.Start(ctx, addr); err != nil { if err := s.Metrics.Start(ctx, addr); err != nil {