diff --git a/config.yaml b/config.yaml index f475a59..99875d5 100644 --- a/config.yaml +++ b/config.yaml @@ -18,12 +18,16 @@ rpc: url: https://juno-rpc.polkachu.com:443 - chainId: kaiyo-1 url: https://kujira-rpc.polkachu.com:443 + - chainId: noble-1 + url: https://noble-rpc.polkachu.com:443 - chainId: nois-1 url: https://nois-rpc.polkachu.com:443 - chainId: osmo-test-5 url: https://rpc.osmotest5.osmosis.zone:443 - chainId: osmosis-1 url: https://osmosis-rpc.stakely.io:443 + - chainId: sandbox-01 + url: https://rpc.sandbox-01.aksh.pw:443 - chainId: theta-testnet-001 url: https://rpc.sentry-01.theta-testnet.polypore.xyz:443 - chainId: umee-1 diff --git a/go.mod b/go.mod index 520083d..0e909d7 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( cosmossdk.io/math v1.0.1 github.com/caarlos0/env/v9 v9.0.0 github.com/cosmos/relayer/v2 v2.4.1 - github.com/google/go-cmp v0.5.9 github.com/google/go-github/v55 v55.0.0 github.com/prometheus/client_golang v1.15.0 github.com/stretchr/testify v1.8.4 @@ -87,6 +86,7 @@ require ( github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect + github.com/google/go-cmp v0.5.9 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/orderedcode v0.0.1 // indirect github.com/google/s2a-go v0.1.4 // indirect diff --git a/pkg/account/account.go b/pkg/account/account.go index 726fcf6..4c9518f 100644 --- a/pkg/account/account.go +++ b/pkg/account/account.go @@ -8,17 +8,11 @@ import ( "github.com/archway-network/relayer_exporter/pkg/chain" ) -const ( - successStatus = "success" - errorStatus = "error" -) - type Account struct { Address string `yaml:"address"` Denom string `yaml:"denom"` ChainID string `yaml:"chainId"` Balance math.Int - Status string } func (a *Account) GetBalance(rpcs map[string]string) error { @@ -34,13 +28,10 @@ func (a *Account) GetBalance(rpcs map[string]string) error { coins, err := chain.ChainProvider.QueryBalanceWithAddress(ctx, a.Address) if err != nil { - a.Status = errorStatus - return err } a.Balance = coins.AmountOf(a.Denom) - a.Status = successStatus return nil } diff --git a/pkg/collector/collector.go b/pkg/collector/collector.go index 5c79796..85793b1 100644 --- a/pkg/collector/collector.go +++ b/pkg/collector/collector.go @@ -13,6 +13,8 @@ import ( ) const ( + successStatus = "success" + errorStatus = "error" clientExpiryMetricName = "cosmos_ibc_client_expiry" walletBalanceMetricName = "cosmos_wallet_balance" ) @@ -21,7 +23,7 @@ var ( clientExpiry = prometheus.NewDesc( clientExpiryMetricName, "Returns light client expiry in unixtime.", - []string{"host_chain_id", "client_id", "target_chain_id"}, nil, + []string{"host_chain_id", "client_id", "target_chain_id", "status"}, nil, ) walletBalance = prometheus.NewDesc( walletBalanceMetricName, @@ -47,24 +49,41 @@ func (cc IBCClientsCollector) Describe(ch chan<- *prometheus.Desc) { func (cc IBCClientsCollector) Collect(ch chan<- prometheus.Metric) { log.Debug("Start collecting", zap.String("metric", clientExpiryMetricName)) - clients := ibc.GetClientsInfos(cc.Paths, cc.RPCs) - - for _, c := range clients { - ch <- prometheus.MustNewConstMetric( - clientExpiry, - prometheus.GaugeValue, - float64(c.ChainAClientExpiration.Unix()), - []string{c.ChainA.ChainID(), c.ChainA.ClientID(), c.ChainB.ChainID()}..., - ) - - ch <- prometheus.MustNewConstMetric( - clientExpiry, - prometheus.GaugeValue, - float64(c.ChainBClientExpiration.Unix()), - []string{c.ChainB.ChainID(), c.ChainB.ClientID(), c.ChainA.ChainID()}..., - ) + var wg sync.WaitGroup + + for _, p := range cc.Paths { + wg.Add(1) + + go func(path *relayer.IBCdata) { + defer wg.Done() + + ci, err := ibc.GetClientsInfo(path, cc.RPCs) + status := successStatus + + if err != nil { + status = errorStatus + + log.Error(err.Error()) + } + + ch <- prometheus.MustNewConstMetric( + clientExpiry, + prometheus.GaugeValue, + float64(ci.ChainAClientExpiration.Unix()), + []string{path.Chain1.ChainName, path.Chain1.ClientID, path.Chain2.ChainName, status}..., + ) + + ch <- prometheus.MustNewConstMetric( + clientExpiry, + prometheus.GaugeValue, + float64(ci.ChainBClientExpiration.Unix()), + []string{path.Chain2.ChainName, path.Chain2.ClientID, path.Chain1.ChainName, status}..., + ) + }(p) } + wg.Wait() + log.Debug("Stop collecting", zap.String("metric", clientExpiryMetricName)) } @@ -84,9 +103,12 @@ func (wb WalletBalanceCollector) Collect(ch chan<- prometheus.Metric) { defer wg.Done() balance := 0.0 + status := successStatus err := account.GetBalance(wb.RPCs) if err != nil { + status = errorStatus + log.Error(err.Error(), zap.Any("account", account)) } else { // Convert to a big float to get a float64 for metrics @@ -97,7 +119,7 @@ func (wb WalletBalanceCollector) Collect(ch chan<- prometheus.Metric) { walletBalance, prometheus.GaugeValue, balance, - []string{account.Address, account.ChainID, account.Denom, account.Status}..., + []string{account.Address, account.ChainID, account.Denom, status}..., ) }(a) } diff --git a/pkg/ibc/ibc.go b/pkg/ibc/ibc.go index d4ba302..51ca875 100644 --- a/pkg/ibc/ibc.go +++ b/pkg/ibc/ibc.go @@ -6,9 +6,7 @@ import ( "time" "github.com/archway-network/relayer_exporter/pkg/chain" - log "github.com/archway-network/relayer_exporter/pkg/logger" "github.com/cosmos/relayer/v2/relayer" - "github.com/google/go-cmp/cmp" ) type ClientsInfo struct { @@ -20,38 +18,6 @@ type ClientsInfo struct { ChainBClientExpiration time.Time } -func GetClientsInfos(ibcs []*relayer.IBCdata, rpcs map[string]string) []ClientsInfo { - num := len(ibcs) - - out := make(chan ClientsInfo, num) - defer close(out) - - for i := 0; i < num; i++ { - go func(i int) { - clientsInfo, err := GetClientsInfo(ibcs[i], rpcs) - if err != nil { - out <- ClientsInfo{} - - log.Error(err.Error()) - - return - } - out <- clientsInfo - }(i) - } - - clientsInfos := []ClientsInfo{} - - for i := 0; i < num; i++ { - ci := <-out - if !cmp.Equal(ci, ClientsInfo{}) { - clientsInfos = append(clientsInfos, ci) - } - } - - return clientsInfos -} - func GetClientsInfo(ibc *relayer.IBCdata, rpcs map[string]string) (ClientsInfo, error) { clientsInfo := ClientsInfo{}