Skip to content

Commit 007c680

Browse files
authored
ibc: fix metrics (#223)
1 parent 38b50b2 commit 007c680

File tree

6 files changed

+66
-43
lines changed

6 files changed

+66
-43
lines changed

modules/apps/transfer/keeper/relay.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
1414
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types"
1515
host "github.com/cosmos/ibc-go/modules/core/24-host"
16+
coretypes "github.com/cosmos/ibc-go/modules/core/types"
1617
)
1718

1819
// SendTransfer handles transfer sending logic. There are 2 possible cases:
@@ -101,16 +102,16 @@ func (k Keeper) SendTransfer(
101102
}
102103

103104
labels := []metrics.Label{
104-
telemetry.NewLabel("destination-port", destinationPort),
105-
telemetry.NewLabel("destination-channel", destinationChannel),
105+
telemetry.NewLabel(coretypes.LabelDestinationPort, destinationPort),
106+
telemetry.NewLabel(coretypes.LabelDestinationChannel, destinationChannel),
106107
}
107108

108109
// NOTE: SendTransfer simply sends the denomination as it exists on its own
109110
// chain inside the packet data. The receiving chain will perform denom
110111
// prefixing as necessary.
111112

112113
if types.SenderChainIsSource(sourcePort, sourceChannel, fullDenomPath) {
113-
labels = append(labels, telemetry.NewLabel("source", "true"))
114+
labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "true"))
114115

115116
// create the escrow address for the tokens
116117
escrowAddress := types.GetEscrowAddress(sourcePort, sourceChannel)
@@ -123,7 +124,7 @@ func (k Keeper) SendTransfer(
123124
}
124125

125126
} else {
126-
labels = append(labels, telemetry.NewLabel("source", "false"))
127+
labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false"))
127128

128129
// transfer the coins to the module account and burn them
129130
if err := k.bankKeeper.SendCoinsFromAccountToModule(
@@ -165,7 +166,7 @@ func (k Keeper) SendTransfer(
165166
telemetry.SetGaugeWithLabels(
166167
[]string{"tx", "msg", "ibc", "transfer"},
167168
float32(token.Amount.Int64()),
168-
[]metrics.Label{telemetry.NewLabel("denom", fullDenomPath)},
169+
[]metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, fullDenomPath)},
169170
)
170171

171172
telemetry.IncrCounterWithLabels(
@@ -200,8 +201,8 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
200201
}
201202

202203
labels := []metrics.Label{
203-
telemetry.NewLabel("source-port", packet.GetSourcePort()),
204-
telemetry.NewLabel("source-channel", packet.GetSourceChannel()),
204+
telemetry.NewLabel(coretypes.LabelSourcePort, packet.GetSourcePort()),
205+
telemetry.NewLabel(coretypes.LabelSourceChannel, packet.GetSourceChannel()),
205206
}
206207

207208
// This is the prefix that would have been prefixed to the denomination
@@ -244,14 +245,14 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
244245
telemetry.SetGaugeWithLabels(
245246
[]string{"ibc", types.ModuleName, "packet", "receive"},
246247
float32(data.Amount),
247-
[]metrics.Label{telemetry.NewLabel("denom", unprefixedDenom)},
248+
[]metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, unprefixedDenom)},
248249
)
249250

250251
telemetry.IncrCounterWithLabels(
251252
[]string{"ibc", types.ModuleName, "receive"},
252253
1,
253254
append(
254-
labels, telemetry.NewLabel("source", "true"),
255+
labels, telemetry.NewLabel(coretypes.LabelSource, "true"),
255256
),
256257
)
257258
}()
@@ -303,14 +304,14 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
303304
telemetry.SetGaugeWithLabels(
304305
[]string{"ibc", types.ModuleName, "packet", "receive"},
305306
float32(data.Amount),
306-
[]metrics.Label{telemetry.NewLabel("denom", data.Denom)},
307+
[]metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, data.Denom)},
307308
)
308309

309310
telemetry.IncrCounterWithLabels(
310311
[]string{"ibc", types.ModuleName, "receive"},
311312
1,
312313
append(
313-
labels, telemetry.NewLabel("source", "false"),
314+
labels, telemetry.NewLabel(coretypes.LabelSource, "false"),
314315
),
315316
)
316317
}()

modules/core/02-client/keeper/client.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (k Keeper) CreateClient(
4747
telemetry.IncrCounterWithLabels(
4848
[]string{"ibc", "client", "create"},
4949
1,
50-
[]metrics.Label{telemetry.NewLabel("client-type", clientState.ClientType())},
50+
[]metrics.Label{telemetry.NewLabel(types.LabelClientType, clientState.ClientType())},
5151
)
5252
}()
5353

@@ -112,9 +112,9 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
112112
[]string{"ibc", "client", "update"},
113113
1,
114114
[]metrics.Label{
115-
telemetry.NewLabel("client-type", clientState.ClientType()),
116-
telemetry.NewLabel("client-id", clientID),
117-
telemetry.NewLabel("update-type", "msg"),
115+
telemetry.NewLabel(types.LabelClientType, clientState.ClientType()),
116+
telemetry.NewLabel(types.LabelClientID, clientID),
117+
telemetry.NewLabel(types.LabelUpdateType, "msg"),
118118
},
119119
)
120120
}()
@@ -129,9 +129,9 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
129129
[]string{"ibc", "client", "misbehaviour"},
130130
1,
131131
[]metrics.Label{
132-
telemetry.NewLabel("client-type", clientState.ClientType()),
133-
telemetry.NewLabel("client-id", clientID),
134-
telemetry.NewLabel("msg-type", "update"),
132+
telemetry.NewLabel(types.LabelClientType, clientState.ClientType()),
133+
telemetry.NewLabel(types.LabelClientID, clientID),
134+
telemetry.NewLabel(types.LabelMsgType, "update"),
135135
},
136136
)
137137
}()
@@ -181,8 +181,8 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e
181181
[]string{"ibc", "client", "upgrade"},
182182
1,
183183
[]metrics.Label{
184-
telemetry.NewLabel("client-type", updatedClientState.ClientType()),
185-
telemetry.NewLabel("client-id", clientID),
184+
telemetry.NewLabel(types.LabelClientType, updatedClientState.ClientType()),
185+
telemetry.NewLabel(types.LabelClientID, clientID),
186186
},
187187
)
188188
}()
@@ -231,8 +231,8 @@ func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour ex
231231
[]string{"ibc", "client", "misbehaviour"},
232232
1,
233233
[]metrics.Label{
234-
telemetry.NewLabel("client-type", misbehaviour.ClientType()),
235-
telemetry.NewLabel("client-id", misbehaviour.GetClientID()),
234+
telemetry.NewLabel(types.LabelClientType, misbehaviour.ClientType()),
235+
telemetry.NewLabel(types.LabelClientID, misbehaviour.GetClientID()),
236236
},
237237
)
238238
}()

modules/core/02-client/keeper/proposal.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo
6262
[]string{"ibc", "client", "update"},
6363
1,
6464
[]metrics.Label{
65-
telemetry.NewLabel("client-type", clientState.ClientType()),
66-
telemetry.NewLabel("client-id", p.SubjectClientId),
67-
telemetry.NewLabel("update-type", "proposal"),
65+
telemetry.NewLabel(types.LabelClientType, clientState.ClientType()),
66+
telemetry.NewLabel(types.LabelClientID, p.SubjectClientId),
67+
telemetry.NewLabel(types.LabelUpdateType, "proposal"),
6868
},
6969
)
7070
}()
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package types
2+
3+
// Prometheus metric labels.
4+
const (
5+
LabelClientType = "client_type"
6+
LabelClientID = "client_id"
7+
LabelUpdateType = "update_type"
8+
LabelMsgType = "msg_type"
9+
)

modules/core/keeper/msg_server.go

+19-18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/cosmos/ibc-go/modules/core/04-channel/types"
1414
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types"
1515
porttypes "github.com/cosmos/ibc-go/modules/core/05-port/types"
16+
coretypes "github.com/cosmos/ibc-go/modules/core/types"
1617
)
1718

1819
var _ clienttypes.MsgServer = Keeper{}
@@ -518,10 +519,10 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke
518519
[]string{"tx", "msg", "ibc", channeltypes.EventTypeRecvPacket},
519520
1,
520521
[]metrics.Label{
521-
telemetry.NewLabel("source-port", msg.Packet.SourcePort),
522-
telemetry.NewLabel("source-channel", msg.Packet.SourceChannel),
523-
telemetry.NewLabel("destination-port", msg.Packet.DestinationPort),
524-
telemetry.NewLabel("destination-channel", msg.Packet.DestinationChannel),
522+
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
523+
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
524+
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
525+
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
525526
},
526527
)
527528
}()
@@ -571,11 +572,11 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c
571572
[]string{"ibc", "timeout", "packet"},
572573
1,
573574
[]metrics.Label{
574-
telemetry.NewLabel("source-port", msg.Packet.SourcePort),
575-
telemetry.NewLabel("source-channel", msg.Packet.SourceChannel),
576-
telemetry.NewLabel("destination-port", msg.Packet.DestinationPort),
577-
telemetry.NewLabel("destination-channel", msg.Packet.DestinationChannel),
578-
telemetry.NewLabel("timeout-type", "height"),
575+
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
576+
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
577+
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
578+
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
579+
telemetry.NewLabel(coretypes.LabelTimeoutType, "height"),
579580
},
580581
)
581582
}()
@@ -627,11 +628,11 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo
627628
[]string{"ibc", "timeout", "packet"},
628629
1,
629630
[]metrics.Label{
630-
telemetry.NewLabel("source-port", msg.Packet.SourcePort),
631-
telemetry.NewLabel("source-channel", msg.Packet.SourceChannel),
632-
telemetry.NewLabel("destination-port", msg.Packet.DestinationPort),
633-
telemetry.NewLabel("destination-channel", msg.Packet.DestinationChannel),
634-
telemetry.NewLabel("timeout-type", "channel-closed"),
631+
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
632+
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
633+
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
634+
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
635+
telemetry.NewLabel(coretypes.LabelTimeoutType, "channel-closed"),
635636
},
636637
)
637638
}()
@@ -676,10 +677,10 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn
676677
[]string{"tx", "msg", "ibc", channeltypes.EventTypeAcknowledgePacket},
677678
1,
678679
[]metrics.Label{
679-
telemetry.NewLabel("source-port", msg.Packet.SourcePort),
680-
telemetry.NewLabel("source-channel", msg.Packet.SourceChannel),
681-
telemetry.NewLabel("destination-port", msg.Packet.DestinationPort),
682-
telemetry.NewLabel("destination-channel", msg.Packet.DestinationChannel),
680+
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
681+
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
682+
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
683+
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
683684
},
684685
)
685686
}()

modules/core/types/metrics.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package types
2+
3+
// Prometheus metric labels.
4+
const (
5+
LabelSourcePort = "source_port"
6+
LabelSourceChannel = "source_channel"
7+
LabelDestinationPort = "destination_port"
8+
LabelDestinationChannel = "destination_channel"
9+
LabelTimeoutType = "timeout_type"
10+
LabelDenom = "denom"
11+
LabelSource = "source"
12+
)

0 commit comments

Comments
 (0)