Some checks failed
CodeQL / Analyze (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Has been cancelled
71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
package telemetry
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/go-metrics"
|
|
|
|
sdkmath "cosmossdk.io/math"
|
|
|
|
"git.cw.tr/mukan-network/mukan-sdk/telemetry"
|
|
|
|
"git.cw.tr/mukan-network/mukan-ibc/modules/apps/transfer/types"
|
|
coremetrics "git.cw.tr/mukan-network/mukan-ibc/modules/core/metrics"
|
|
)
|
|
|
|
func ReportTransfer(sourcePort, sourceChannel, destinationPort, destinationChannel string, token types.Token) {
|
|
labels := []metrics.Label{
|
|
telemetry.NewLabel(coremetrics.LabelDestinationPort, destinationPort),
|
|
telemetry.NewLabel(coremetrics.LabelDestinationChannel, destinationChannel),
|
|
}
|
|
|
|
amount, ok := sdkmath.NewIntFromString(token.Amount)
|
|
if ok && amount.IsInt64() {
|
|
telemetry.SetGaugeWithLabels(
|
|
[]string{"tx", "msg", "ibc", "transfer"},
|
|
float32(amount.Int64()),
|
|
[]metrics.Label{telemetry.NewLabel(coremetrics.LabelDenom, token.Denom.Path())},
|
|
)
|
|
}
|
|
|
|
labels = append(labels, telemetry.NewLabel(coremetrics.LabelSource, fmt.Sprintf("%t", !token.Denom.HasPrefix(sourcePort, sourceChannel))))
|
|
|
|
telemetry.IncrCounterWithLabels(
|
|
[]string{"ibc", types.ModuleName, "send"},
|
|
1,
|
|
labels,
|
|
)
|
|
}
|
|
|
|
func ReportOnRecvPacket(sourcePort, sourceChannel, destinationPort, destinationChannel string, token types.Token) {
|
|
labels := []metrics.Label{
|
|
telemetry.NewLabel(coremetrics.LabelSourcePort, sourcePort),
|
|
telemetry.NewLabel(coremetrics.LabelSourceChannel, sourceChannel),
|
|
}
|
|
|
|
// Modify trace as Recv does.
|
|
if token.Denom.HasPrefix(sourcePort, sourceChannel) {
|
|
token.Denom.Trace = token.Denom.Trace[1:]
|
|
} else {
|
|
trace := []types.Hop{types.NewHop(destinationPort, destinationChannel)}
|
|
token.Denom.Trace = append(trace, token.Denom.Trace...)
|
|
}
|
|
|
|
// Transfer amount has already been parsed in caller.
|
|
transferAmount, ok := sdkmath.NewIntFromString(token.Amount)
|
|
if ok && transferAmount.IsInt64() {
|
|
telemetry.SetGaugeWithLabels(
|
|
[]string{"ibc", types.ModuleName, "packet", "receive"},
|
|
float32(transferAmount.Int64()),
|
|
[]metrics.Label{telemetry.NewLabel(coremetrics.LabelDenom, token.Denom.Path())},
|
|
)
|
|
}
|
|
|
|
labels = append(labels, telemetry.NewLabel(coremetrics.LabelSource, fmt.Sprintf("%t", token.Denom.HasPrefix(sourcePort, sourceChannel))))
|
|
|
|
telemetry.IncrCounterWithLabels(
|
|
[]string{"ibc", types.ModuleName, "receive"},
|
|
1,
|
|
labels,
|
|
)
|
|
}
|