From 8f22051d48c74dd366ed90a692053faae6f27b3a Mon Sep 17 00:00:00 2001 From: Smuu <18609909+Smuu@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:34:43 +0100 Subject: [PATCH] feat: use logger object Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> --- test/e2e/benchmark/benchmark.go | 6 +-- test/e2e/benchmark/throughput.go | 6 +-- test/e2e/main.go | 2 +- test/e2e/major_upgrade_v2.go | 2 +- test/e2e/major_upgrade_v3.go | 2 +- test/e2e/minor_version_compatibility.go | 2 +- test/e2e/simple.go | 2 +- test/e2e/testnet/node.go | 16 +++--- test/e2e/testnet/testnet.go | 72 +++++++++---------------- test/e2e/testnet/txsimNode.go | 19 ++----- test/e2e/testnet/util.go | 11 ++-- 11 files changed, 55 insertions(+), 85 deletions(-) diff --git a/test/e2e/benchmark/benchmark.go b/test/e2e/benchmark/benchmark.go index 5af7b8539e..7433846fd7 100644 --- a/test/e2e/benchmark/benchmark.go +++ b/test/e2e/benchmark/benchmark.go @@ -24,7 +24,7 @@ type BenchmarkTest struct { // NewBenchmarkTest wraps around testnet.New to create a new benchmark test. // It may modify genesis consensus parameters based on manifest. -func NewBenchmarkTest(name string, manifest *Manifest) (*BenchmarkTest, error) { +func NewBenchmarkTest(logger *log.Logger, name string, manifest *Manifest) (*BenchmarkTest, error) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -42,8 +42,8 @@ func NewBenchmarkTest(name string, manifest *Manifest) (*BenchmarkTest, error) { log.Printf("Knuu initialized with scope %s", kn.Scope) - testNet, err := testnet.New(kn, testnet.Options{ - Grafana: testnet.GetGrafanaInfoFromEnvVar(), + testNet, err := testnet.New(logger, kn, testnet.Options{ + Grafana: testnet.GetGrafanaInfoFromEnvVar(logger), ChainID: manifest.ChainID, GenesisModifiers: manifest.GetGenesisModifiers(), }) diff --git a/test/e2e/benchmark/throughput.go b/test/e2e/benchmark/throughput.go index 75bf1bdf6c..e3f83d49c8 100644 --- a/test/e2e/benchmark/throughput.go +++ b/test/e2e/benchmark/throughput.go @@ -90,7 +90,7 @@ func TwoNodeSimple(logger *log.Logger) error { DisableBBR: true, } - benchTest, err := NewBenchmarkTest(testName, &manifest) + benchTest, err := NewBenchmarkTest(logger, testName, &manifest) testnet.NoError("failed to create benchmark test", err) ctx, cancel := context.WithCancel(context.Background()) @@ -113,8 +113,8 @@ func TwoNodeSimple(logger *log.Logger) error { func runBenchmarkTest(logger *log.Logger, testName string, manifest Manifest) error { logger.Println("Running", testName) manifest.ChainID = manifest.summary() - log.Println("ChainID: ", manifest.ChainID) - benchTest, err := NewBenchmarkTest(testName, &manifest) + logger.Println("ChainID: ", manifest.ChainID) + benchTest, err := NewBenchmarkTest(logger, testName, &manifest) testnet.NoError("failed to create benchmark test", err) ctx, cancel := context.WithCancel(context.Background()) diff --git a/test/e2e/main.go b/test/e2e/main.go index 768907e2cf..fda37934e2 100644 --- a/test/e2e/main.go +++ b/test/e2e/main.go @@ -56,7 +56,7 @@ func runTest(logger *log.Logger, test Test) { if err != nil { logger.Fatalf("--- ERROR %s: %v", test.Name, err) } - logger.Printf("--- ✅ PASS: %s \n\n", test.Name) + logger.Println("--- ✅ PASS: %s \n\n", test.Name) } func getTestNames(tests []Test) string { diff --git a/test/e2e/major_upgrade_v2.go b/test/e2e/major_upgrade_v2.go index 3e44eb0bc3..124089f7b5 100644 --- a/test/e2e/major_upgrade_v2.go +++ b/test/e2e/major_upgrade_v2.go @@ -35,7 +35,7 @@ func MajorUpgradeToV2(logger *log.Logger) error { logger.Printf("Knuu initialized with scope %s", kn.Scope) logger.Println("Creating testnet") - testNet, err := testnet.New(kn, testnet.Options{}) + testNet, err := testnet.New(logger, kn, testnet.Options{}) testnet.NoError("failed to create testnet", err) defer testNet.Cleanup(ctx) diff --git a/test/e2e/major_upgrade_v3.go b/test/e2e/major_upgrade_v3.go index 35cb79b045..33c145248b 100644 --- a/test/e2e/major_upgrade_v3.go +++ b/test/e2e/major_upgrade_v3.go @@ -34,7 +34,7 @@ func MajorUpgradeToV3(logger *log.Logger) error { logger.Printf("Knuu initialized with scope %s", kn.Scope) logger.Println("Creating testnet") - testNet, err := testnet.New(kn, testnet.Options{}) + testNet, err := testnet.New(logger, kn, testnet.Options{}) testnet.NoError("failed to create testnet", err) defer testNet.Cleanup(ctx) diff --git a/test/e2e/minor_version_compatibility.go b/test/e2e/minor_version_compatibility.go index bb81d5e021..b4df163317 100644 --- a/test/e2e/minor_version_compatibility.go +++ b/test/e2e/minor_version_compatibility.go @@ -50,7 +50,7 @@ func MinorVersionCompatibility(logger *log.Logger) error { kn.HandleStopSignal(ctx) logger.Printf("Knuu initialized with scope %s", kn.Scope) - testNet, err := testnet.New(kn, testnet.Options{Seed: seed}) + testNet, err := testnet.New(logger, kn, testnet.Options{Seed: seed}) testnet.NoError("failed to create testnet", err) defer testNet.Cleanup(ctx) diff --git a/test/e2e/simple.go b/test/e2e/simple.go index 8dab0278eb..c431f993ad 100644 --- a/test/e2e/simple.go +++ b/test/e2e/simple.go @@ -30,7 +30,7 @@ func E2ESimple(logger *log.Logger) error { kn.HandleStopSignal(ctx) logger.Printf("Knuu initialized with scope %s", kn.Scope) - testNet, err := testnet.New(kn, testnet.Options{}) + testNet, err := testnet.New(logger, kn, testnet.Options{}) testnet.NoError("failed to create testnet", err) defer testNet.Cleanup(ctx) diff --git a/test/e2e/testnet/node.go b/test/e2e/testnet/node.go index c186136e3e..e640fa97cb 100644 --- a/test/e2e/testnet/node.go +++ b/test/e2e/testnet/node.go @@ -4,11 +4,11 @@ package testnet import ( "context" "fmt" + "log" "os" "path/filepath" serverconfig "github.com/cosmos/cosmos-sdk/server/config" - "github.com/rs/zerolog/log" "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/p2p" @@ -55,13 +55,15 @@ type Node struct { // FIXME: This does not work currently with the reverse proxy // grpcProxyHost string traceProxyHost string + + logger *log.Logger } // PullRoundStateTraces retrieves the round state traces from a node. // It will save them to the provided path. func (n *Node) PullRoundStateTraces(path string) ([]trace.Event[schema.RoundState], error) { addr := n.AddressTracing() - log.Info().Str("Address", addr).Msg("Pulling round state traces") + n.logger.Println("Pulling round state traces", "address", addr) err := trace.GetTable(addr, schema.RoundState{}.Table(), path) if err != nil { @@ -74,7 +76,7 @@ func (n *Node) PullRoundStateTraces(path string) ([]trace.Event[schema.RoundStat // It will save them to the provided path. func (n *Node) PullBlockSummaryTraces(path string) ([]trace.Event[schema.BlockSummary], error) { addr := n.AddressTracing() - log.Info().Str("Address", addr).Msg("Pulling block summary traces") + n.logger.Println("Pulling block summary traces", "address", addr) err := trace.GetTable(addr, schema.BlockSummary{}.Table(), path) if err != nil { @@ -97,6 +99,7 @@ type Resources struct { func NewNode( ctx context.Context, + logger *log.Logger, name string, version string, startHeight int64, @@ -178,6 +181,7 @@ func NewNode( NetworkKey: networkKey, SelfDelegation: selfDelegation, sidecars: sidecars, + logger: logger, }, nil } @@ -205,9 +209,7 @@ func (n *Node) Init(ctx context.Context, genesis *types.GenesisDoc, peers []stri } defer os.RemoveAll(tmpDir) nodeDir := filepath.Join(tmpDir, n.Name) - log.Info().Str("name", n.Name). - Str("directory", nodeDir). - Msg("Creating validator's config and data directories") + n.logger.Println("Creating validator's config and data directories", "name", n.Name, "directory", nodeDir) for _, dir := range []string{ filepath.Join(nodeDir, "config"), filepath.Join(nodeDir, "data"), @@ -324,7 +326,7 @@ func (n Node) IsValidator() bool { } func (n Node) Client() (*http.HTTP, error) { - log.Debug().Str("RPC Address", n.AddressRPC()).Msg("Creating HTTP client for node") + n.logger.Println("Creating HTTP client for node", "rpc_address", n.AddressRPC()) return http.New(n.AddressRPC(), "/websocket") } diff --git a/test/e2e/testnet/testnet.go b/test/e2e/testnet/testnet.go index cada95988b..ee3af2e98f 100644 --- a/test/e2e/testnet/testnet.go +++ b/test/e2e/testnet/testnet.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "log" "os" "path/filepath" "time" @@ -16,7 +17,6 @@ import ( "github.com/celestiaorg/knuu/pkg/preloader" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/rs/zerolog/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) @@ -35,6 +35,8 @@ type Testnet struct { knuu *knuu.Knuu chainID string genesisHash string + + logger *log.Logger } type Options struct { @@ -44,7 +46,7 @@ type Options struct { GenesisModifiers []genesis.Modifier } -func New(knuu *knuu.Knuu, opts Options) (*Testnet, error) { +func New(logger *log.Logger, knuu *knuu.Knuu, opts Options) (*Testnet, error) { opts.setDefaults() return &Testnet{ seed: opts.Seed, @@ -55,6 +57,7 @@ func New(knuu *knuu.Knuu, opts Options) (*Testnet, error) { knuu: knuu, chainID: opts.ChainID, genesisHash: "", + logger: logger, }, nil } @@ -78,7 +81,7 @@ func (t *Testnet) SetConsensusMaxBlockSize(size int64) { func (t *Testnet) CreateGenesisNode(ctx context.Context, version string, selfDelegation, upgradeHeightV2 int64, resources Resources, disableBBR bool) error { signerKey := t.keygen.Generate(ed25519Type) networkKey := t.keygen.Generate(ed25519Type) - node, err := NewNode(ctx, fmt.Sprintf("val%d", len(t.nodes)), version, 0, selfDelegation, nil, signerKey, networkKey, upgradeHeightV2, resources, t.grafana, t.knuu, disableBBR) + node, err := NewNode(ctx, t.logger, fmt.Sprintf("val%d", len(t.nodes)), version, 0, selfDelegation, nil, signerKey, networkKey, upgradeHeightV2, resources, t.grafana, t.knuu, disableBBR) if err != nil { return err } @@ -111,15 +114,10 @@ func (t *Testnet) CreateTxClients(ctx context.Context, name := fmt.Sprintf("txsim%d", i) err := t.CreateTxClient(ctx, name, version, sequences, blobRange, blobPerSequence, resources, grpcEndpoint, upgradeSchedule) if err != nil { - log.Err(err).Str("name", name). - Str("grpc endpoint", grpcEndpoint). - Msg("txsim creation failed") + t.logger.Println("txsim creation failed", "name", name, "grpc_endpoint", grpcEndpoint, "error", err) return err } - log.Info(). - Str("name", name). - Str("grpc endpoint", grpcEndpoint). - Msg("txsim created") + t.logger.Println("txsim created", "name", name, "grpc_endpoint", grpcEndpoint) } return nil } @@ -190,29 +188,22 @@ func (t *Testnet) CreateTxClient( } } - txsim, err := CreateTxClient(ctx, name, version, grpcEndpoint, t.seed, blobSequences, blobRange, blobPerSequence, 1, resources, remoteRootDir, t.knuu, upgradeSchedule) + txsim, err := CreateTxClient(ctx, t.logger, name, version, grpcEndpoint, t.seed, blobSequences, blobRange, blobPerSequence, 1, resources, remoteRootDir, t.knuu, upgradeSchedule) if err != nil { - log.Err(err). - Str("name", name). - Msg("error creating txsim") + t.logger.Println("error creating txsim", "name", name, "error", err) return err } err = txsim.Instance.Build().Commit(ctx) if err != nil { - log.Err(err). - Str("name", name). - Msg("error committing txsim") + t.logger.Println("error committing txsim", "name", name, "error", err) return err } // copy over the keyring directory to the txsim instance err = txsim.Instance.Storage().AddFolder(txsimKeyringDir, remoteRootDir, "10001:10001") if err != nil { - log.Err(err). - Str("directory", txsimKeyringDir). - Str("name", name). - Msg("error adding keyring dir to txsim") + t.logger.Println("error adding keyring dir to txsim", "directory", txsimKeyringDir, "name", name, "error", err) return err } @@ -224,14 +215,10 @@ func (t *Testnet) StartTxClients(ctx context.Context) error { for _, txsim := range t.txClients { err := txsim.Instance.Execution().StartAsync(ctx) if err != nil { - log.Err(err). - Str("name", txsim.Name). - Msg("txsim failed to start") + t.logger.Println("txsim failed to start", "name", txsim.Name, "error", err) return err } - log.Info(). - Str("name", txsim.Name). - Msg("txsim started") + t.logger.Println("txsim started", "name", txsim.Name) } // wait for txsims to start for _, txsim := range t.txClients { @@ -279,17 +266,14 @@ func (t *Testnet) CreateAccount(name string, tokens int64, txsimKeyringDir strin return nil, err } - log.Info(). - Str("name", name). - Str("pk", pk.String()). - Msg("txsim account created and added to genesis") + t.logger.Println("txsim account created and added to genesis", "name", name, "pk", pk.String()) return kr, nil } func (t *Testnet) CreateNode(ctx context.Context, version string, startHeight, upgradeHeight int64, resources Resources, disableBBR bool) error { signerKey := t.keygen.Generate(ed25519Type) networkKey := t.keygen.Generate(ed25519Type) - node, err := NewNode(ctx, fmt.Sprintf("val%d", len(t.nodes)), version, startHeight, 0, nil, signerKey, networkKey, upgradeHeight, resources, t.grafana, t.knuu, disableBBR) + node, err := NewNode(ctx, t.logger, fmt.Sprintf("val%d", len(t.nodes)), version, startHeight, 0, nil, signerKey, networkKey, upgradeHeight, resources, t.grafana, t.knuu, disableBBR) if err != nil { return err } @@ -386,8 +370,7 @@ func (t *Testnet) WaitToSync(ctx context.Context) error { } for _, node := range genesisNodes { - log.Info().Str("name", node.Name).Msg( - "waiting for node to sync") + t.logger.Println("waiting for node to sync", "name", node.Name) client, err := node.Client() if err != nil { return fmt.Errorf("failed to initialize client for node %s: %w", node.Name, err) @@ -396,15 +379,12 @@ func (t *Testnet) WaitToSync(ctx context.Context) error { resp, err := client.Status(ctx) if err == nil { if resp != nil && resp.SyncInfo.LatestBlockHeight > 0 { - log.Info().Int("attempts", i).Str("name", node.Name).Int64("latest_block_height", resp.SyncInfo.LatestBlockHeight).Msg( - "node has synced") + t.logger.Println("node has synced", "name", node.Name, "attempts", i, "latest_block_height", resp.SyncInfo.LatestBlockHeight) break } - log.Info().Str("name", node.Name).Int("attempt", i).Msg( - "node status retrieved but not synced yet, waiting...") + t.logger.Println("node status retrieved but not synced yet, waiting...", "name", node.Name, "attempt", i) } else { - log.Error().Str("name", node.Name).Int("attempt", i).Err(err).Msg( - "error getting status, retrying...") + t.logger.Printf("error getting status, retrying...", "name", node.Name, "attempt", i, "error", err) } if i == 19 { return fmt.Errorf("timed out waiting for node %s to sync: %w", node.Name, err) @@ -432,17 +412,15 @@ func (t *Testnet) StartNodes(ctx context.Context) error { } } - log.Info().Msg("create endpoint proxies for genesis nodes") + t.logger.Println("create endpoint proxies for genesis nodes") // wait for instances to be running for _, node := range genesisNodes { err := node.WaitUntilStartedAndCreateProxy(ctx) if err != nil { - log.Err(err).Str("name", node.Name).Str("version", - node.Version).Msg("failed to start and create proxy") + t.logger.Println("failed to start and create proxy", "name", node.Name, "version", node.Version, "error", err) return fmt.Errorf("node %s failed to start: %w", node.Name, err) } - log.Info().Str("name", node.Name).Str("version", - node.Version).Msg("started and created proxy") + t.logger.Println("started and created proxy", "name", node.Name, "version", node.Version) } return nil } @@ -454,7 +432,7 @@ func (t *Testnet) Start(ctx context.Context) error { return err } // wait for nodes to sync - log.Info().Msg("waiting for genesis nodes to sync") + t.logger.Println("waiting for genesis nodes to sync") err = t.WaitToSync(ctx) if err != nil { return err @@ -465,7 +443,7 @@ func (t *Testnet) Start(ctx context.Context) error { func (t *Testnet) Cleanup(ctx context.Context) { if err := t.knuu.CleanUp(ctx); err != nil { - log.Err(err).Msg("failed to cleanup knuu") + t.logger.Println("failed to cleanup knuu", "error", err) } } diff --git a/test/e2e/testnet/txsimNode.go b/test/e2e/testnet/txsimNode.go index c63062598b..0402b417be 100644 --- a/test/e2e/testnet/txsimNode.go +++ b/test/e2e/testnet/txsimNode.go @@ -4,12 +4,12 @@ package testnet import ( "context" "fmt" + "log" "strings" "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/knuu/pkg/instance" "github.com/celestiaorg/knuu/pkg/knuu" - "github.com/rs/zerolog/log" ) const ( @@ -28,6 +28,7 @@ type TxSim struct { // CreateTxClient returns a new TxSim instance. func CreateTxClient( ctx context.Context, + logger *log.Logger, name string, version string, endpoint string, @@ -46,16 +47,10 @@ func CreateTxClient( return nil, err } image := txsimDockerImageName(version) - log.Info(). - Str("name", name). - Str("image", image). - Msg("setting image for tx client") + logger.Println("setting image for tx client", "name", name, "image", image) err = instance.Build().SetImage(ctx, image) if err != nil { - log.Err(err). - Str("name", name). - Str("image", image). - Msg("failed to set image for tx client") + logger.Println("failed to set image for tx client", "name", name, "image", image, "error", err) return nil, err } err = instance.Resources().SetMemory(resources.MemoryRequest, resources.MemoryLimit) @@ -89,11 +84,7 @@ func CreateTxClient( return nil, err } - log.Info(). - Str("name", name). - Str("image", image). - Str("args", strings.Join(args, " ")). - Msg("created tx client") + logger.Println("created tx client", "name", name, "image", image, "args", strings.Join(args, " ")) return &TxSim{ Name: name, diff --git a/test/e2e/testnet/util.go b/test/e2e/testnet/util.go index edf89aceda..6ed19be5e4 100644 --- a/test/e2e/testnet/util.go +++ b/test/e2e/testnet/util.go @@ -1,9 +1,8 @@ package testnet import ( + "log" "os" - - "github.com/rs/zerolog/log" ) type GrafanaInfo struct { @@ -12,17 +11,17 @@ type GrafanaInfo struct { Token string } -func GetGrafanaInfoFromEnvVar() *GrafanaInfo { - log.Info().Msg("Checking Grafana environment variables") +func GetGrafanaInfoFromEnvVar(logger *log.Logger) *GrafanaInfo { + logger.Println("Checking Grafana environment variables") if os.Getenv("GRAFANA_ENDPOINT") == "" || os.Getenv("GRAFANA_USERNAME") == "" || os.Getenv("GRAFANA_TOKEN") == "" { - log.Info().Msg("No Grafana environment variables found") + logger.Println("No Grafana environment variables found") return nil } - log.Info().Msg("Grafana environment variables found") + logger.Println("Grafana environment variables found") return &GrafanaInfo{ Endpoint: os.Getenv("GRAFANA_ENDPOINT"), Username: os.Getenv("GRAFANA_USERNAME"),