fix: Skip reference parameter creation if parameter is unused in template #1673
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR ensures that no reference parameter is added to a config if the parameter is unused in the template.
Due to the way the code currently works, the fix is made in both dependency resolvers. This could maybe be improved in a follow up PR, however changes to this code have performance implications and thus should be measured.
A test is also added demonstrating the correct behavior.
In practice the simplest way to demonstrate it is to create a classic config with a name that occurs often in configs out of context. A good example is a network zone with the name
_
.This string occurs often in templates however as a false positive, which is detected via a regex:
dynatrace-configuration-as-code/pkg/download/dependency_resolution/resolver/shared.go
Lines 69 to 82 in 3290212
The simple fix here just checks if the
replaceAll
function actually changed the content of the template and if not, skips parameter creation.