diff --git a/pkg/collector/collector.go b/pkg/collector/collector.go index 192fb78..0a8288b 100644 --- a/pkg/collector/collector.go +++ b/pkg/collector/collector.go @@ -16,13 +16,11 @@ import ( ) const ( - successStatus = "success" - errorStatus = "error" - clientExpiryMetricName = "cosmos_ibc_client_expiry" - walletBalanceMetricName = "cosmos_wallet_balance" - channelStuckPacketsMetricName = "cosmos_ibc_stuck_packets_total" - channelSrcStuckPacketsMetricName = "cosmos_ibc_stuck_packets_src" - channelDstStuckPacketsMetricName = "cosmos_ibc_stuck_packets_dst" + successStatus = "success" + errorStatus = "error" + clientExpiryMetricName = "cosmos_ibc_client_expiry" + walletBalanceMetricName = "cosmos_wallet_balance" + channelStuckPacketsMetricName = "cosmos_ibc_stuck_packets" ) var ( @@ -43,30 +41,6 @@ var ( }, nil, ) - channelSrcStuckPackets = prometheus.NewDesc( - channelSrcStuckPacketsMetricName, - "Returns source stuck packets for a channel.", - []string{ - "src_channel_id", - "dst_channel_id", - "src_chain_id", - "dst_chain_id", - "status", - }, - nil, - ) - channelDstStuckPackets = prometheus.NewDesc( - channelDstStuckPacketsMetricName, - "Returns destination stuck packets for a channel.", - []string{ - "src_channel_id", - "dst_channel_id", - "src_chain_id", - "dst_chain_id", - "status", - }, - nil, - ) walletBalance = prometheus.NewDesc( walletBalanceMetricName, "Returns wallet balance for an address on a chain.", @@ -141,19 +115,6 @@ func (cc IBCCollector) Collect(ch chan<- prometheus.Metric) { 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, @@ -165,14 +126,14 @@ func (cc IBCCollector) Collect(ch chan<- prometheus.Metric) { ) ch <- prometheus.MustNewConstMetric( - channelDstStuckPackets, + channelStuckPackets, prometheus.GaugeValue, float64(sp.StuckPackets.Destination), []string{ - sp.Source, sp.Destination, - (*cc.RPCs)[path.Chain1.ChainName].ChainID, + sp.Source, (*cc.RPCs)[path.Chain2.ChainName].ChainID, + (*cc.RPCs)[path.Chain1.ChainName].ChainID, status, }..., ) diff --git a/pkg/ibc/ibc.go b/pkg/ibc/ibc.go index 5889e97..b287c33 100644 --- a/pkg/ibc/ibc.go +++ b/pkg/ibc/ibc.go @@ -24,18 +24,18 @@ type ClientsInfo struct { } type ChannelsInfo struct { - ChainA *relayer.Chain - ChainB *relayer.Chain Channels []Channel } type Channel struct { - Source string - Destination string - StuckPackets struct { + Source string + Destination string + SourcePort string + DestinationPort string + Ordering string + StuckPackets struct { Source int Destination int - Total int } } @@ -95,8 +95,19 @@ func GetChannelsInfo(ibc *relayer.IBCdata, rpcs *map[string]config.RPC) (Channel ctx := context.Background() channelInfo := ChannelsInfo{} + // Init channel data + for _, c := range ibc.Channels { + var channel Channel + channel.Source = c.Chain1.ChannelID + channel.Destination = c.Chain2.ChannelID + channel.SourcePort = c.Chain1.PortID + channel.DestinationPort = c.Chain2.PortID + channel.Ordering = c.Ordering + channelInfo.Channels = append(channelInfo.Channels, channel) + } + if (*rpcs)[ibc.Chain1.ChainName].ChainID == "" || (*rpcs)[ibc.Chain2.ChainName].ChainID == "" { - return ChannelsInfo{}, fmt.Errorf( + return channelInfo, fmt.Errorf( "Error: RPC data is missing, cannot retrieve channel data: %v", ibc.Channels, ) @@ -128,24 +139,12 @@ func GetChannelsInfo(ibc *relayer.IBCdata, rpcs *map[string]config.RPC) (Channel if _, _, err := relayer.QueryLatestHeights( ctx, chainA, chainB, ); err != nil { - 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 { + for i, c := range channelInfo.Channels { var order chantypes.Order - var channel Channel - - channel.Source = c.Chain1.ChannelID - channel.Destination = c.Chain2.ChannelID - switch c.Ordering { case "none": order = chantypes.NONE @@ -159,20 +158,17 @@ func GetChannelsInfo(ibc *relayer.IBCdata, rpcs *map[string]config.RPC) (Channel State: stateOpen, Ordering: order, Counterparty: chantypes.Counterparty{ - PortId: c.Chain2.PortID, - ChannelId: c.Chain2.ChannelID, + PortId: c.DestinationPort, + ChannelId: c.Destination, }, - PortId: c.Chain1.PortID, - ChannelId: c.Chain2.ChannelID, + PortId: c.SourcePort, + ChannelId: c.Source, } unrelayedSequences := relayer.UnrelayedSequences(ctx, chainA, chainB, &ch) - channel.StuckPackets.Total += len(unrelayedSequences.Src) + len(unrelayedSequences.Dst) - channel.StuckPackets.Source += len(unrelayedSequences.Src) - channel.StuckPackets.Destination += len(unrelayedSequences.Dst) - - channelInfo.Channels = append(channelInfo.Channels, channel) + channelInfo.Channels[i].StuckPackets.Source += len(unrelayedSequences.Src) + channelInfo.Channels[i].StuckPackets.Destination += len(unrelayedSequences.Dst) } return channelInfo, nil