From def031958bbc52cc972666e8adc8f683d898c006 Mon Sep 17 00:00:00 2001 From: Maxim Merzhanov Date: Tue, 19 Nov 2019 13:24:24 +0300 Subject: [PATCH] add overriding logging level via env var --- config_service_integration_test.go | 26 ++++++++++++++++++-------- main.go | 4 ++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/config_service_integration_test.go b/config_service_integration_test.go index 9192901..22f3509 100644 --- a/config_service_integration_test.go +++ b/config_service_integration_test.go @@ -87,7 +87,7 @@ func setup(testCtx *ctx.TestContext, runTest func() int) int { Grpc: grpcAddr, }, Cluster: conf.ClusterConfiguration{ - InMemory: true, + InMemory: false, DataDir: "./data", Peers: nil, OuterAddress: httpAddr.GetAddress(), @@ -106,6 +106,7 @@ func setup(testCtx *ctx.TestContext, runTest func() int) int { for i := 0; i < configsNumber; i++ { c := configs[i] peersAddrsEnv := generatePeersConfigEnv(peersAddrs) + peersAddrsEnv["LOG_LEVEL"] = "debug" ctx := env.RunAppContainer( cfg.Images.Module, c, nil, docker.WithName(c.GrpcOuterAddress.IP), @@ -136,16 +137,19 @@ func TestClusterElection(t *testing.T) { } }() a := assert.New(t) - - testClusterReady(a, -1) - var ready bool + + ready = testClusterReady(a, -1) + if !ready { + return + } + for i := 0; i < configsNumber; i++ { fmt.Println() log.Printf("stopping %d container\n", i) a.NoError(configsCtxs[i].StopContainer(20 * time.Second)) - time.Sleep(9 * time.Second) + time.Sleep(5 * time.Second) fmt.Println() log.Printf("checking cluster except %d\n", i) ready = testClusterReady(a, i) @@ -157,7 +161,7 @@ func TestClusterElection(t *testing.T) { log.Printf("starting %d container\n", i) a.NoError(configsCtxs[i].StartContainer()) - log.Println("checking cluster") + log.Printf("checking cluster, iteration %d\n", i+1) ready = testClusterReady(a, -1) if !ready { return @@ -197,9 +201,14 @@ func testClusterReady(a *assert.Assertions, except int) bool { } } - var prevRoutes = getRoutes(clients[0], a) + prevRoutes := getRoutes(clients[0], a) + routesLen := len(clients) for i := 1; i < len(clients); i++ { routes := getRoutes(clients[i], a) + t := a.Lenf(routes, routesLen, "invalid length") + if !t { + return t + } match := a.ElementsMatch(prevRoutes, routes, "different backend declarations") if !match { return match @@ -258,6 +267,7 @@ func getRoutes(client *backend.InternalGrpcClient, a *assert.Assertions) []struc nil, &response, ) + //log.Println("routes:", response) a.NoError(err) return response } @@ -286,7 +296,7 @@ func (l *writeLogger) Write(p []byte) (int, error) { lines := bytes.SplitAfter(p, []byte("\n")) for _, line := range lines { s := string(line) - if strings.Contains(s, l.filter) || strings.TrimSpace(s) == "" { + if l.filter != "" && strings.Contains(s, l.filter) || strings.TrimSpace(s) == "" { continue } _, err := l.w.Write(p) diff --git a/main.go b/main.go index e3a1090..5410db9 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "github.com/integration-system/isp-lib/bootstrap" "github.com/integration-system/isp-lib/config" "github.com/integration-system/isp-lib/structure" + "github.com/integration-system/isp-lib/utils" log "github.com/integration-system/isp-log" "github.com/soheilhy/cmux" "github.com/thecodeteam/goodbye" @@ -42,6 +43,9 @@ var ( func init() { config.InitConfig(&conf.Configuration{}) + if utils.LOG_LEVEL != "" { + _ = log.SetLevel(utils.LOG_LEVEL) + } } // @title ISP configuration service