From 278a9dab7c1bc107b3ea73500a8b0079eae20c37 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Thu, 24 Mar 2022 15:08:03 -0500 Subject: [PATCH] ci: set test log level off in gha --- .github/workflows/test-core.yaml | 2 +- command/agent/keyring_test.go | 8 +++++--- command/agent/log_levels.go | 2 +- command/agent/testagent.go | 29 +++++++---------------------- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test-core.yaml b/.github/workflows/test-core.yaml index 8ed7dc2b4..41cf603a6 100644 --- a/.github/workflows/test-core.yaml +++ b/.github/workflows/test-core.yaml @@ -27,7 +27,7 @@ env: CONSUL_VERSION: 1.11.3 VAULT_VERSION: 1.9.3 NOMAD_SLOW_TEST: 0 - NOMAD_TEST_LOG_LEVEL: ERROR + NOMAD_TEST_LOG_LEVEL: OFF jobs: checks: runs-on: ubuntu-20.04 diff --git a/command/agent/keyring_test.go b/command/agent/keyring_test.go index 284a11314..aa35f4762 100644 --- a/command/agent/keyring_test.go +++ b/command/agent/keyring_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/ci" + "github.com/hashicorp/nomad/helper/testlog" ) func TestAgent_LoadKeyrings(t *testing.T) { @@ -29,9 +30,10 @@ func TestAgent_LoadKeyrings(t *testing.T) { // Server should auto-load WAN keyring files agent2 := &TestAgent{ - T: t, - Name: t.Name() + "2", - Key: key, + T: t, + Name: t.Name() + "2", + Key: key, + logger: testlog.HCLogger(t), } agent2.Start() defer agent2.Shutdown() diff --git a/command/agent/log_levels.go b/command/agent/log_levels.go index f4455e47f..8b4e35236 100644 --- a/command/agent/log_levels.go +++ b/command/agent/log_levels.go @@ -10,7 +10,7 @@ import ( // levels that we use. func LevelFilter() *logutils.LevelFilter { return &logutils.LevelFilter{ - Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"}, + Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"}, MinLevel: "INFO", Writer: ioutil.Discard, } diff --git a/command/agent/testagent.go b/command/agent/testagent.go index b69459c85..223303e98 100644 --- a/command/agent/testagent.go +++ b/command/agent/testagent.go @@ -2,7 +2,6 @@ package agent import ( "fmt" - "io" "io/ioutil" "math/rand" "net/http" @@ -55,9 +54,8 @@ type TestAgent struct { // when Shutdown() is called. Config *Config - // LogOutput is the sink for the logs. If nil, logs are written - // to os.Stderr. - LogOutput io.Writer + // logger is used for logging + logger hclog.InterceptLogger // DataDir is the data directory which is used when Config.DataDir // is not set. It is created automatically and removed when @@ -102,6 +100,7 @@ func NewTestAgent(t testing.TB, name string, configCallback func(*Config)) *Test Name: name, ConfigCallback: configCallback, Enterprise: EnterpriseTestAgent, + logger: testlog.HCLogger(t), } a.Start() @@ -235,11 +234,6 @@ RETRY: } func (a *TestAgent) start() (*Agent, error) { - if a.LogOutput == nil { - prefix := fmt.Sprintf("%v:%v ", a.Config.BindAddr, a.Config.Ports.RPC) - a.LogOutput = testlog.NewPrefixWriter(a.T, prefix) - } - inm := metrics.NewInmemSink(10*time.Second, time.Minute) metrics.NewGlobal(metrics.DefaultConfig("service-name"), inm) @@ -247,14 +241,7 @@ func (a *TestAgent) start() (*Agent, error) { return nil, fmt.Errorf("unable to set up in memory metrics needed for agent initialization") } - logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{ - Name: "agent", - Level: hclog.LevelFromString(a.Config.LogLevel), - Output: a.LogOutput, - JSONFormat: a.Config.LogJson, - }) - - agent, err := NewAgent(a.Config, logger, a.LogOutput, inm) + agent, err := NewAgent(a.Config, a.logger, testlog.NewWriter(a.T), inm) if err != nil { return nil, err } @@ -349,8 +336,7 @@ func (a *TestAgent) pickRandomPorts(c *Config) { } } -// TestConfig returns a unique default configuration for testing an -// agent. +// TestConfig returns a unique default configuration for testing an agent. func (a *TestAgent) config() *Config { conf := DevConfig(nil) @@ -361,10 +347,9 @@ func (a *TestAgent) config() *Config { // Setup client config conf.ClientConfig = client.DefaultConfig() - logger := testlog.HCLogger(a.T) conf.LogLevel = testlog.HCLoggerTestLevel().String() - conf.NomadConfig.Logger = logger - conf.ClientConfig.Logger = logger + conf.NomadConfig.Logger = a.logger + conf.ClientConfig.Logger = a.logger // Set the name conf.NodeName = a.Name