From e5e448b7abbd07724e5bb1bc40258632a68d7119 Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Fri, 21 Mar 2025 20:03:42 -0400 Subject: [PATCH 1/2] Nice debug logs --- helper/resource/plugin.go | 26 +++++++++++++------------- helper/resource/testing.go | 4 ---- helper/resource/testing_new.go | 2 -- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/helper/resource/plugin.go b/helper/resource/plugin.go index 5c92f3ab9..9fba439b7 100644 --- a/helper/resource/plugin.go +++ b/helper/resource/plugin.go @@ -178,14 +178,14 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl providerName = strings.TrimPrefix(providerName, "terraform-provider-") providerAddress := getProviderAddr(providerName) - logging.HelperResourceDebug(ctx, "Creating sdkv2 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Creating sdkv2 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) provider, err := factory() if err != nil { return fmt.Errorf("unable to create provider %q from factory: %w", providerName, err) } - logging.HelperResourceDebug(ctx, "Created sdkv2 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Created sdkv2 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) // keep track of the running factory, so we can make sure it's // shut down. @@ -215,14 +215,14 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl ProviderAddr: providerAddress, } - logging.HelperResourceDebug(ctx, "Starting sdkv2 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Starting sdkv2 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) config, closeCh, err := plugin.DebugServe(ctx, opts) if err != nil { return fmt.Errorf("unable to serve provider %q: %w", providerName, err) } - logging.HelperResourceDebug(ctx, "Started sdkv2 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Started sdkv2 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) tfexecConfig := tfexec.ReattachConfig{ Protocol: config.Protocol, @@ -272,14 +272,14 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl } } - logging.HelperResourceDebug(ctx, "Creating tfprotov5 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Creating tfprotov5 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) provider, err := factory() if err != nil { return fmt.Errorf("unable to create provider %q from factory: %w", providerName, err) } - logging.HelperResourceDebug(ctx, "Created tfprotov5 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Created tfprotov5 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) // keep track of the running factory, so we can make sure it's // shut down. @@ -303,14 +303,14 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl ProviderAddr: providerAddress, } - logging.HelperResourceDebug(ctx, "Starting tfprotov5 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Starting tfprotov5 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) config, closeCh, err := plugin.DebugServe(ctx, opts) if err != nil { return fmt.Errorf("unable to serve provider %q: %w", providerName, err) } - logging.HelperResourceDebug(ctx, "Started tfprotov5 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Started tfprotov5 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) tfexecConfig := tfexec.ReattachConfig{ Protocol: config.Protocol, @@ -361,14 +361,14 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl } } - logging.HelperResourceDebug(ctx, "Creating tfprotov6 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Creating tfprotov6 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) provider, err := factory() if err != nil { return fmt.Errorf("unable to create provider %q from factory: %w", providerName, err) } - logging.HelperResourceDebug(ctx, "Created tfprotov6 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Created tfprotov6 provider instance", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) // keep track of the running factory, so we can make sure it's // shut down. @@ -388,14 +388,14 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl ProviderAddr: providerAddress, } - logging.HelperResourceDebug(ctx, "Starting tfprotov6 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Starting tfprotov6 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) config, closeCh, err := plugin.DebugServe(ctx, opts) if err != nil { return fmt.Errorf("unable to serve provider %q: %w", providerName, err) } - logging.HelperResourceDebug(ctx, "Started tfprotov6 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) + logging.HelperResourceTrace(ctx, "Started tfprotov6 provider instance server", map[string]interface{}{logging.KeyProviderAddress: providerAddress}) tfexecConfig := tfexec.ReattachConfig{ Protocol: config.Protocol, @@ -441,7 +441,7 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl } logging.HelperResourceTrace(ctx, "Called wrapped Terraform CLI command") - logging.HelperResourceDebug(ctx, "Stopping providers") + logging.HelperResourceTrace(ctx, "Stopping providers") // cancel the servers so they'll return. Otherwise, this closeCh won't // get closed, and we'll hang here. diff --git a/helper/resource/testing.go b/helper/resource/testing.go index c7bdcd75e..14774ca58 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -929,11 +929,7 @@ func Test(t testing.T, c TestCase) { // This is done after creating the helper because a working directory is required // to retrieve the Terraform version. if c.TerraformVersionChecks != nil { - logging.HelperResourceDebug(ctx, "Calling TestCase Terraform version checks") - runTFVersionChecks(ctx, t, helper.TerraformVersion(), c.TerraformVersionChecks) - - logging.HelperResourceDebug(ctx, "Called TestCase Terraform version checks") } runNewTest(ctx, t, c, helper) diff --git a/helper/resource/testing_new.go b/helper/resource/testing_new.go index 8e0bc2167..1a84188b8 100644 --- a/helper/resource/testing_new.go +++ b/helper/resource/testing_new.go @@ -129,8 +129,6 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest } } - logging.HelperResourceDebug(ctx, "Starting TestSteps") - // use this to track last step successfully applied // acts as default for import tests var appliedCfg string From b0c7444994ba0875568d11cdd920f90d3a42114f Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Tue, 25 Mar 2025 08:45:45 -0400 Subject: [PATCH 2/2] fixup! Merge branch 'main' into nice-debug-logs --- .changes/unreleased/NOTES-20250325-084449.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/unreleased/NOTES-20250325-084449.yaml diff --git a/.changes/unreleased/NOTES-20250325-084449.yaml b/.changes/unreleased/NOTES-20250325-084449.yaml new file mode 100644 index 000000000..b64de080f --- /dev/null +++ b/.changes/unreleased/NOTES-20250325-084449.yaml @@ -0,0 +1,5 @@ +kind: NOTES +body: reduced the volume of DEBUG-level logging to make it easier to visually scan debug output +time: 2025-03-25T08:44:49.949718-04:00 +custom: + Issue: "463"