From 509d76fbed797a364c7a33e5cabea6fc04bfb437 Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Wed, 30 Aug 2023 17:41:02 +0100 Subject: [PATCH] Add loglevel flag (#1490) * Add loglevel flag * set default log level to info 3 --- .github/workflows/manual-deploy-testnet-l2.yml | 8 +++++++- .github/workflows/manual-upgrade-testnet-l2.yml | 6 ++++++ go/node/cmd/cli.go | 3 +++ go/node/cmd/cli_flags.go | 2 ++ go/node/cmd/main.go | 1 + go/node/config.go | 9 +++++++++ go/node/docker_node.go | 2 ++ testnet/launcher/docker.go | 1 + 8 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/workflows/manual-deploy-testnet-l2.yml b/.github/workflows/manual-deploy-testnet-l2.yml index 5c8acf92f7..f8f1d95c13 100644 --- a/.github/workflows/manual-deploy-testnet-l2.yml +++ b/.github/workflows/manual-deploy-testnet-l2.yml @@ -7,7 +7,7 @@ name: '[M] Deploy Testnet L2' on: workflow_dispatch: - inputs: + testnet_type: testnet_type: description: 'Testnet Type' required: true @@ -16,6 +16,11 @@ on: options: - 'dev-testnet' - 'testnet' + log_level: + description: 'Log Level 1-Error 5-Trace' + required: true + default: 3 + type: number jobs: build: @@ -258,6 +263,7 @@ jobs: -enclave_docker_image=${{needs.build.outputs.L2_ENCLAVE_DOCKER_BUILD_TAG}} \ -host_docker_image=${{needs.build.outputs.L2_HOST_DOCKER_BUILD_TAG}} \ -is_debug_namespace_enabled=true \ + -log_level=${{ github.event.inputs.log_level }} \ start' diff --git a/.github/workflows/manual-upgrade-testnet-l2.yml b/.github/workflows/manual-upgrade-testnet-l2.yml index d63093e867..3119d08a6b 100644 --- a/.github/workflows/manual-upgrade-testnet-l2.yml +++ b/.github/workflows/manual-upgrade-testnet-l2.yml @@ -23,6 +23,11 @@ on: options: - 'dev-testnet' - 'testnet' + log_level: + description: 'Log Level 1-Error 5-Trace' + required: true + default: 3 + type: number jobs: build: @@ -176,6 +181,7 @@ jobs: -host_p2p_port=10000 \ -enclave_docker_image=${{needs.build.outputs.L2_ENCLAVE_DOCKER_BUILD_TAG}} \ -host_docker_image=${{needs.build.outputs.L2_HOST_DOCKER_BUILD_TAG}} \ + -log_level=${{ github.event.inputs.log_level }} \ upgrade' check-obscuro-is-healthy: diff --git a/go/node/cmd/cli.go b/go/node/cmd/cli.go index 2a22ea797a..5774903ff5 100644 --- a/go/node/cmd/cli.go +++ b/go/node/cmd/cli.go @@ -40,6 +40,7 @@ type NodeConfigCLI struct { hostWSPort int nodeName string isDebugNamespaceEnabled bool + logLevel int } // ParseConfigCLI returns a NodeConfigCLI based the cli params and defaults. @@ -71,6 +72,7 @@ func ParseConfigCLI() *NodeConfigCLI { pccsAddr := flag.String(pccsAddrFlag, "", flagUsageMap[pccsAddrFlag]) edgelessDBImage := flag.String(edgelessDBImageFlag, "ghcr.io/edgelesssys/edgelessdb-sgx-4gb:v0.3.2", flagUsageMap[edgelessDBImageFlag]) isDebugNamespaceEnabled := flag.Bool(isDebugNamespaceEnabledFlag, false, flagUsageMap[isDebugNamespaceEnabledFlag]) + logLevel := flag.Int(logLevelFlag, 3, flagUsageMap[logLevelFlag]) flag.Parse() cfg.nodeName = *nodeName @@ -97,6 +99,7 @@ func ParseConfigCLI() *NodeConfigCLI { cfg.hostHTTPPort = *hostHTTPPort cfg.hostWSPort = *hostWSPort cfg.isDebugNamespaceEnabled = *isDebugNamespaceEnabled + cfg.logLevel = *logLevel cfg.nodeAction = flag.Arg(0) if !validateNodeAction(cfg.nodeAction) { diff --git a/go/node/cmd/cli_flags.go b/go/node/cmd/cli_flags.go index 9fd9e4aa7e..a64a783e9b 100644 --- a/go/node/cmd/cli_flags.go +++ b/go/node/cmd/cli_flags.go @@ -26,6 +26,7 @@ const ( pccsAddrFlag = "pccs_addr" edgelessDBImageFlag = "edgeless_db_image" isDebugNamespaceEnabledFlag = "is_debug_namespace_enabled" + logLevelFlag = "log_level" ) // Returns a map of the flag usages. @@ -56,5 +57,6 @@ func getFlagUsageMap() map[string]string { hostHTTPPortFlag: "Host HTTPs bound port", hostWSPortFlag: "Host WebSocket bound port", isDebugNamespaceEnabledFlag: "Enables the debug namespace for both enclave and host", + logLevelFlag: "Sets the log level 1-Error, 5-Trace", } } diff --git a/go/node/cmd/main.go b/go/node/cmd/main.go index 4a4bbf7fbc..b239536e25 100644 --- a/go/node/cmd/main.go +++ b/go/node/cmd/main.go @@ -32,6 +32,7 @@ func main() { node.WithPCCSAddr(cliConfig.pccsAddr), node.WithEdgelessDBImage(cliConfig.edgelessDBImage), node.WithDebugNamespaceEnabled(cliConfig.isDebugNamespaceEnabled), // false + node.WithLogLevel(cliConfig.logLevel), ) dockerNode := node.NewDockerNode(nodeCfg) diff --git a/go/node/config.go b/go/node/config.go index 5ba5861cf6..ffcc24b70d 100644 --- a/go/node/config.go +++ b/go/node/config.go @@ -45,6 +45,7 @@ type Config struct { hostInMemDB bool debugNamespaceEnabled bool profilerEnabled bool + logLevel int } func NewNodeConfig(opts ...Option) *Config { @@ -70,6 +71,7 @@ func (c *Config) ToEnclaveConfig() *config.EnclaveConfig { cfg.HostID = gethcommon.HexToAddress(c.hostID) cfg.HostAddress = fmt.Sprintf("127.0.0.1:%d", c.hostP2PPort) cfg.LogPath = testlog.LogFile() + cfg.LogLevel = c.logLevel cfg.Address = fmt.Sprintf("%s:%d", _localhost, c.enclaveWSPort) return cfg @@ -97,6 +99,7 @@ func (c *Config) ToHostConfig() *config.HostInputConfig { cfg.LogPath = testlog.LogFile() cfg.ProfilerEnabled = c.profilerEnabled cfg.MetricsEnabled = false + cfg.LogLevel = c.logLevel return cfg } @@ -264,3 +267,9 @@ func WithProfiler(b bool) Option { c.profilerEnabled = b } } + +func WithLogLevel(i int) Option { + return func(c *Config) { + c.logLevel = i + } +} diff --git a/go/node/docker_node.go b/go/node/docker_node.go index 7e626f4314..5abe023ce5 100644 --- a/go/node/docker_node.go +++ b/go/node/docker_node.go @@ -116,6 +116,7 @@ func (d *DockerNode) startHost() error { // todo (@stefan): once the limiter is in, increase it back to 5 or 10s "-batchInterval=1s", "-rollupInterval=3s", + fmt.Sprintf("-logLevel=%d", d.cfg.logLevel), } if !d.cfg.hostInMemDB { cmd = append(cmd, "-levelDBPath", _hostDataDir) @@ -175,6 +176,7 @@ func (d *DockerNode) startEnclave() error { fmt.Sprintf("-debugNamespaceEnabled=%t", d.cfg.debugNamespaceEnabled), "-maxBatchSize=25600", "-maxRollupSize=65536", + fmt.Sprintf("-logLevel=%d", d.cfg.logLevel), ) if d.cfg.sgxEnabled { diff --git a/testnet/launcher/docker.go b/testnet/launcher/docker.go index c6b64f47ed..2ba1c95656 100644 --- a/testnet/launcher/docker.go +++ b/testnet/launcher/docker.go @@ -61,6 +61,7 @@ func (t *Testnet) Start() error { node.WithL1Start(networkConfig.L1StartHash), node.WithInMemoryHostDB(true), node.WithDebugNamespaceEnabled(true), + node.WithLogLevel(4), ) sequencerNode := node.NewDockerNode(sequencerNodeConfig)