From 04dd6a45e5d18953b5a436715efba2cac5c6d8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:50:32 +0200 Subject: [PATCH 1/3] backport https://github.com/cosmos/ibc-go/pull/223 --- x/ibc/applications/transfer/keeper/relay.go | 19 ++++++----- x/ibc/core/02-client/keeper/client.go | 26 +++++++-------- x/ibc/core/02-client/keeper/proposal.go | 6 ++-- x/ibc/core/02-client/types/metrics.go | 9 +++++ x/ibc/core/keeper/msg_server.go | 37 +++++++++++---------- x/ibc/core/types/metrics.go | 12 +++++++ 6 files changed, 66 insertions(+), 43 deletions(-) create mode 100644 x/ibc/core/02-client/types/metrics.go create mode 100644 x/ibc/core/types/metrics.go diff --git a/x/ibc/applications/transfer/keeper/relay.go b/x/ibc/applications/transfer/keeper/relay.go index 4889014a40af..58e140bf8075 100644 --- a/x/ibc/applications/transfer/keeper/relay.go +++ b/x/ibc/applications/transfer/keeper/relay.go @@ -13,6 +13,7 @@ import ( clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" host "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host" + coretypes "github.com/cosmos/cosmos-sdk/x/ibc/core/types" ) // SendTransfer handles transfer sending logic. There are 2 possible cases: @@ -101,8 +102,8 @@ func (k Keeper) SendTransfer( } labels := []metrics.Label{ - telemetry.NewLabel("destination-port", destinationPort), - telemetry.NewLabel("destination-channel", destinationChannel), + telemetry.NewLabel(coretypes.LabelDestinationPort, destinationPort), + telemetry.NewLabel(coretypes.LabelDestinationChannel, destinationChannel), } // NOTE: SendTransfer simply sends the denomination as it exists on its own @@ -110,7 +111,7 @@ func (k Keeper) SendTransfer( // prefixing as necessary. if types.SenderChainIsSource(sourcePort, sourceChannel, fullDenomPath) { - labels = append(labels, telemetry.NewLabel("source", "true")) + labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "true")) // create the escrow address for the tokens escrowAddress := types.GetEscrowAddress(sourcePort, sourceChannel) @@ -123,7 +124,7 @@ func (k Keeper) SendTransfer( } } else { - labels = append(labels, telemetry.NewLabel("source", "false")) + labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false")) // transfer the coins to the module account and burn them if err := k.bankKeeper.SendCoinsFromAccountToModule( @@ -165,7 +166,7 @@ func (k Keeper) SendTransfer( telemetry.SetGaugeWithLabels( []string{"tx", "msg", "ibc", "transfer"}, float32(token.Amount.Int64()), - []metrics.Label{telemetry.NewLabel("denom", fullDenomPath)}, + []metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, fullDenomPath)}, ) telemetry.IncrCounterWithLabels( @@ -244,14 +245,14 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t telemetry.SetGaugeWithLabels( []string{"ibc", types.ModuleName, "packet", "receive"}, float32(data.Amount), - []metrics.Label{telemetry.NewLabel("denom", unprefixedDenom)}, + []metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, unprefixedDenom)}, ) telemetry.IncrCounterWithLabels( []string{"ibc", types.ModuleName, "receive"}, 1, append( - labels, telemetry.NewLabel("source", "true"), + labels, telemetry.NewLabel(coretypes.LabelSource, "true"), ), ) }() @@ -303,14 +304,14 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t telemetry.SetGaugeWithLabels( []string{"ibc", types.ModuleName, "packet", "receive"}, float32(data.Amount), - []metrics.Label{telemetry.NewLabel("denom", data.Denom)}, + []metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, data.Denom)}, ) telemetry.IncrCounterWithLabels( []string{"ibc", types.ModuleName, "receive"}, 1, append( - labels, telemetry.NewLabel("source", "false"), + labels, telemetry.NewLabel(coretypes.LabelSource, "false"), ), ) }() diff --git a/x/ibc/core/02-client/keeper/client.go b/x/ibc/core/02-client/keeper/client.go index e822402bfb3e..9b0cc3fc54e0 100644 --- a/x/ibc/core/02-client/keeper/client.go +++ b/x/ibc/core/02-client/keeper/client.go @@ -28,7 +28,7 @@ func (k Keeper) CreateClient( clientID := k.GenerateClientIdentifier(ctx, clientState.ClientType()) k.SetClientState(ctx, clientID, clientState) - k.Logger(ctx).Info("client created at height", "client-id", clientID, "height", clientState.GetLatestHeight().String()) + k.Logger(ctx).Info("client created at height", types.LabelClientID, clientID, "height", clientState.GetLatestHeight().String()) // verifies initial consensus state against client state and initializes client store with any client-specific metadata // e.g. set ProcessedTime in Tendermint clients @@ -41,13 +41,13 @@ func (k Keeper) CreateClient( k.SetClientConsensusState(ctx, clientID, clientState.GetLatestHeight(), consensusState) } - k.Logger(ctx).Info("client created at height", "client-id", clientID, "height", clientState.GetLatestHeight().String()) + k.Logger(ctx).Info("client created at height", types.LabelClientID, clientID, "height", clientState.GetLatestHeight().String()) defer func() { telemetry.IncrCounterWithLabels( []string{"ibc", "client", "create"}, 1, - []metrics.Label{telemetry.NewLabel("client-type", clientState.ClientType())}, + []metrics.Label{telemetry.NewLabel(types.LabelClientType, clientState.ClientType())}, ) }() @@ -83,16 +83,16 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H consensusHeight = types.GetSelfHeight(ctx) } - k.Logger(ctx).Info("client state updated", "client-id", clientID, "height", consensusHeight.String()) + k.Logger(ctx).Info("client state updated", types.LabelClientID, clientID, "height", consensusHeight.String()) defer func() { telemetry.IncrCounterWithLabels( []string{"ibc", "client", "update"}, 1, []metrics.Label{ - telemetry.NewLabel("client-type", clientState.ClientType()), - telemetry.NewLabel("client-id", clientID), - telemetry.NewLabel("update-type", "msg"), + telemetry.NewLabel(types.LabelClientType, clientState.ClientType()), + telemetry.NewLabel(types.LabelClientID, clientID), + telemetry.NewLabel(types.LabelUpdateType, "msg"), }, ) }() @@ -144,15 +144,15 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e k.SetClientState(ctx, clientID, updatedClientState) k.SetClientConsensusState(ctx, clientID, updatedClientState.GetLatestHeight(), updatedConsState) - k.Logger(ctx).Info("client state upgraded", "client-id", clientID, "height", updatedClientState.GetLatestHeight().String()) + k.Logger(ctx).Info("client state upgraded", types.LabelClientID, clientID, "height", updatedClientState.GetLatestHeight().String()) defer func() { telemetry.IncrCounterWithLabels( []string{"ibc", "client", "upgrade"}, 1, []metrics.Label{ - telemetry.NewLabel("client-type", updatedClientState.ClientType()), - telemetry.NewLabel("client-id", clientID), + telemetry.NewLabel(types.LabelClientType, updatedClientState.ClientType()), + telemetry.NewLabel(types.LabelClientID, clientID), }, ) }() @@ -188,15 +188,15 @@ func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour ex } k.SetClientState(ctx, misbehaviour.GetClientID(), clientState) - k.Logger(ctx).Info("client frozen due to misbehaviour", "client-id", misbehaviour.GetClientID(), "height", misbehaviour.GetHeight().String()) + k.Logger(ctx).Info("client frozen due to misbehaviour", types.LabelClientID, misbehaviour.GetClientID(), "height", misbehaviour.GetHeight().String()) defer func() { telemetry.IncrCounterWithLabels( []string{"ibc", "client", "misbehaviour"}, 1, []metrics.Label{ - telemetry.NewLabel("client-type", misbehaviour.ClientType()), - telemetry.NewLabel("client-id", misbehaviour.GetClientID()), + telemetry.NewLabel(types.LabelClientType, misbehaviour.ClientType()), + telemetry.NewLabel(types.LabelClientID, misbehaviour.GetClientID()), }, ) }() diff --git a/x/ibc/core/02-client/keeper/proposal.go b/x/ibc/core/02-client/keeper/proposal.go index 6b17278e09dd..17244562aed8 100644 --- a/x/ibc/core/02-client/keeper/proposal.go +++ b/x/ibc/core/02-client/keeper/proposal.go @@ -42,9 +42,9 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo []string{"ibc", "client", "update"}, 1, []metrics.Label{ - telemetry.NewLabel("client-type", clientState.ClientType()), - telemetry.NewLabel("client-id", p.ClientId), - telemetry.NewLabel("update-type", "proposal"), + telemetry.NewLabel(types.LabelClientType, clientState.ClientType()), + telemetry.NewLabel(types.LabelClientID, p.ClientId), + telemetry.NewLabel(types.LabelUpdateType, "proposal"), }, ) }() diff --git a/x/ibc/core/02-client/types/metrics.go b/x/ibc/core/02-client/types/metrics.go new file mode 100644 index 000000000000..879e79a40d13 --- /dev/null +++ b/x/ibc/core/02-client/types/metrics.go @@ -0,0 +1,9 @@ +package types + +// Prometheus metric labels. +const ( + LabelClientType = "client_type" + LabelClientID = "client_id" + LabelUpdateType = "update_type" + LabelMsgType = "msg_type" +) diff --git a/x/ibc/core/keeper/msg_server.go b/x/ibc/core/keeper/msg_server.go index dcddcaed16d4..7a65b2a1fd77 100644 --- a/x/ibc/core/keeper/msg_server.go +++ b/x/ibc/core/keeper/msg_server.go @@ -13,6 +13,7 @@ import ( channel "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" porttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/05-port/types" + coretypes "github.com/cosmos/cosmos-sdk/x/ibc/core/types" ) var _ clienttypes.MsgServer = Keeper{} @@ -462,10 +463,10 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke []string{"tx", "msg", "ibc", msg.Type()}, 1, []metrics.Label{ - telemetry.NewLabel("source-port", msg.Packet.SourcePort), - telemetry.NewLabel("source-channel", msg.Packet.SourceChannel), - telemetry.NewLabel("destination-port", msg.Packet.DestinationPort), - telemetry.NewLabel("destination-channel", msg.Packet.DestinationChannel), + telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort), + telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel), + telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort), + telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel), }, ) }() @@ -509,11 +510,11 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c []string{"ibc", "timeout", "packet"}, 1, []metrics.Label{ - telemetry.NewLabel("source-port", msg.Packet.SourcePort), - telemetry.NewLabel("source-channel", msg.Packet.SourceChannel), - telemetry.NewLabel("destination-port", msg.Packet.DestinationPort), - telemetry.NewLabel("destination-channel", msg.Packet.DestinationChannel), - telemetry.NewLabel("timeout-type", "height"), + telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort), + telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel), + telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort), + telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel), + telemetry.NewLabel(coretypes.LabelTimeoutType, "height"), }, ) }() @@ -560,11 +561,11 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo []string{"ibc", "timeout", "packet"}, 1, []metrics.Label{ - telemetry.NewLabel("source-port", msg.Packet.SourcePort), - telemetry.NewLabel("source-channel", msg.Packet.SourceChannel), - telemetry.NewLabel("destination-port", msg.Packet.DestinationPort), - telemetry.NewLabel("destination-channel", msg.Packet.DestinationChannel), - telemetry.NewLabel("timeout-type", "channel-closed"), + telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort), + telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel), + telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort), + telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel), + telemetry.NewLabel(coretypes.LabelTimeoutType, "channel-closed"), }, ) }() @@ -604,10 +605,10 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn []string{"tx", "msg", "ibc", msg.Type()}, 1, []metrics.Label{ - telemetry.NewLabel("source-port", msg.Packet.SourcePort), - telemetry.NewLabel("source-channel", msg.Packet.SourceChannel), - telemetry.NewLabel("destination-port", msg.Packet.DestinationPort), - telemetry.NewLabel("destination-channel", msg.Packet.DestinationChannel), + telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort), + telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel), + telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort), + telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel), }, ) }() diff --git a/x/ibc/core/types/metrics.go b/x/ibc/core/types/metrics.go new file mode 100644 index 000000000000..9fcd348a7d6e --- /dev/null +++ b/x/ibc/core/types/metrics.go @@ -0,0 +1,12 @@ +package types + +// Prometheus metric labels. +const ( + LabelSourcePort = "source_port" + LabelSourceChannel = "source_channel" + LabelDestinationPort = "destination_port" + LabelDestinationChannel = "destination_channel" + LabelTimeoutType = "timeout_type" + LabelDenom = "denom" + LabelSource = "source" +) From dd1c31e82e6c0b1d75ae95ebef13c02fdfd3f3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:53:21 +0200 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8be9cfb3c11..c16cbdbef462 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* [\#9645](https://github.com/cosmos/cosmos-sdk/pull/9645) Use correct Prometheus format for metric labels. * [\#9299](https://github.com/cosmos/cosmos-sdk/pull/9299) Fix `[appd] keys parse cosmos1...` freezing. ## [v0.42.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.42.6) - 2021-06-18 From 99ba7158dd4e71908a192f40d4f187ea5b71b119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:59:33 +0200 Subject: [PATCH 3/3] fix unnecessary changes --- x/ibc/applications/transfer/keeper/relay.go | 4 ++-- x/ibc/core/02-client/keeper/client.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x/ibc/applications/transfer/keeper/relay.go b/x/ibc/applications/transfer/keeper/relay.go index 58e140bf8075..cbe4a0749b0f 100644 --- a/x/ibc/applications/transfer/keeper/relay.go +++ b/x/ibc/applications/transfer/keeper/relay.go @@ -201,8 +201,8 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t } labels := []metrics.Label{ - telemetry.NewLabel("source-port", packet.GetSourcePort()), - telemetry.NewLabel("source-channel", packet.GetSourceChannel()), + telemetry.NewLabel(coretypes.LabelSourcePort, packet.GetSourcePort()), + telemetry.NewLabel(coretypes.LabelSourceChannel, packet.GetSourceChannel()), } // This is the prefix that would have been prefixed to the denomination diff --git a/x/ibc/core/02-client/keeper/client.go b/x/ibc/core/02-client/keeper/client.go index 9b0cc3fc54e0..b4ca97f81bcd 100644 --- a/x/ibc/core/02-client/keeper/client.go +++ b/x/ibc/core/02-client/keeper/client.go @@ -28,7 +28,7 @@ func (k Keeper) CreateClient( clientID := k.GenerateClientIdentifier(ctx, clientState.ClientType()) k.SetClientState(ctx, clientID, clientState) - k.Logger(ctx).Info("client created at height", types.LabelClientID, clientID, "height", clientState.GetLatestHeight().String()) + k.Logger(ctx).Info("client created at height", "client-id", clientID, "height", clientState.GetLatestHeight().String()) // verifies initial consensus state against client state and initializes client store with any client-specific metadata // e.g. set ProcessedTime in Tendermint clients @@ -41,7 +41,7 @@ func (k Keeper) CreateClient( k.SetClientConsensusState(ctx, clientID, clientState.GetLatestHeight(), consensusState) } - k.Logger(ctx).Info("client created at height", types.LabelClientID, clientID, "height", clientState.GetLatestHeight().String()) + k.Logger(ctx).Info("client created at height", "client-id", clientID, "height", clientState.GetLatestHeight().String()) defer func() { telemetry.IncrCounterWithLabels( @@ -83,7 +83,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H consensusHeight = types.GetSelfHeight(ctx) } - k.Logger(ctx).Info("client state updated", types.LabelClientID, clientID, "height", consensusHeight.String()) + k.Logger(ctx).Info("client state updated", "client-id", clientID, "height", consensusHeight.String()) defer func() { telemetry.IncrCounterWithLabels( @@ -144,7 +144,7 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e k.SetClientState(ctx, clientID, updatedClientState) k.SetClientConsensusState(ctx, clientID, updatedClientState.GetLatestHeight(), updatedConsState) - k.Logger(ctx).Info("client state upgraded", types.LabelClientID, clientID, "height", updatedClientState.GetLatestHeight().String()) + k.Logger(ctx).Info("client state upgraded", "client-id", clientID, "height", updatedClientState.GetLatestHeight().String()) defer func() { telemetry.IncrCounterWithLabels( @@ -188,7 +188,7 @@ func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour ex } k.SetClientState(ctx, misbehaviour.GetClientID(), clientState) - k.Logger(ctx).Info("client frozen due to misbehaviour", types.LabelClientID, misbehaviour.GetClientID(), "height", misbehaviour.GetHeight().String()) + k.Logger(ctx).Info("client frozen due to misbehaviour", "client-id", misbehaviour.GetClientID(), "height", misbehaviour.GetHeight().String()) defer func() { telemetry.IncrCounterWithLabels(