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

refactor: remove dynamic labels from metrics #629

Merged
merged 1 commit into from
Aug 7, 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
9 changes: 0 additions & 9 deletions telemetry/label.go

This file was deleted.

12 changes: 4 additions & 8 deletions telemetry/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ import (

var maxFloat32, _ = big.NewInt(0).SetString(fmt.Sprintf("%.0f", math.MaxFloat32), 10)

func SetGaugeLabelsWithToken(keys []string, token string, amount *big.Int, labels ...metrics.Label) {
func SetGaugeLabelsWithDenom(keys []string, denom string, amount *big.Int, labels ...metrics.Label) {
if amount.Cmp(maxFloat32) == 1 {
return
}
amountFloat32, _ := new(big.Float).SetInt(amount).Float32()
telemetry.SetGaugeWithLabels(append(keys, token), amountFloat32,
append(labels, telemetry.NewLabel(LabelToken, token)))
}

func SetGaugeLabelsWithCoin(keys []string, coin sdk.Coin, labels ...metrics.Label) {
SetGaugeLabelsWithToken(keys, coin.Denom, coin.Amount.BigInt(), labels...)
telemetry.SetGaugeWithLabels(append(keys, denom), amountFloat32,
append(labels, telemetry.NewLabel("denom", denom)))
}

func SetGaugeLabelsWithCoins(keys []string, coins sdk.Coins, labels ...metrics.Label) {
for _, coin := range coins {
SetGaugeLabelsWithCoin(keys, coin, labels...)
SetGaugeLabelsWithDenom(keys, coin.Denom, coin.Amount.BigInt(), labels...)
}
}
14 changes: 5 additions & 9 deletions x/crosschain/keeper/bridge_call_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ func (k Keeper) BridgeCallHandler(ctx sdk.Context, msg *types.MsgBridgeCallClaim

if !ctx.IsCheckTx() {
telemetry.IncrCounterWithLabels(
[]string{types.ModuleName, types.MetricsKeyBridgeCallIn},
[]string{types.ModuleName, "bridge_call_in"},
float32(1),
[]metrics.Label{
telemetry.NewLabel(types.MetricsLabelModule, k.moduleName),
telemetry.NewLabel(fxtelemetry.LabelSender, msg.GetSender()),
telemetry.NewLabel(fxtelemetry.LabelTo, msg.GetTo()),
telemetry.NewLabel(fxtelemetry.LabelSuccess, strconv.FormatBool(err == nil)),
telemetry.NewLabel(types.MetricsLabelRefund, msg.GetRefund()),
telemetry.NewLabel(types.MetricsLabelTxOrigin, msg.GetTxOrigin()),
telemetry.NewLabel("module", k.moduleName),
telemetry.NewLabel("success", strconv.FormatBool(err == nil)),
},
)
}
Expand Down Expand Up @@ -93,9 +89,9 @@ func (k Keeper) BridgeCallTransferAndCallEvm(ctx sdk.Context, sender, refundAddr

if !ctx.IsCheckTx() {
fxtelemetry.SetGaugeLabelsWithCoins(
[]string{types.ModuleName, types.MetricsKeyBridgeCallIn},
[]string{types.ModuleName, "bridge_call_in_amount"},
coins,
telemetry.NewLabel(types.MetricsLabelModule, k.moduleName),
telemetry.NewLabel("module", k.moduleName),
)
}

Expand Down
26 changes: 11 additions & 15 deletions x/crosschain/keeper/bridge_call_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,21 @@ func (k Keeper) AddOutgoingBridgeCallWithoutBuild(ctx sdk.Context, outCall *type
))

if !ctx.IsCheckTx() {
tokenLabels := make([]metrics.Label, 0, len(outCall.Tokens))
for _, t := range outCall.Tokens {
fxtelemetry.SetGaugeLabelsWithToken(
[]string{types.ModuleName, types.MetricsKeyBridgeCallOut},
fxtelemetry.SetGaugeLabelsWithDenom(
[]string{types.ModuleName, "bridge_call_out_amount"},
t.Contract, t.Amount.BigInt(),
telemetry.NewLabel(types.MetricsLabelModule, k.moduleName),
telemetry.NewLabel("module", k.moduleName),
)
telemetry.IncrCounterWithLabels(
[]string{types.ModuleName, "bridge_call_out"},
float32(1),
[]metrics.Label{
telemetry.NewLabel("module", k.moduleName),
telemetry.NewLabel("contract", t.Contract),
},
)
tokenLabels = append(tokenLabels, telemetry.NewLabel(fxtelemetry.LabelToken, t.Contract))
}
telemetry.IncrCounterWithLabels(
[]string{types.ModuleName, types.MetricsKeyBridgeCallOut},
float32(1),
append([]metrics.Label{
telemetry.NewLabel(types.MetricsLabelModule, k.moduleName),
telemetry.NewLabel(fxtelemetry.LabelSender, outCall.Sender),
telemetry.NewLabel(types.MetricsLabelRefund, outCall.Refund),
telemetry.NewLabel(fxtelemetry.LabelTo, outCall.To),
}, tokenLabels...),
)
}

return outCall.Nonce
Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ func (s MsgServer) AddDelegate(c context.Context, msg *types.MsgAddDelegate) (*t
oracle.StartHeight = ctx.BlockHeight()
if !ctx.IsCheckTx() {
telemetry.SetGaugeWithLabels(
[]string{types.ModuleName, types.MetricsKeyOracleStatus},
[]string{types.ModuleName, "oracle_status"},
float32(0),
[]metrics.Label{
telemetry.NewLabel(types.MetricsLabelModule, s.moduleName),
telemetry.NewLabel(types.MetricsLabelAddress, oracle.OracleAddress),
telemetry.NewLabel("module", s.moduleName),
telemetry.NewLabel("address", oracle.OracleAddress),
},
)
}
Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ func (k Keeper) SlashOracle(ctx sdk.Context, oracleAddrStr string) {
}
if !ctx.IsCheckTx() {
telemetry.SetGaugeWithLabels(
[]string{types.ModuleName, types.MetricsKeyOracleStatus},
[]string{types.ModuleName, "oracle_status"},
float32(1),
[]metrics.Label{
telemetry.NewLabel(types.MetricsLabelModule, k.moduleName),
telemetry.NewLabel(types.MetricsLabelAddress, oracle.OracleAddress),
telemetry.NewLabel("module", k.moduleName),
telemetry.NewLabel("address", oracle.OracleAddress),
},
)
}
Expand Down
19 changes: 8 additions & 11 deletions x/crosschain/keeper/outgoing_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,17 @@ func (k Keeper) addToOutgoingPool(ctx sdk.Context, sender sdk.AccAddress, receiv
))

if !ctx.IsCheckTx() {
fxtelemetry.SetGaugeLabelsWithCoin(
[]string{types.ModuleName, types.MetricsKeyOutgoingTx},
amount,
telemetry.NewLabel(types.MetricsLabelModule, k.moduleName),
fxtelemetry.SetGaugeLabelsWithDenom(
[]string{types.ModuleName, "outgoing_tx_amount"},
amount.Denom, amount.Amount.BigInt(),
telemetry.NewLabel("module", k.moduleName),
)

metrics.IncrCounterWithLabels(
[]string{types.ModuleName, types.MetricsKeyOutgoingTx},
telemetry.IncrCounterWithLabels(
[]string{types.ModuleName, "outgoing_tx"},
1,
[]metrics.Label{
telemetry.NewLabel(types.MetricsLabelModule, k.moduleName),
telemetry.NewLabel(fxtelemetry.LabelSender, sender.String()),
telemetry.NewLabel(fxtelemetry.LabelReceiver, receiver),
telemetry.NewLabel(fxtelemetry.LabelToken, amount.Denom),
telemetry.NewLabel("module", k.moduleName),
telemetry.NewLabel("denom", amount.Denom),
},
)
}
Expand Down
19 changes: 19 additions & 0 deletions x/crosschain/keeper/send_to_fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"github.com/armon/go-metrics"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/ethereum/go-ethereum/common"

"github.com/functionx/fx-core/v7/contract"
fxtelemetry "github.com/functionx/fx-core/v7/telemetry"
fxtypes "github.com/functionx/fx-core/v7/types"
"github.com/functionx/fx-core/v7/x/crosschain/types"
)
Expand All @@ -26,6 +29,22 @@ func (k Keeper) SendToFxExecuted(ctx sdk.Context, claim *types.MsgSendToFxClaim)
}

coin := sdk.NewCoin(bridgeToken.Denom, claim.Amount)
if !ctx.IsCheckTx() {
defer func() {
telemetry.IncrCounterWithLabels(
[]string{types.ModuleName, "send_to_fx"},
float32(1),
[]metrics.Label{
telemetry.NewLabel("module", k.moduleName),
},
)
fxtelemetry.SetGaugeLabelsWithDenom(
[]string{types.ModuleName, "send_to_fx_amount"},
coin.Denom, coin.Amount.BigInt(),
telemetry.NewLabel("module", k.moduleName),
)
}()
}
receiveAddr, err := sdk.AccAddressFromBech32(claim.Receiver)
if err != nil {
return errorsmod.Wrap(types.ErrInvalid, "receiver address")
Expand Down
12 changes: 0 additions & 12 deletions x/crosschain/legacy/precompile_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package legacy
import (
"math/big"

"github.com/armon/go-metrics"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
)
Expand All @@ -22,16 +20,6 @@ func Fip20CrossChainEvents(ctx sdk.Context, from, token common.Address, recipien
sdk.NewAttribute(AttributeKeyTokenAddress, token.String()),
sdk.NewAttribute(AttributeKeyDenom, denom),
))

telemetry.IncrCounterWithLabels(
[]string{"relay_transfer_cross_chain"},
1,
[]metrics.Label{
telemetry.NewLabel("erc20", token.String()),
telemetry.NewLabel("denom", denom),
telemetry.NewLabel("target", target),
},
)
}

// CrossChainEvents
Expand Down
15 changes: 0 additions & 15 deletions x/crosschain/types/metrics.go

This file was deleted.

10 changes: 2 additions & 8 deletions x/migrate/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

errorsmod "cosmossdk.io/errors"
"github.com/armon/go-metrics"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -55,13 +54,8 @@ func (k Keeper) MigrateAccount(goCtx context.Context, msg *types.MsgMigrateAccou
k.SetMigrateRecord(ctx, fromAddress, toAddress)

defer func() {
telemetry.IncrCounterWithLabels(
[]string{types.ModuleName, msg.Type()},
1,
[]metrics.Label{
telemetry.NewLabel("from", msg.From),
telemetry.NewLabel("to", msg.To),
},
telemetry.IncrCounter(1,
types.ModuleName, msg.Type(),
)
}()

Expand Down