Skip to content

Commit

Permalink
chore: reduce noisy log output (#180)
Browse files Browse the repository at this point in the history
Too much output while running tests makes it hard to see what failed.
All logger instances in tests will now source their Debug flag from the
config object. Debug can be set via the `SIDECAR_DEBUG=true` flag when
running tests to get more verbose output.
  • Loading branch information
seanmcgary authored Jan 10, 2025
2 parents 16bf7db + de5231a commit bcb4b12
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 43 deletions.
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func StringWithDefault(value, defaultValue string) string {
}

var (
Debug = "debug"
DatabaseHost = "database.host"
DatabasePort = "database.port"
DatabaseUser = "database.user"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Layr-Labs/sidecar/pkg/utils"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"os"
"testing"
)

Expand All @@ -21,10 +22,10 @@ func setup() (
cfg := config.NewConfig()
cfg.Chain = config.Chain_Mainnet
cfg.EthereumRpcConfig.BaseUrl = "https://tame-fabled-liquid.quiknode.pro/f27d4be93b4d7de3679f5c5ae881233f857407a0"
cfg.Debug = true
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

return l, cfg, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ func (s *PostgresContractStore) InitializeCoreContracts() error {
return fmt.Errorf("Failed to create core contract: %w", err)
}
if found {
s.Logger.Sugar().Infow("Contract already exists", zap.String("contractAddress", contract.ContractAddress))
s.Logger.Sugar().Debugw("Contract already exists", zap.String("contractAddress", contract.ContractAddress))
continue
}

_, err = s.SetContractCheckedForProxy(contract.ContractAddress)
if err != nil {
return fmt.Errorf("Failed to create core contract: %w", err)
}
s.Logger.Sugar().Infow("Created core contract", zap.String("contractAddress", contract.ContractAddress))
s.Logger.Sugar().Debugw("Created core contract", zap.String("contractAddress", contract.ContractAddress))
}
for _, proxy := range coreContracts.ProxyContracts {
_, found, err := s.FindOrCreateProxyContract(
Expand All @@ -258,13 +258,13 @@ func (s *PostgresContractStore) InitializeCoreContracts() error {
return fmt.Errorf("Failed to create core proxy contract: %w", err)
}
if found {
s.Logger.Sugar().Infow("Proxy contract already exists",
s.Logger.Sugar().Debugw("Proxy contract already exists",
zap.String("contractAddress", proxy.ContractAddress),
zap.String("proxyContractAddress", proxy.ContractAddress),
)
continue
}
s.Logger.Sugar().Infow("Created proxy contract",
s.Logger.Sugar().Debugw("Created proxy contract",
zap.String("contractAddress", proxy.ContractAddress),
zap.String("proxyContractAddress", proxy.ContractAddress),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"gorm.io/gorm"
"os"
"testing"
)

Expand All @@ -20,9 +21,10 @@ func setup() (
error,
) {
cfg := config.NewConfig()
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/eigenState/avsOperators/avsOperators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/Layr-Labs/sidecar/pkg/postgres"
"github.com/Layr-Labs/sidecar/pkg/storage"
"os"
"testing"
"time"

Expand All @@ -26,10 +27,10 @@ func setup() (
) {
cfg := config.NewConfig()
cfg.Chain = config.Chain_Mainnet
cfg.Debug = false
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/Layr-Labs/sidecar/pkg/postgres"
"github.com/Layr-Labs/sidecar/pkg/storage"
"math/big"
"os"
"testing"
"time"

Expand All @@ -25,9 +26,10 @@ func setup() (
error,
) {
cfg := config.NewConfig()
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/eigenState/eigenstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eigenState

import (
"github.com/Layr-Labs/sidecar/pkg/postgres"
"os"
"testing"

"github.com/Layr-Labs/sidecar/internal/config"
Expand All @@ -23,9 +24,10 @@ func setup() (
error,
) {
cfg := config.NewConfig()
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/eigenState/rewardSubmissions/rewardSubmissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/Layr-Labs/sidecar/pkg/postgres"
"github.com/Layr-Labs/sidecar/pkg/storage"
"math/big"
"os"
"strings"
"testing"
"time"
Expand All @@ -27,8 +28,9 @@ func setup() (
) {
cfg := config.NewConfig()
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()
cfg.Debug = os.Getenv(config.Debug) == "true"

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
Expand Down
18 changes: 0 additions & 18 deletions pkg/eigenState/stakerShares/stakerShares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ func setup() (
return dbname, grm, l, cfg, nil
}

func logChanges(changes *AccumulatedStateChanges) {
// for _, change := range changes.Changes {
// // fmt.Printf("Change: %+v\n", change)
// }
}

func Test_StakerSharesState(t *testing.T) {
dbName, grm, l, cfg, err := setup()

Expand Down Expand Up @@ -112,7 +106,6 @@ func Test_StakerSharesState(t *testing.T) {
assert.NotNil(t, change)

typedChange := change.(*AccumulatedStateChanges)
logChanges(typedChange)

assert.Equal(t, 1, len(typedChange.Changes))
assert.Equal(t, "0x00105f70bf0a2dec987dbfc87a869c3090abf6a0", typedChange.Changes[0].Staker)
Expand Down Expand Up @@ -192,14 +185,9 @@ func Test_StakerSharesState(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, change)

typedChange = change.(*AccumulatedStateChanges)
logChanges(typedChange)

change, err = model.HandleStateChange(withdrawalQueuedTx)
assert.Nil(t, err)
assert.NotNil(t, change)
typedChange = change.(*AccumulatedStateChanges)
logChanges(typedChange)

err = model.CommitFinalState(transaction.BlockNumber)
assert.Nil(t, err)
Expand Down Expand Up @@ -267,14 +255,10 @@ func Test_StakerSharesState(t *testing.T) {
change, err = model.HandleStateChange(withdrawalQueued)
assert.Nil(t, err)
assert.NotNil(t, change)
typedChange = change.(*AccumulatedStateChanges)
logChanges(typedChange)

change, err = model.HandleStateChange(withdrawalMigrated)
assert.Nil(t, err)
assert.NotNil(t, change)
typedChange = change.(*AccumulatedStateChanges)
logChanges(typedChange)

err = model.CommitFinalState(transaction.BlockNumber)
assert.Nil(t, err)
Expand Down Expand Up @@ -324,8 +308,6 @@ func Test_StakerSharesState(t *testing.T) {
change, err = model.HandleStateChange(deposit2)
assert.Nil(t, err)
assert.NotNil(t, change)
typedChange = change.(*AccumulatedStateChanges)
logChanges(typedChange)

err = model.CommitFinalState(transaction.BlockNumber)
assert.Nil(t, err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/eigenState/stateManager/stateManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package stateManager
import (
"github.com/Layr-Labs/sidecar/pkg/postgres"
"github.com/Layr-Labs/sidecar/pkg/storage"
"os"
"testing"
"time"

Expand All @@ -23,9 +24,10 @@ func setup() (
error,
) {
cfg := config.NewConfig()
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/Layr-Labs/sidecar/pkg/postgres"
"github.com/Layr-Labs/sidecar/pkg/storage"
"math/big"
"os"
"testing"
"time"

Expand All @@ -25,9 +26,10 @@ func setup() (
error,
) {
cfg := config.NewConfig()
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/eventBus/eventBus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package eventBus

import (
"context"
"github.com/Layr-Labs/sidecar/internal/config"
"github.com/Layr-Labs/sidecar/internal/logger"
"github.com/Layr-Labs/sidecar/pkg/eventBus/eventBusTypes"
"github.com/stretchr/testify/assert"
"os"
"sync"
"sync/atomic"
"testing"
)

func Test_EventBus(t *testing.T) {
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
debug := os.Getenv(config.Debug) == "true"
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: debug})

eb := NewEventBus(l)

Expand Down
7 changes: 3 additions & 4 deletions pkg/indexer/restakedStrategies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"go.uber.org/zap"
"gorm.io/gorm"
"log"
"os"
"testing"
"time"
)
Expand All @@ -33,10 +34,10 @@ func setup() (
) {
cfg := config.NewConfig()
cfg.Chain = config.Chain_Holesky
cfg.Debug = false
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
Expand Down Expand Up @@ -162,8 +163,6 @@ func Test_IndexerRestakedStrategies(t *testing.T) {
query := `select * from operator_restaked_strategies`
result := grm.Raw(query).Scan(&results)

fmt.Printf("Results: %+v\n", results)

assert.Nil(t, result.Error)
assert.True(t, len(results) > 0)

Expand Down
4 changes: 3 additions & 1 deletion pkg/pipeline/pipelineIntegration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/Layr-Labs/sidecar/pkg/storage"
pgStorage "github.com/Layr-Labs/sidecar/pkg/storage/postgres"
"log"
"os"
"testing"

"github.com/Layr-Labs/sidecar/internal/config"
Expand Down Expand Up @@ -51,11 +52,12 @@ func setup(ethConfig *ethereum.EthereumClientConfig) (
)

cfg := config.NewConfig()
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.Chain = config.Chain_Mainnet
cfg.EthereumRpcConfig.BaseUrl = rpcUrl
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

metricsClients, err := metrics.InitMetricsSinksFromConfig(cfg, l)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/postgres/migrations/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (m *Migrator) Migrate(migration Migration) error {
result := m.GDb.Find(&migrationRecord, "name = ?", name).Limit(1)

if result.Error == nil && result.RowsAffected == 0 {
m.Logger.Sugar().Infof("Running migration '%s'", name)
m.Logger.Sugar().Debugf("Running migration '%s'", name)
// run migration
err := migration.Up(m.Db, m.GDb, m.globalConfig)
if err != nil {
Expand All @@ -153,7 +153,7 @@ func (m *Migrator) Migrate(migration Migration) error {
m.Logger.Sugar().Errorw(fmt.Sprintf("Failed to find migration '%s'", name), zap.Error(result.Error))
return result.Error
} else if result.RowsAffected > 0 {
m.Logger.Sugar().Infof("Migration %s already run", name)
m.Logger.Sugar().Debugf("Migration %s already run", name)
return nil
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"github.com/Layr-Labs/sidecar/internal/logger"
"github.com/Layr-Labs/sidecar/internal/tests"
"github.com/Layr-Labs/sidecar/pkg/postgres/migrations"
"os"
"testing"
)

func Test_Postgres(t *testing.T) {
cfg := config.NewConfig()
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

testDbName, err := tests.GenerateTestDbName()
Expand All @@ -18,7 +20,7 @@ func Test_Postgres(t *testing.T) {
}
cfg.DatabaseConfig.DbName = testDbName

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

pgConfig := PostgresConfigFromDbConfig(&cfg.DatabaseConfig)
pgConfig.CreateDbIfNotExists = true
Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/postgres/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/Layr-Labs/sidecar/pkg/parser"
"github.com/Layr-Labs/sidecar/pkg/postgres"
"github.com/Layr-Labs/sidecar/pkg/storage"
"os"
"strings"
"testing"
"time"
Expand All @@ -24,9 +25,10 @@ func setup() (
error,
) {
cfg := config.NewConfig()
cfg.Debug = os.Getenv(config.Debug) == "true"
cfg.DatabaseConfig = *tests.GetDbConfigFromEnv()

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})
l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
Expand Down
Loading

0 comments on commit bcb4b12

Please sign in to comment.