From 078d9f1ed51683544ae465eb52520cc24ed26ce4 Mon Sep 17 00:00:00 2001 From: Sebastian Choren Date: Wed, 28 Aug 2024 18:42:09 -0300 Subject: [PATCH] fix: reenable debug logging --- cli/cloud/cmd/run_cmd.go | 15 ++++++++------- cli/cloud/cmd/wait_cmd.go | 5 +++-- cli/cloud/runner/rungroup.go | 5 ++--- cli/cmd/config.go | 3 ++- cli/cmd/resource_run_cmd.go | 2 +- cli/cmd/resources.go | 8 ++++---- cli/cmd/wait_cmd.go | 2 +- cli/cmdutil/logger.go | 6 ------ cli/pkg/resourcemanager/client.go | 3 +-- cli/processor/environment.go | 3 +-- cli/processor/monitor.go | 3 +-- cli/processor/test.go | 3 +-- cli/processor/testsuite.go | 3 +-- cli/processor/trigger_preprocessor/graphql.go | 3 +-- cli/processor/trigger_preprocessor/grpc.go | 3 +-- cli/processor/trigger_preprocessor/http.go | 3 +-- .../trigger_preprocessor/playwrightengine.go | 3 +-- cli/processor/variableset.go | 3 +-- cli/runner/registry.go | 3 +-- 19 files changed, 32 insertions(+), 47 deletions(-) diff --git a/cli/cloud/cmd/run_cmd.go b/cli/cloud/cmd/run_cmd.go index e06b14da72..401a3e6472 100644 --- a/cli/cloud/cmd/run_cmd.go +++ b/cli/cloud/cmd/run_cmd.go @@ -10,24 +10,25 @@ import ( "github.com/kubeshop/tracetest/cli/formatters" "github.com/kubeshop/tracetest/cli/pkg/resourcemanager" "github.com/kubeshop/tracetest/cli/processor" + "go.uber.org/zap" cliRunner "github.com/kubeshop/tracetest/cli/runner" ) -func RunMultipleFiles(ctx context.Context, httpClient *resourcemanager.HTTPClient, runParams *cmdutil.RunParameters, cliConfig *config.Config, runnerRegistry cliRunner.Registry, format string) (int, error) { +func RunMultipleFiles(ctx context.Context, logger *zap.Logger, httpClient *resourcemanager.HTTPClient, runParams *cmdutil.RunParameters, cliConfig *config.Config, runnerRegistry cliRunner.Registry, format string) (int, error) { if cliConfig.Jwt == "" { return cliRunner.ExitCodeGeneralError, fmt.Errorf("you should be authenticated to run multiple files, please run 'tracetest configure'") } - variableSetPreprocessor := processor.VariableSet(cmdutil.GetLogger()) + variableSetPreprocessor := processor.VariableSet(logger) - runGroup := runner.RunGroup(config.GetAPIClient(*cliConfig)) + runGroup := runner.RunGroup(logger, config.GetAPIClient(*cliConfig)) formatter := formatters.MultipleRun[cliRunner.RunResult](func() string { return cliConfig.UI() }, true) orchestrator := runner.MultiFileOrchestrator( - cmdutil.GetLogger(), + logger, runGroup, - GetVariableSetClient(httpClient, variableSetPreprocessor), + GetVariableSetClient(logger, httpClient, variableSetPreprocessor), runnerRegistry, formatter, ) @@ -44,9 +45,9 @@ func RunMultipleFiles(ctx context.Context, httpClient *resourcemanager.HTTPClien }, format) } -func GetVariableSetClient(httpClient *resourcemanager.HTTPClient, preprocessor processor.Preprocessor) resourcemanager.Client { +func GetVariableSetClient(logger *zap.Logger, httpClient *resourcemanager.HTTPClient, preprocessor processor.Preprocessor) resourcemanager.Client { variableSetClient := resourcemanager.NewClient( - httpClient, cmdutil.GetLogger(), + httpClient, logger, "variableset", "variablesets", resourcemanager.WithTableConfig(resourcemanager.TableConfig{ Cells: []resourcemanager.TableCellConfig{ diff --git a/cli/cloud/cmd/wait_cmd.go b/cli/cloud/cmd/wait_cmd.go index 1165cac82d..7de72cf823 100644 --- a/cli/cloud/cmd/wait_cmd.go +++ b/cli/cloud/cmd/wait_cmd.go @@ -8,10 +8,11 @@ import ( "github.com/kubeshop/tracetest/cli/config" "github.com/kubeshop/tracetest/cli/formatters" cliRunner "github.com/kubeshop/tracetest/cli/runner" + "go.uber.org/zap" ) -func Wait(ctx context.Context, cliConfig *config.Config, runGroupID, format string) (int, error) { - rungroupWaiter := runner.RunGroup(config.GetAPIClient(*cliConfig)) +func Wait(ctx context.Context, logger *zap.Logger, cliConfig *config.Config, runGroupID, format string) (int, error) { + rungroupWaiter := runner.RunGroup(logger, config.GetAPIClient(*cliConfig)) runGroup, err := rungroupWaiter.WaitForCompletion(ctx, runGroupID) if err != nil { return runner.ExitCodeGeneralError, err diff --git a/cli/cloud/runner/rungroup.go b/cli/cloud/runner/rungroup.go index 186af42bd9..64130f4b7b 100644 --- a/cli/cloud/runner/rungroup.go +++ b/cli/cloud/runner/rungroup.go @@ -6,7 +6,6 @@ import ( "time" "github.com/davecgh/go-spew/spew" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/openapi" "go.uber.org/zap" ) @@ -16,9 +15,9 @@ type runGroup struct { logger *zap.Logger } -func RunGroup(openapiClient *openapi.APIClient) *runGroup { +func RunGroup(logger *zap.Logger, openapiClient *openapi.APIClient) *runGroup { return &runGroup{ - logger: cmdutil.GetLogger(), + logger: logger, openapiClient: openapiClient, } } diff --git a/cli/cmd/config.go b/cli/cmd/config.go index ca2cee1908..ca35f3e04f 100644 --- a/cli/cmd/config.go +++ b/cli/cmd/config.go @@ -130,7 +130,8 @@ func validateConfig(cmd *cobra.Command, args []string) { } func setupLogger(cmd *cobra.Command, args []string) { - cliLogger = cmdutil.GetLogger(cmdutil.WithVerbose(verbose)) + l := cmdutil.GetLogger(cmdutil.WithVerbose(verbose)) + *cliLogger = *l } func teardownCommand(cmd *cobra.Command, args []string) { diff --git a/cli/cmd/resource_run_cmd.go b/cli/cmd/resource_run_cmd.go index cdf0d2be3c..d82c760169 100644 --- a/cli/cmd/resource_run_cmd.go +++ b/cli/cmd/resource_run_cmd.go @@ -108,7 +108,7 @@ func runMultipleFiles(ctx context.Context) (string, error) { return "", nil } - exitCode, err := cloudCmd.RunMultipleFiles(ctx, httpClient, runParams, &cliConfig, runnerRegistry, output) + exitCode, err := cloudCmd.RunMultipleFiles(ctx, cliLogger, httpClient, runParams, &cliConfig, runnerRegistry, output) ExitCLI(exitCode) return "", err } diff --git a/cli/cmd/resources.go b/cli/cmd/resources.go index 8c8735a21f..e428f3ca48 100644 --- a/cli/cmd/resources.go +++ b/cli/cmd/resources.go @@ -9,13 +9,13 @@ import ( "github.com/Jeffail/gabs/v2" "github.com/kubeshop/tracetest/cli/analytics" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/formatters" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "github.com/kubeshop/tracetest/cli/pkg/resourcemanager" "github.com/kubeshop/tracetest/cli/processor" "github.com/kubeshop/tracetest/cli/processor/trigger_preprocessor" "github.com/kubeshop/tracetest/cli/runner" + "go.uber.org/zap" ) var resourceParams = &resourceParameters{} @@ -41,7 +41,7 @@ var ( httpClient = &resourcemanager.HTTPClient{} variableSetPreprocessor = processor.VariableSet(cliLogger) - variableSetClient = GetVariableSetClient(httpClient, variableSetPreprocessor) + variableSetClient = GetVariableSetClient(cliLogger, httpClient, variableSetPreprocessor) pollingProfileClient = resourcemanager.NewClient( httpClient, cliLogger, @@ -453,9 +453,9 @@ func formatItemDate(item *gabs.Container, path string) error { return nil } -func GetVariableSetClient(httpClient *resourcemanager.HTTPClient, preprocessor processor.Preprocessor) resourcemanager.Client { +func GetVariableSetClient(logger *zap.Logger, httpClient *resourcemanager.HTTPClient, preprocessor processor.Preprocessor) resourcemanager.Client { variableSetClient := resourcemanager.NewClient( - httpClient, cmdutil.GetLogger(), + httpClient, logger, "variableset", "variablesets", resourcemanager.WithTableConfig(resourcemanager.TableConfig{ Cells: []resourcemanager.TableCellConfig{ diff --git a/cli/cmd/wait_cmd.go b/cli/cmd/wait_cmd.go index 754138af6d..4c5139b574 100644 --- a/cli/cmd/wait_cmd.go +++ b/cli/cmd/wait_cmd.go @@ -17,7 +17,7 @@ var waitCmd = &cobra.Command{ Long: "Waits for a run group to be finished and displays the result", PreRun: setupCommand(), Run: WithResultHandler(WithParamsHandler(waitParams)(func(_ context.Context, _ *cobra.Command, _ []string) (string, error) { - exitCode, err := cmd.Wait(context.Background(), &cliConfig, waitParams.RunGroupID, output) + exitCode, err := cmd.Wait(context.Background(), cliLogger, &cliConfig, waitParams.RunGroupID, output) ExitCLI(exitCode) return "", err diff --git a/cli/cmdutil/logger.go b/cli/cmdutil/logger.go index 69b0a04916..001f9723a8 100644 --- a/cli/cmdutil/logger.go +++ b/cli/cmdutil/logger.go @@ -7,8 +7,6 @@ import ( "go.uber.org/zap/zapcore" ) -var logger *zap.Logger - type loggerConfig struct { Verbose bool } @@ -22,10 +20,6 @@ func WithVerbose(verbose bool) loggerOption { } func GetLogger(opts ...loggerOption) *zap.Logger { - if logger != nil { - return logger - } - loggerConfig := loggerConfig{} for _, opt := range opts { opt(&loggerConfig) diff --git a/cli/pkg/resourcemanager/client.go b/cli/pkg/resourcemanager/client.go index d5883dfa0f..2b5d93587e 100644 --- a/cli/pkg/resourcemanager/client.go +++ b/cli/pkg/resourcemanager/client.go @@ -10,7 +10,6 @@ import ( "path" "strings" - "github.com/kubeshop/tracetest/cli/cmdutil" "go.uber.org/zap" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -102,7 +101,7 @@ func NewClient( client: httpClient, resourceName: resourceName, resourceNamePlural: resourceNamePlural, - logger: cmdutil.GetLogger(), + logger: logger, } for _, opt := range opts { diff --git a/cli/processor/environment.go b/cli/processor/environment.go index abc451c74f..ce82da9bdc 100644 --- a/cli/processor/environment.go +++ b/cli/processor/environment.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/goccy/go-yaml" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/openapi" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "go.uber.org/zap" @@ -21,7 +20,7 @@ type environment struct { } func Environment(logger *zap.Logger, applyFn applyFn, updateEnvFn updateEnvFn) environment { - return environment{logger: cmdutil.GetLogger(), applyFn: applyFn, updateEnvFn: updateEnvFn} + return environment{logger: logger, applyFn: applyFn, updateEnvFn: updateEnvFn} } func (e environment) Postprocess(ctx context.Context, input fileutil.File) (fileutil.File, error) { diff --git a/cli/processor/monitor.go b/cli/processor/monitor.go index 962656789e..7e710bedfb 100644 --- a/cli/processor/monitor.go +++ b/cli/processor/monitor.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/goccy/go-yaml" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/openapi" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "go.uber.org/zap" @@ -19,7 +18,7 @@ type monitor struct { func Monitor(logger *zap.Logger, applyTestSuiteFn, applyTestFn applyResourceFunc) monitor { return monitor{ - logger: cmdutil.GetLogger(), + logger: logger, applyTestFn: applyTestFn, applyTestSuiteFn: applyTestSuiteFn, } diff --git a/cli/processor/test.go b/cli/processor/test.go index 241ddbfe88..62893b2793 100644 --- a/cli/processor/test.go +++ b/cli/processor/test.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/goccy/go-yaml" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/openapi" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "github.com/kubeshop/tracetest/cli/processor/trigger_preprocessor" @@ -20,7 +19,7 @@ type test struct { func Test(logger *zap.Logger, triggerProcessorRegistry trigger_preprocessor.Registry, applyPollingProfileFunc applyResourceFunc) test { return test{ - logger: cmdutil.GetLogger(), + logger: logger, applyPollingProfileFunc: applyPollingProfileFunc, triggerProcessorRegistry: triggerProcessorRegistry, } diff --git a/cli/processor/testsuite.go b/cli/processor/testsuite.go index 5c1b0c14ad..394cf46d4f 100644 --- a/cli/processor/testsuite.go +++ b/cli/processor/testsuite.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/goccy/go-yaml" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/openapi" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "go.uber.org/zap" @@ -20,7 +19,7 @@ type testSuite struct { func TestSuite(logger *zap.Logger, applyTestFn applyResourceFunc) testSuite { return testSuite{ - logger: cmdutil.GetLogger(), + logger: logger, applyTestFn: applyTestFn, } } diff --git a/cli/processor/trigger_preprocessor/graphql.go b/cli/processor/trigger_preprocessor/graphql.go index d51edf2d50..daff5a2b78 100644 --- a/cli/processor/trigger_preprocessor/graphql.go +++ b/cli/processor/trigger_preprocessor/graphql.go @@ -2,7 +2,6 @@ package trigger_preprocessor import ( "github.com/kubeshop/tracetest/agent/workers/trigger" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/openapi" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "go.uber.org/zap" @@ -13,7 +12,7 @@ type graphql struct { } func GRAPHQL(logger *zap.Logger) graphql { - return graphql{logger: cmdutil.GetLogger()} + return graphql{logger: logger} } func (g graphql) Type() trigger.TriggerType { diff --git a/cli/processor/trigger_preprocessor/grpc.go b/cli/processor/trigger_preprocessor/grpc.go index b599290c18..13cbaac7a7 100644 --- a/cli/processor/trigger_preprocessor/grpc.go +++ b/cli/processor/trigger_preprocessor/grpc.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/kubeshop/tracetest/agent/workers/trigger" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/openapi" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "go.uber.org/zap" @@ -15,7 +14,7 @@ type grpc struct { } func GRPC(logger *zap.Logger) grpc { - return grpc{logger: cmdutil.GetLogger()} + return grpc{logger: logger} } func (g grpc) Type() trigger.TriggerType { diff --git a/cli/processor/trigger_preprocessor/http.go b/cli/processor/trigger_preprocessor/http.go index 3d90ae8db6..56e8d7f863 100644 --- a/cli/processor/trigger_preprocessor/http.go +++ b/cli/processor/trigger_preprocessor/http.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/kubeshop/tracetest/agent/workers/trigger" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/openapi" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "go.uber.org/zap" @@ -15,7 +14,7 @@ type http struct { } func HTTP(logger *zap.Logger) http { - return http{logger: cmdutil.GetLogger()} + return http{logger: logger} } func (g http) Type() trigger.TriggerType { diff --git a/cli/processor/trigger_preprocessor/playwrightengine.go b/cli/processor/trigger_preprocessor/playwrightengine.go index c22d69a8c8..016b756ba8 100644 --- a/cli/processor/trigger_preprocessor/playwrightengine.go +++ b/cli/processor/trigger_preprocessor/playwrightengine.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/kubeshop/tracetest/agent/workers/trigger" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/openapi" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "go.uber.org/zap" @@ -15,7 +14,7 @@ type playwrightengine struct { } func PLAYWRIGHTENGINE(logger *zap.Logger) playwrightengine { - return playwrightengine{logger: cmdutil.GetLogger()} + return playwrightengine{logger: logger} } func (g playwrightengine) Type() trigger.TriggerType { diff --git a/cli/processor/variableset.go b/cli/processor/variableset.go index 6cc593e26d..41b753d253 100644 --- a/cli/processor/variableset.go +++ b/cli/processor/variableset.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/goccy/go-yaml" - "github.com/kubeshop/tracetest/cli/cmdutil" "github.com/kubeshop/tracetest/cli/pkg/fileutil" "go.uber.org/zap" ) @@ -21,7 +20,7 @@ type generic struct { func VariableSet(logger *zap.Logger) variableSet { return variableSet{ - logger: cmdutil.GetLogger(), + logger: logger, } } diff --git a/cli/runner/registry.go b/cli/runner/registry.go index cdf0a3ace3..153cb9a288 100644 --- a/cli/runner/registry.go +++ b/cli/runner/registry.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "github.com/kubeshop/tracetest/cli/cmdutil" "go.uber.org/zap" ) @@ -18,7 +17,7 @@ func NewRegistry(logger *zap.Logger) Registry { return Registry{ runners: map[string]Runner{}, proxies: map[string]string{}, - logger: cmdutil.GetLogger(), + logger: logger, } }