Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ibc: metrics #7441

Merged
merged 23 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d0e8dc2
ibc transfer metrics
fedekunze Oct 2, 2020
b44ad6d
ibc client metrics
fedekunze Oct 2, 2020
17bc7a8
update connection logs
fedekunze Oct 2, 2020
abc2f4a
connection metrics
fedekunze Oct 2, 2020
be7aab0
channel metrics
fedekunze Oct 2, 2020
50e495b
update logs
fedekunze Oct 2, 2020
2c66152
docs updates
fedekunze Oct 2, 2020
d42c553
Merge branch 'master' into fedekunze/ibc-metrics
fedekunze Oct 2, 2020
3559b1f
update telemetry.md
fedekunze Oct 2, 2020
0ad064d
move calls from handler
fedekunze Oct 2, 2020
2cfd6e1
Merge branch 'fedekunze/ibc-metrics' of github.com:cosmos/cosmos-sdk …
fedekunze Oct 2, 2020
582bad7
Merge branch 'master' into fedekunze/ibc-metrics
fedekunze Oct 2, 2020
8d9784c
Update x/ibc/core/04-channel/keeper/handshake.go
fedekunze Oct 5, 2020
5bea1a6
conflicts
fedekunze Oct 5, 2020
83fd274
changes from reviews
fedekunze Oct 5, 2020
264e009
Merge branch 'master' into fedekunze/ibc-metrics
cwgoes Oct 6, 2020
e6fce0e
Merge branch 'master' into fedekunze/ibc-metrics
colin-axner Oct 6, 2020
55c84af
Merge branch 'master' of github.com:cosmos/cosmos-sdk into fedekunze/…
fedekunze Oct 6, 2020
a9a7236
add chain-id metric
fedekunze Oct 6, 2020
f7f40e8
Merge branch 'fedekunze/ibc-metrics' of github.com:cosmos/cosmos-sdk …
fedekunze Oct 6, 2020
07f729c
Merge branch 'master' into fedekunze/ibc-metrics
colin-axner Oct 7, 2020
d9a0916
Merge branch 'master' of github.com:cosmos/cosmos-sdk into fedekunze/…
fedekunze Oct 8, 2020
46c854d
address @colin-axner comments
fedekunze Oct 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 63 additions & 42 deletions docs/core/telemetry.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/ibc/applications/transfer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func handleMsgTransfer(ctx sdk.Context, k keeper.Keeper, msg *types.MsgTransfer)
return nil, err
}

k.Logger(ctx).Info("IBC fungible token transfer", "token", msg.Token, "sender", msg.Sender, "receiver", msg.Receiver)
k.Logger(ctx).Info("IBC fungible token transfer", "token", msg.Token.Denom, "amount", msg.Token.Amount.String(), "sender", msg.Sender, "receiver", msg.Receiver)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
Expand Down
78 changes: 74 additions & 4 deletions x/ibc/applications/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"strings"

"github.com/armon/go-metrics"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
Expand Down Expand Up @@ -96,11 +98,17 @@ func (k Keeper) SendTransfer(
}
}

labels := []metrics.Label{
telemetry.NewLabel("chain_id", ctx.ChainID()),
}

// 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"))

// create the escrow address for the tokens
escrowAddress := types.GetEscrowAddress(sourcePort, sourceChannel)

Expand All @@ -112,6 +120,8 @@ func (k Keeper) SendTransfer(
}

} else {
labels = append(labels, telemetry.NewLabel("source", "false"))

// transfer the coins to the module account and burn them
if err := k.bankKeeper.SendCoinsFromAccountToModule(
ctx, sender, types.ModuleName, sdk.NewCoins(token),
Expand Down Expand Up @@ -144,7 +154,25 @@ func (k Keeper) SendTransfer(
timeoutTimestamp,
)

return k.channelKeeper.SendPacket(ctx, channelCap, packet)
if err := k.channelKeeper.SendPacket(ctx, channelCap, packet); err != nil {
return err
}

defer func() {
telemetry.SetGaugeWithLabels(
[]string{"tx", "msg", "ibc", "transfer"},
float32(token.Amount.Int64()),
[]metrics.Label{telemetry.NewLabel("denom", fullDenomPath)},
)

telemetry.IncrCounterWithLabels(
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
[]string{"ibc", types.ModuleName, "send"},
1,
labels,
)
}()

return nil
}

// OnRecvPacket processes a cross chain fungible token transfer. If the
Expand Down Expand Up @@ -186,7 +214,28 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t

// unescrow tokens
escrowAddress := types.GetEscrowAddress(packet.GetDestPort(), packet.GetDestChannel())
return k.bankKeeper.SendCoins(ctx, escrowAddress, receiver, sdk.NewCoins(token))
if err := k.bankKeeper.SendCoins(ctx, escrowAddress, receiver, sdk.NewCoins(token)); err != nil {
return err
}

defer func() {
telemetry.SetGaugeWithLabels(
[]string{"ibc", types.ModuleName, "packet", "receive"},
float32(data.Amount),
[]metrics.Label{telemetry.NewLabel("denom", unprefixedDenom)},
)

telemetry.IncrCounterWithLabels(
[]string{"ibc", types.ModuleName, "receive"},
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
1,
[]metrics.Label{
telemetry.NewLabel("chain_id", ctx.ChainID()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the chain ID? this would never change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 although it would be useful to retrieve the chain_id from the counterparty chain? Would that be better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea that makes a lot more sense

telemetry.NewLabel("source", "true"),
},
)
}()

return nil
}

// sender chain is the source, mint vouchers
Expand Down Expand Up @@ -223,9 +272,30 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
}

// send to receiver
return k.bankKeeper.SendCoinsFromModuleToAccount(
if err := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, types.ModuleName, receiver, sdk.NewCoins(voucher),
)
); err != nil {
return err
}

defer func() {
telemetry.SetGaugeWithLabels(
[]string{"ibc", types.ModuleName, "packet", "receive"},
float32(data.Amount),
[]metrics.Label{telemetry.NewLabel("denom", data.Denom)},
)

telemetry.IncrCounterWithLabels(
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
[]string{"ibc", types.ModuleName, "receive"},
1,
[]metrics.Label{
telemetry.NewLabel("chain_id", ctx.ChainID()),
telemetry.NewLabel("source", "true"),
},
)
}()

return nil
}

// OnAcknowledgementPacket responds to the the success or failure of a packet
Expand Down
53 changes: 48 additions & 5 deletions x/ibc/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package keeper

import (
"fmt"
"github.com/armon/go-metrics"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
Expand All @@ -26,7 +27,15 @@ func (k Keeper) CreateClient(
}

k.SetClientState(ctx, clientID, clientState)
k.Logger(ctx).Info(fmt.Sprintf("client %s created at height %d", clientID, clientState.GetLatestHeight()))
k.Logger(ctx).Info("client created at height", "client-id", clientID, "height", clientState.GetLatestHeight().String())

defer func() {
telemetry.IncrCounterWithLabels(
[]string{"ibc", "client", "create"},
1,
[]metrics.Label{telemetry.NewLabel("client-type", clientState.ClientType())},
)
}()

return nil
}
Expand Down Expand Up @@ -65,7 +74,19 @@ 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)
k.Logger(ctx).Info("client state updated", "client-id", 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"),
},
)
}()

// emitting events in the keeper emits for both begin block and handler client updates
ctx.EventManager().EmitEvent(
Expand Down Expand Up @@ -100,7 +121,18 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e

k.SetClientState(ctx, clientID, upgradedClient)

k.Logger(ctx).Info("client state upgraded", "client-id", clientID, "height", upgradedClient.GetLatestHeight())
k.Logger(ctx).Info("client state upgraded", "client-id", clientID, "height", upgradedClient.GetLatestHeight().String())

defer func() {
telemetry.IncrCounterWithLabels(
[]string{"ibc", "client", "upgrade"},
1,
[]metrics.Label{
telemetry.NewLabel("client-type", clientState.ClientType()),
telemetry.NewLabel("client-id", clientID),
},
)
}()

// emitting events in the keeper emits for client upgrades
ctx.EventManager().EmitEvent(
Expand Down Expand Up @@ -129,7 +161,18 @@ func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour ex
}

k.SetClientState(ctx, misbehaviour.GetClientID(), clientState)
k.Logger(ctx).Info(fmt.Sprintf("client %s frozen due to misbehaviour", misbehaviour.GetClientID()))
k.Logger(ctx).Info("client frozen due to misbehaviour", "client-id", 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()),
},
)
}()

return nil
}
19 changes: 16 additions & 3 deletions x/ibc/core/02-client/keeper/proposal.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package keeper

import (
"fmt"
"github.com/armon/go-metrics"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
Expand Down Expand Up @@ -34,15 +35,27 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo
k.SetClientState(ctx, p.ClientId, clientState)
k.SetClientConsensusState(ctx, p.ClientId, header.GetHeight(), consensusState)

k.Logger(ctx).Info("client updated after governance proposal passed", "client-id", p.ClientId, "height", clientState.GetLatestHeight())
k.Logger(ctx).Info("client updated after governance proposal passed", "client-id", p.ClientId, "height", clientState.GetLatestHeight().String())

defer func() {
telemetry.IncrCounterWithLabels(
[]string{"ibc", "client", "update"},
1,
[]metrics.Label{
telemetry.NewLabel("client-type", clientState.ClientType()),
telemetry.NewLabel("client-id", p.ClientId),
telemetry.NewLabel("update-type", "proposal"),
},
)
}()

// emitting events in the keeper for proposal updates to clients
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeUpdateClientProposal,
sdk.NewAttribute(types.AttributeKeyClientID, p.ClientId),
sdk.NewAttribute(types.AttributeKeyClientType, clientState.ClientType()),
sdk.NewAttribute(types.AttributeKeyConsensusHeight, fmt.Sprintf("%d", header.GetHeight())),
sdk.NewAttribute(types.AttributeKeyConsensusHeight, header.GetHeight().String()),
),
)

Expand Down
33 changes: 26 additions & 7 deletions x/ibc/core/03-connection/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package keeper

import (
"bytes"
"fmt"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
Expand All @@ -24,7 +24,7 @@ func (k Keeper) ConnOpenInit(
) error {
_, found := k.GetConnection(ctx, connectionID)
if found {
return types.ErrConnectionExists
return sdkerrors.Wrap(types.ErrConnectionExists, connectionID)
}

versions := types.GetCompatibleEncodedVersions()
Expand All @@ -44,7 +44,12 @@ func (k Keeper) ConnOpenInit(
return err
}

k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: NONE -> INIT", connectionID))
k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", "NONE", "new-state", "INIT")

defer func() {
telemetry.IncrCounter(1, "ibc", "connection", "open-init")
}()

return nil
}

Expand Down Expand Up @@ -83,7 +88,7 @@ func (k Keeper) ConnOpenTry(

expectedConsensusState, found := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight)
if !found {
return clienttypes.ErrSelfConsensusStateNotFound
return sdkerrors.Wrap(clienttypes.ErrSelfConsensusStateNotFound, consensusHeight.String())
}

if provedID != connectionID && provedID != "" {
Expand Down Expand Up @@ -154,7 +159,12 @@ func (k Keeper) ConnOpenTry(
}

k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: %s -> TRYOPEN ", connectionID, previousConnection.State))
k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", previousConnection.State.String(), "new-state", "TRYOPEN")

defer func() {
telemetry.IncrCounter(1, "ibc", "connection", "open-try")
}()

return nil
}

Expand Down Expand Up @@ -256,7 +266,11 @@ func (k Keeper) ConnOpenAck(
return err
}

k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: %s -> OPEN ", connectionID, connection.State))
k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", connection.State.String(), "new-state", "OPEN")

defer func() {
telemetry.IncrCounter(1, "ibc", "connection", "open-ack")
}()

// Update connection state to Open
connection.State = types.OPEN
Expand Down Expand Up @@ -305,6 +319,11 @@ func (k Keeper) ConnOpenConfirm(
// Update ChainB's connection to Open
connection.State = types.OPEN
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: TRYOPEN -> OPEN ", connectionID))
k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", "TRYOPEN", "new-state", "OPEN")

defer func() {
telemetry.IncrCounter(1, "ibc", "connection", "open-confirm")
}()

return nil
}
Loading