Skip to content

Commit

Permalink
add parameters for loki logging
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsaigle committed Dec 9, 2024
1 parent b6be4ff commit 6ae4219
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
36 changes: 34 additions & 2 deletions node/cmd/transfer-verifier/transfer-verifier-evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"fmt"
"os"

"github.com/certusone/wormhole/node/pkg/telemetry"
txverifier "github.com/certusone/wormhole/node/pkg/transfer-verifier"
"github.com/certusone/wormhole/node/pkg/version"
"github.com/certusone/wormhole/node/pkg/watchers/evm/connectors"
"github.com/ethereum/go-ethereum/common"
ipfslog "github.com/ipfs/go-log/v2"
Expand Down Expand Up @@ -36,11 +38,12 @@ func init() {
evmRpc = TransferVerifierCmdEvm.Flags().String("rpcUrl", "ws://localhost:8546", "RPC url")
evmCoreContract = TransferVerifierCmdEvm.Flags().String("coreContract", "", "core bridge address")
evmTokenBridgeContract = TransferVerifierCmdEvm.Flags().String("tokenContract", "", "token bridge")
pruneHeightDelta = TransferVerifierCmdEvm.Flags().Uint64("pruneHeightDelta", 10, "The number of blocks for which to retain transaction receipts. Defaults to 10 blocks.")

TransferVerifierCmd.MarkFlagRequired("rpcUrl")

Check failure on line 43 in node/cmd/transfer-verifier/transfer-verifier-evm.go

View workflow job for this annotation

GitHub Actions / node-lint

Error return value of `TransferVerifierCmd.MarkFlagRequired` is not checked (errcheck)
TransferVerifierCmd.MarkFlagRequired("coreContract")

Check failure on line 44 in node/cmd/transfer-verifier/transfer-verifier-evm.go

View workflow job for this annotation

GitHub Actions / node-lint

Error return value of `TransferVerifierCmd.MarkFlagRequired` is not checked (errcheck)
TransferVerifierCmd.MarkFlagRequired("tokenContract")

Check failure on line 45 in node/cmd/transfer-verifier/transfer-verifier-evm.go

View workflow job for this annotation

GitHub Actions / node-lint

Error return value of `TransferVerifierCmd.MarkFlagRequired` is not checked (errcheck)
pruneHeightDelta = TransferVerifierCmdEvm.Flags().Uint64("pruneHeightDelta", 10, "The number of blocks for which to retain transaction receipts. Defaults to 10 blocks.")

}

// Note: logger.Error should be reserved only for conditions that break the
Expand All @@ -55,8 +58,37 @@ func runTransferVerifierEvm(cmd *cobra.Command, args []string) {
}

logger := ipfslog.Logger("wormhole-transfer-verifier").Desugar()

ipfslog.SetAllLoggers(lvl)

// Setup logging to Loki if configured
if *telemetryLokiUrl != "" && *telemetryNodeName != "" {
labels := map[string]string{
// Is this required?
// "network": *p2pNetworkID,
"node_name": *telemetryNodeName,
"version": version.Version(),
}

tm, err := telemetry.NewLokiCloudLogger(
context.Background(),
logger,
*telemetryLokiUrl,
// Note: the product name parameter here is representing a per-chain configuration, so 'eth' is used
// rather than 'evm'. This allows us to distinguish this instance from other EVM chains that may be added in
// the future.
"transfer-verifier-eth",
// Private logs are not used in this code
false,
labels,
)
if err != nil {
logger.Fatal("Failed to initialize telemetry", zap.Error(err))
}

defer tm.Close()
logger = tm.WrapLogger(logger) // Wrap logger with telemetry logger
}

logger.Info("Starting EVM transfer verifier")

// Verify CLI parameters
Expand Down
29 changes: 29 additions & 0 deletions node/cmd/transfer-verifier/transfer-verifier-sui.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"strconv"
"time"

"github.com/certusone/wormhole/node/pkg/telemetry"
txverifier "github.com/certusone/wormhole/node/pkg/transfer-verifier"
"github.com/certusone/wormhole/node/pkg/version"

ipfslog "github.com/ipfs/go-log/v2"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -57,6 +59,33 @@ func runTransferVerifierSui(cmd *cobra.Command, args []string) {
logger := ipfslog.Logger("wormhole-transfer-verifier-sui").Desugar()

ipfslog.SetAllLoggers(lvl)

// Setup logging to Loki if configured
if *telemetryLokiUrl != "" && *telemetryNodeName != "" {
labels := map[string]string{
// Is this required?
// "network": *p2pNetworkID,
"node_name": *telemetryNodeName,
"version": version.Version(),
}

tm, err := telemetry.NewLokiCloudLogger(
context.Background(),
logger,
*telemetryLokiUrl,
"transfer-verifier-sui",
// Private logs are not used in this code
false,
labels,
)
if err != nil {
logger.Fatal("Failed to initialize telemetry", zap.Error(err))
}

defer tm.Close()
logger = tm.WrapLogger(logger) // Wrap logger with telemetry logger
}

logger.Info("Starting Sui transfer verifier")
logger.Debug("Sui rpc connection", zap.String("url", *suiRPC))
logger.Debug("Sui core contract", zap.String("address", *suiCoreContract))
Expand Down
15 changes: 10 additions & 5 deletions node/cmd/transfer-verifier/transfer-verifier.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package transferverifier

/*
TODOs:
*/

import (
"github.com/spf13/cobra"
)
Expand All @@ -16,6 +12,10 @@ var TransferVerifierCmd = &cobra.Command{
var (
// logLevel is a global flag that is used to set the logging level for the TransferVerifierCmd
logLevel *string
// telemetryLokiUrl is a global flag that is used to set the Loki cloud logging URL for the TransferVerifierCmd.
telemetryLokiUrl *string
// telemetryNodeName is a global flag that is used to set the node name used in telemetry for the TransferVerifierCmd.
telemetryNodeName *string
)

// init initializes the global flags and subcommands for the TransferVerifierCmd.
Expand All @@ -24,8 +24,13 @@ var (
func init() {
// Global flags
logLevel = TransferVerifierCmd.PersistentFlags().String("logLevel", "info", "Logging level (debug, info, warn, error, dpanic, panic, fatal)")
telemetryLokiUrl = TransferVerifierCmd.PersistentFlags().String("telemetryLokiUrl", "", "Loki cloud logging URL")
telemetryNodeName = TransferVerifierCmd.PersistentFlags().String("telemetryNodeName", "", "Node name used in telemetry")

// Either both loki flags should be present or neither of them.
TransferVerifierCmd.MarkFlagsRequiredTogether("telemetryLokiUrl", "telemetryNodeName")

// Subcommands
// Subcommands corresponding to chains supported by the Transfer Verifier.
TransferVerifierCmd.AddCommand(TransferVerifierCmdEvm)
TransferVerifierCmd.AddCommand(TransferVerifierCmdSui)
}
2 changes: 1 addition & 1 deletion scripts/transfer-verifier-localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RPC="${ETH_RPC_DEVNET}"

LOG_LEVEL="debug"

# Do `make node` first to compile transfer-verifier into guardiand
# Do `make node` first to compile transfer-verifier into guardiand. Note that the telemetry parameters are omitted here.
./build/bin/guardiand transfer-verifier evm \
--rpcUrl "${RPC}" \
--coreContract "${CORE_CONTRACT}" \
Expand Down

0 comments on commit 6ae4219

Please sign in to comment.