From 600eadfcf2526ddd22026d5c2464d2fa1af7bb74 Mon Sep 17 00:00:00 2001 From: Joonas Lehtimaki Date: Tue, 18 Jun 2024 13:28:23 +0300 Subject: [PATCH] fix: timeouts - make exporter perform better, running collectors as routines - increasing default timeouts since processes take quite a while to perform - adding /healthz endpoint to check the process health --- cmd/warden-exporter/warden-exporter.go | 21 +++++++++++++++------ pkg/collector/warden_collector.go | 4 +++- pkg/collector/warp_collector.go | 2 ++ pkg/config/config.go | 4 ++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/cmd/warden-exporter/warden-exporter.go b/cmd/warden-exporter/warden-exporter.go index 78eca15..e9fad7c 100644 --- a/cmd/warden-exporter/warden-exporter.go +++ b/cmd/warden-exporter/warden-exporter.go @@ -46,28 +46,29 @@ func main() { Cfg: cfg, } - prometheus.MustRegister(wardenCollector) - prometheus.MustRegister(intentCollector) - prometheus.MustRegister(authCollector) - prometheus.MustRegister(walletCollector) + go prometheus.MustRegister(wardenCollector) + go prometheus.MustRegister(intentCollector) + go prometheus.MustRegister(authCollector) + go prometheus.MustRegister(walletCollector) } if cfg.ValidatorMetrics { validatorCollector := collector.ValidatorsCollector{ Cfg: cfg, } - prometheus.MustRegister(validatorCollector) + go prometheus.MustRegister(validatorCollector) } if cfg.WarpMetrics { warpCollector := collector.WarpCollector{ Cfg: cfg, } - prometheus.MustRegister(warpCollector) + go prometheus.MustRegister(warpCollector) } mux := http.NewServeMux() mux.Handle("/metrics", promhttp.Handler()) + mux.HandleFunc("/healthz", healthCheckHandler) addr := fmt.Sprintf(":%d", *port) @@ -84,3 +85,11 @@ func main() { log.Fatal(err.Error()) } } + +// healthCheckHandler handles the /healthz endpoint. +func healthCheckHandler(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + if _, err := w.Write([]byte("OK")); err != nil { + log.Error(err.Error()) + } +} diff --git a/pkg/collector/warden_collector.go b/pkg/collector/warden_collector.go index a7305d3..1f43ced 100644 --- a/pkg/collector/warden_collector.go +++ b/pkg/collector/warden_collector.go @@ -136,6 +136,8 @@ func (w WardenCollector) Describe(ch chan<- *prometheus.Desc) { ch <- pendingKeys ch <- keychains ch <- keychainRequests + ch <- keychain + ch <- keychainSignatureRequests } func (w WardenCollector) Collect(ch chan<- prometheus.Metric) { @@ -289,5 +291,5 @@ func (w WardenCollector) Collect(ch chan<- prometheus.Metric) { ) } - log.Debug("Stop collecting", zap.String("metric", spacesMetricName)) + log.Info("Stop collecting", zap.String("metric", spacesMetricName)) } diff --git a/pkg/collector/warp_collector.go b/pkg/collector/warp_collector.go index 63093a7..5ed9e5d 100644 --- a/pkg/collector/warp_collector.go +++ b/pkg/collector/warp_collector.go @@ -6,6 +6,7 @@ import ( _ "github.com/go-sql-driver/mysql" // mysql driver "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" "github.com/warden-protocol/warden-exporter/pkg/config" log "github.com/warden-protocol/warden-exporter/pkg/logger" @@ -114,6 +115,7 @@ func (w WarpCollector) Collect(ch chan<- prometheus.Metric) { }..., ) } + log.Info("Stop collecting", zap.String("metric", "warp")) } func queryWarpUsers(db *sql.DB) (int, error) { diff --git a/pkg/config/config.go b/pkg/config/config.go index 82f97d4..2770e86 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -20,8 +20,8 @@ func configError(msg string) error { type Config struct { Addr string `env:"GRPC_ADDR" envDefault:"grpc.buenavista.wardenprotocol.org:443"` TLS bool `env:"GRPC_TLS_ENABLED" envDefault:"true"` - Timeout int `env:"GRPC_TIMEOUT_SECONDS" envDefault:"15"` - TTL int `env:"TTL" envDefault:"30"` + Timeout int `env:"GRPC_TIMEOUT_SECONDS" envDefault:"45"` + TTL int `env:"TTL" envDefault:"60"` ChainID string `env:"CHAIN_ID" envDefault:"buenavista-1"` WardenMetrics bool `env:"WARDEN_METRICS" envDefault:"true"` ValidatorMetrics bool `env:"VALIDATOR_METRICS" envDefault:"true"`