Skip to content

Commit

Permalink
Added LogLevel endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
otoumas committed Oct 7, 2022
1 parent f67f9c7 commit 5ef4283
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 127 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -40,20 +40,20 @@ build-release:
run-mainnet-online:
docker container rm rosetta-zen-mainnet-online || true
docker run --rm -v "${PWD}/zen-data:/data" ubuntu:20.04 bash -c 'chown -R nobody:nogroup /data';
docker run -d --name=rosetta-zen-mainnet-online --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/zen-data:/data" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -e "LOGLEVEL=DEBUG" -p 8080:8080 -p 9033:9033 rosetta-zen:latest;
docker run -d --name=rosetta-zen-mainnet-online --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/zen-data:/data" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 -p 9033:9033 rosetta-zen:latest;

run-mainnet-offline:
docker container rm rosetta-zen-mainnet-offline || true
docker run -d --name=rosetta-zen-mainnet-offline -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -e "LOGLEVEL=DEBUG" -p 8081:8081 rosetta-zen:latest
docker run -d --name=rosetta-zen-mainnet-offline -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -p 8081:8081 rosetta-zen:latest

run-testnet-online:
docker container rm rosetta-zen-testnet-online || true
docker run --rm -v "${PWD}/zen-data:/data" ubuntu:20.04 bash -c 'chown -R nobody:nogroup /data';
docker run -d --name=rosetta-zen-testnet-online --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/zen-data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -e "LOGLEVEL=DEBUG" -p 8080:8080 -p 19033:19033 -p 18231:18231 rosetta-zen:latest;
docker run -d --name=rosetta-zen-testnet-online --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/zen-data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 -p 19033:19033 -p 18231:18231 rosetta-zen:latest;

run-testnet-offline:
docker container rm rosetta-zen-testnet-offline || true
docker run -d --name=rosetta-zen-testnet-offline -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -e "LOGLEVEL=DEBUG" -p 8081:8081 rosetta-zen:latest
docker run -d --name=rosetta-zen-testnet-offline -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -p 8081:8081 rosetta-zen:latest

stop-mainnet-online:
docker container stop rosetta-zen-mainnet-online
Expand Down
12 changes: 0 additions & 12 deletions configuration/configuration.go
Expand Up @@ -107,11 +107,6 @@ const (
// read to determine the port for the Rosetta
// implementation.
PortEnv = "PORT"

// LogLevel is the environment variable
// read to determine if the log level for the Rosetta
// implementation must be set to debug.
LogLevel = "LOGLEVEL"
)

// PruningConfiguration is the configuration to
Expand All @@ -137,7 +132,6 @@ type Configuration struct {
ZendPath string
ZendVersion string
Compressors []*encoder.CompressorEntry
LogLevelDebug bool
}

// LoadConfiguration attempts to create a new Configuration
Expand Down Expand Up @@ -238,12 +232,6 @@ func LoadConfiguration(baseDirectory string) (*Configuration, error) {
}
config.Port = port

logLevel := os.Getenv(LogLevel)
if len(logLevel) == 0 || logLevel != "DEBUG" {
config.LogLevelDebug = false
} else {
config.LogLevelDebug = true
}
return config, nil
}

Expand Down
27 changes: 11 additions & 16 deletions configuration/configuration_test.go
Expand Up @@ -30,12 +30,11 @@ import (

func TestLoadConfiguration(t *testing.T) {
tests := map[string]struct {
Mode string
Network string
Port string
LogLevel string
cfg *Configuration
err error
Mode string
Network string
Port string
cfg *Configuration
err error
}{
"no envs set": {
err: errors.New("MODE must be populated"),
Expand All @@ -50,10 +49,9 @@ func TestLoadConfiguration(t *testing.T) {
err: errors.New("PORT must be populated"),
},
"all set (mainnet)": {
Mode: string(Online),
Network: Mainnet,
Port: "1000",
LogLevel: "DEBUG",
Mode: string(Online),
Network: Mainnet,
Port: "1000",
cfg: &Configuration{
Mode: Online,
Network: &types.NetworkIdentifier{
Expand All @@ -78,7 +76,6 @@ func TestLoadConfiguration(t *testing.T) {
DictionaryPath: mainnetTransactionDictionary,
},
},
LogLevelDebug: true,
},
},
"all set (testnet)": {
Expand Down Expand Up @@ -109,7 +106,6 @@ func TestLoadConfiguration(t *testing.T) {
DictionaryPath: testnetTransactionDictionary,
},
},
LogLevelDebug: false,
},
},
"invalid mode": {
Expand Down Expand Up @@ -138,10 +134,9 @@ func TestLoadConfiguration(t *testing.T) {
assert.NoError(t, err)
defer utils.RemoveTempDir(newDir)

os.Setenv(ModeEnv, test.Mode)
os.Setenv(NetworkEnv, test.Network)
os.Setenv(PortEnv, test.Port)
os.Setenv(LogLevel, test.LogLevel)
_ = os.Setenv(ModeEnv, test.Mode)
_ = os.Setenv(NetworkEnv, test.Network)
_ = os.Setenv(PortEnv, test.Port)

cfg, err := LoadConfiguration(newDir)
if test.err != nil {
Expand Down
25 changes: 6 additions & 19 deletions main.go
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/coinbase/rosetta-sdk-go/server"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -112,27 +111,11 @@ func startOnlineDependencies(
return client, i, nil
}

func initializeLogger(cfg *configuration.Configuration) *zap.Logger {
if cfg.LogLevelDebug {
loggerRaw, err := zap.NewDevelopment()
if err != nil {
log.Fatalf("can't initialize zap logger: %v", err)
}
return loggerRaw
}
loggerRaw, err := zap.NewProduction()
if err != nil {
log.Fatalf("can't initialize zap logger: %v", err)
}
return loggerRaw
}

func main() {
cfg, err := configuration.LoadConfiguration(configuration.DataDirectory)
loggerRaw, err := utils.NewLogger()
if err != nil {
log.Fatalf("Unable to load configuration: %v", err)
log.Fatalf("can't initialize zap logger: %v", err)
}
loggerRaw := initializeLogger(cfg)
defer func() {
_ = loggerRaw.Sync()
}()
Expand All @@ -142,6 +125,10 @@ func main() {
go handleSignals(ctx, []context.CancelFunc{cancel})

logger := loggerRaw.Sugar().Named("main")
cfg, err := configuration.LoadConfiguration(configuration.DataDirectory)
if err != nil {
logger.Fatalw("Unable to load configuration", "error", err)
}
logger.Infow("loaded configuration", "configuration", types.PrintStruct(cfg))

g, ctx := errgroup.WithContext(ctx)
Expand Down
49 changes: 25 additions & 24 deletions mocks/indexer/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ef4283

Please sign in to comment.