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

feat(transfer): move telemetry to internal folder #6513

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions modules/apps/transfer/internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package telemetry

import (
"github.com/hashicorp/go-metrics"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/telemetry"

"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
coretypes "github.com/cosmos/ibc-go/v8/modules/core/types"
)

func ReportTransferTelemetry(tokens types.Tokens, labels []metrics.Label) {
for _, token := range tokens {
amount, ok := sdkmath.NewIntFromString(token.Amount)
if ok && amount.IsInt64() {
telemetry.SetGaugeWithLabels(
[]string{"tx", "msg", "ibc", "transfer"},
float32(amount.Int64()),
[]metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, token.Denom.Path())},
)
}
}

telemetry.IncrCounterWithLabels(
[]string{"ibc", types.ModuleName, "send"},
1,
labels,
)
}
Comment on lines +14 to +31
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the case where amount.IsInt64() returns false.

Currently, if amount.IsInt64() returns false, the function silently skips recording telemetry for that token. It might be beneficial to log this occurrence or handle it in a way that ensures visibility of the issue.


func ReportOnRecvPacketTelemetry(transferAmount sdkmath.Int, denomPath string, labels []metrics.Label) {
if transferAmount.IsInt64() {
telemetry.SetGaugeWithLabels(
[]string{"ibc", types.ModuleName, "packet", "receive"},
float32(transferAmount.Int64()),
[]metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, denomPath)},
)
}

telemetry.IncrCounterWithLabels(
[]string{"ibc", types.ModuleName, "receive"},
1,
labels,
)
}
Comment on lines +33 to +47
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure robust error handling when transferAmount.IsInt64() returns false.

Similar to ReportTransferTelemetry, this function does not handle the case where transferAmount.IsInt64() returns false. Consider adding error logging or another form of notification to handle this scenario effectively.

60 changes: 7 additions & 53 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

metrics "github.com/hashicorp/go-metrics"
"github.com/hashicorp/go-metrics"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
Expand All @@ -13,6 +13,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v8/modules/apps/transfer/internal/events"
internaltelemetry "github.com/cosmos/ibc-go/v8/modules/apps/transfer/internal/telemetry"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Expand Down Expand Up @@ -147,24 +148,7 @@ func (k Keeper) sendTransfer(

events.EmitTransferEvent(ctx, sender.String(), receiver, tokens, memo)

defer func() {
for _, token := range tokens {
amount, ok := sdkmath.NewIntFromString(token.Amount)
if ok && amount.IsInt64() {
telemetry.SetGaugeWithLabels(
[]string{"tx", "msg", "ibc", "transfer"},
float32(amount.Int64()),
[]metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, token.Denom.Path())},
)
}
}

telemetry.IncrCounterWithLabels(
[]string{"ibc", types.ModuleName, "send"},
1,
labels,
)
}()
defer internaltelemetry.ReportTransferTelemetry(tokens, labels)

return sequence, nil
}
Expand Down Expand Up @@ -227,23 +211,8 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
}

denomPath := token.Denom.Path()
defer func() {
if transferAmount.IsInt64() {
telemetry.SetGaugeWithLabels(
[]string{"ibc", types.ModuleName, "packet", "receive"},
float32(transferAmount.Int64()),
[]metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, denomPath)},
)
}

telemetry.IncrCounterWithLabels(
[]string{"ibc", types.ModuleName, "receive"},
1,
append(
labels, telemetry.NewLabel(coretypes.LabelSource, "true"),
),
)
}()
labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "true"))
defer internaltelemetry.ReportOnRecvPacketTelemetry(transferAmount, denomPath, labels)

// Continue processing rest of tokens in packet data.
continue
Expand Down Expand Up @@ -283,23 +252,8 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
}

denomPath := token.Denom.Path()
defer func() {
if transferAmount.IsInt64() {
telemetry.SetGaugeWithLabels(
[]string{"ibc", types.ModuleName, "packet", "receive"},
float32(transferAmount.Int64()),
[]metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, denomPath)},
)
}

telemetry.IncrCounterWithLabels(
[]string{"ibc", types.ModuleName, "receive"},
1,
append(
labels, telemetry.NewLabel(coretypes.LabelSource, "false"),
),
)
}()
labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false"))
defer internaltelemetry.ReportOnRecvPacketTelemetry(transferAmount, denomPath, labels)
}

return nil
Expand Down
Loading