diff --git a/pkg/collector/collector.go b/pkg/collector/collector.go index 7e5c1a4..192fb78 100644 --- a/pkg/collector/collector.go +++ b/pkg/collector/collector.go @@ -3,6 +3,7 @@ package collector import ( "fmt" "math/big" + "reflect" "sync" "github.com/cosmos/relayer/v2/relayer" @@ -132,49 +133,50 @@ func (cc IBCCollector) Collect(ch chan<- prometheus.Metric) { if err != nil { status = errorStatus - fmt.Println("FOOOOBAAAAR") log.Error(err.Error()) } - for _, sp := range stuckPackets.Channels { - ch <- prometheus.MustNewConstMetric( - channelStuckPackets, - prometheus.GaugeValue, - float64(sp.StuckPackets.Total), - []string{ - sp.Source, - sp.Destination, - (*cc.RPCs)[path.Chain1.ChainName].ChainID, - (*cc.RPCs)[path.Chain2.ChainName].ChainID, - status, - }..., - ) - - ch <- prometheus.MustNewConstMetric( - channelSrcStuckPackets, - prometheus.GaugeValue, - float64(sp.StuckPackets.Source), - []string{ - sp.Source, - sp.Destination, - (*cc.RPCs)[path.Chain1.ChainName].ChainID, - (*cc.RPCs)[path.Chain2.ChainName].ChainID, - status, - }..., - ) - - ch <- prometheus.MustNewConstMetric( - channelDstStuckPackets, - prometheus.GaugeValue, - float64(sp.StuckPackets.Destination), - []string{ - sp.Source, - sp.Destination, - (*cc.RPCs)[path.Chain1.ChainName].ChainID, - (*cc.RPCs)[path.Chain2.ChainName].ChainID, - status, - }..., - ) + if !reflect.DeepEqual(stuckPackets, ibc.ChannelsInfo{}) { + for _, sp := range stuckPackets.Channels { + ch <- prometheus.MustNewConstMetric( + channelStuckPackets, + prometheus.GaugeValue, + float64(sp.StuckPackets.Total), + []string{ + sp.Source, + sp.Destination, + (*cc.RPCs)[path.Chain1.ChainName].ChainID, + (*cc.RPCs)[path.Chain2.ChainName].ChainID, + status, + }..., + ) + + ch <- prometheus.MustNewConstMetric( + channelSrcStuckPackets, + prometheus.GaugeValue, + float64(sp.StuckPackets.Source), + []string{ + sp.Source, + sp.Destination, + (*cc.RPCs)[path.Chain1.ChainName].ChainID, + (*cc.RPCs)[path.Chain2.ChainName].ChainID, + status, + }..., + ) + + ch <- prometheus.MustNewConstMetric( + channelDstStuckPackets, + prometheus.GaugeValue, + float64(sp.StuckPackets.Destination), + []string{ + sp.Source, + sp.Destination, + (*cc.RPCs)[path.Chain1.ChainName].ChainID, + (*cc.RPCs)[path.Chain2.ChainName].ChainID, + status, + }..., + ) + } } }(p) } diff --git a/pkg/ibc/ibc.go b/pkg/ibc/ibc.go index 33e43fd..5889e97 100644 --- a/pkg/ibc/ibc.go +++ b/pkg/ibc/ibc.go @@ -24,6 +24,8 @@ type ClientsInfo struct { } type ChannelsInfo struct { + ChainA *relayer.Chain + ChainB *relayer.Chain Channels []Channel } @@ -126,7 +128,14 @@ func GetChannelsInfo(ibc *relayer.IBCdata, rpcs *map[string]config.RPC) (Channel if _, _, err := relayer.QueryLatestHeights( ctx, chainA, chainB, ); err != nil { - return ChannelsInfo{}, fmt.Errorf("Error: %w for %v", err, cdA) + for _, c := range ibc.Channels { + var channel Channel + channel.Source = c.Chain1.ChannelID + channel.Destination = c.Chain2.ChannelID + channelInfo.Channels = append(channelInfo.Channels, channel) + } + + return channelInfo, fmt.Errorf("Error: %w for %v", err, cdA) } for _, c := range ibc.Channels {