Only call StringWithNodeTypes for TRACE logs (#1810)

Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
This commit is contained in:
Jon Johnson 2024-07-24 10:44:20 -07:00 committed by GitHub
parent eb69100dbd
commit 7d94797219
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 10 deletions

View File

@ -6,6 +6,7 @@ NEW FEATURES:
ENHANCEMENTS: ENHANCEMENTS:
* Added `-show-sensitive` flag to tofu plan, apply, state-show and output commands to display sensitive data in output. ([#1554](https://github.com/opentofu/opentofu/pull/1554)) * Added `-show-sensitive` flag to tofu plan, apply, state-show and output commands to display sensitive data in output. ([#1554](https://github.com/opentofu/opentofu/pull/1554))
* Improved performance for large graphs when debug logs are not enabled. ([#1810](https://github.com/opentofu/opentofu/pull/1810))
BUG FIXES: BUG FIXES:
* Ensure that using a sensitive path for templatefile that it doesn't panic([#1801](https://github.com/opentofu/opentofu/issues/1801)) * Ensure that using a sensitive path for templatefile that it doesn't panic([#1801](https://github.com/opentofu/opentofu/issues/1801))

View File

@ -43,12 +43,15 @@ func (b *BasicGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Di
log.Printf("[TRACE] Executing graph transform %T", step) log.Printf("[TRACE] Executing graph transform %T", step)
err := step.Transform(g) err := step.Transform(g)
if logging.IsDebugOrHigher() {
if thisStepStr := g.StringWithNodeTypes(); thisStepStr != lastStepStr { if thisStepStr := g.StringWithNodeTypes(); thisStepStr != lastStepStr {
log.Printf("[TRACE] Completed graph transform %T with new graph:\n%s ------", step, logging.Indent(thisStepStr)) log.Printf("[TRACE] Completed graph transform %T with new graph:\n%s ------", step, logging.Indent(thisStepStr))
lastStepStr = thisStepStr lastStepStr = thisStepStr
} else { } else {
log.Printf("[TRACE] Completed graph transform %T (no changes)", step) log.Printf("[TRACE] Completed graph transform %T (no changes)", step)
} }
}
if err != nil { if err != nil {
if nf, isNF := err.(tfdiags.NonFatalError); isNF { if nf, isNF := err.(tfdiags.NonFatalError); isNF {

View File

@ -39,6 +39,8 @@ func (t *graphTransformerMulti) Transform(g *Graph) error {
if err := t.Transform(g); err != nil { if err := t.Transform(g); err != nil {
return err return err
} }
if logging.IsDebugOrHigher() {
if thisStepStr := g.StringWithNodeTypes(); thisStepStr != lastStepStr { if thisStepStr := g.StringWithNodeTypes(); thisStepStr != lastStepStr {
log.Printf("[TRACE] (graphTransformerMulti) Completed graph transform %T with new graph:\n%s ------", t, logging.Indent(thisStepStr)) log.Printf("[TRACE] (graphTransformerMulti) Completed graph transform %T with new graph:\n%s ------", t, logging.Indent(thisStepStr))
lastStepStr = thisStepStr lastStepStr = thisStepStr
@ -46,6 +48,7 @@ func (t *graphTransformerMulti) Transform(g *Graph) error {
log.Printf("[TRACE] (graphTransformerMulti) Completed graph transform %T (no changes)", t) log.Printf("[TRACE] (graphTransformerMulti) Completed graph transform %T (no changes)", t)
} }
} }
}
return nil return nil
} }