Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed Jul 7, 2021
1 parent 3776793 commit 04dd6a4
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 43 deletions.
19 changes: 10 additions & 9 deletions x/ibc/applications/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -101,16 +102,16 @@ 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
// chain inside the packet data. The receiving chain will perform denom
// 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)
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"),
),
)
}()
Expand Down Expand Up @@ -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"),
),
)
}()
Expand Down
26 changes: 13 additions & 13 deletions x/ibc/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())},
)
}()

Expand Down Expand Up @@ -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"),
},
)
}()
Expand Down Expand Up @@ -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),
},
)
}()
Expand Down Expand Up @@ -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()),
},
)
}()
Expand Down
6 changes: 3 additions & 3 deletions x/ibc/core/02-client/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
)
}()
Expand Down
9 changes: 9 additions & 0 deletions x/ibc/core/02-client/types/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package types

// Prometheus metric labels.
const (
LabelClientType = "client_type"
LabelClientID = "client_id"
LabelUpdateType = "update_type"
LabelMsgType = "msg_type"
)
37 changes: 19 additions & 18 deletions x/ibc/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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),
},
)
}()
Expand Down Expand Up @@ -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"),
},
)
}()
Expand Down Expand Up @@ -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"),
},
)
}()
Expand Down Expand Up @@ -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),
},
)
}()
Expand Down
12 changes: 12 additions & 0 deletions x/ibc/core/types/metrics.go
Original file line number Diff line number Diff line change
@@ -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"
)

0 comments on commit 04dd6a4

Please sign in to comment.