Skip to content

Commit

Permalink
[confmap] Only log error in expandconverter if expansion actually hap…
Browse files Browse the repository at this point in the history
…pens (#10392)

#### Description
Fix a bug where we printed a warning log when we were not expanding a
value

#### Link to tracking issue
Fixes
#10356

#### Testing
Tested manually
  • Loading branch information
TylerHelmuth committed Jun 12, 2024
1 parent 7dfb57b commit e4a1f5b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
25 changes: 25 additions & 0 deletions .chloggen/confmap-fix-log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: expandconverter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix bug where an warning was logged incorrectly.

# One or more tracking issues or pull requests related to the change
issues: [10392]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
16 changes: 9 additions & 7 deletions confmap/converter/expandconverter/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ func (c converter) expandStringValues(value any) (any, error) {
func (c converter) expandEnv(s string) (string, error) {
var err error
res := os.Expand(s, func(str string) string {
// This allows escaping environment variable substitution via $$, e.g.
// - $FOO will be substituted with env var FOO
// - $$FOO will be replaced with $FOO
// - $$$FOO will be replaced with $ + substituted env var FOO
if str == "$" {
return "$"
}

// Matches on $VAR style environment variables
// in order to make sure we don't log a warning for ${VAR}
var regex = regexp.MustCompile(fmt.Sprintf(`\$%s`, regexp.QuoteMeta(str)))
Expand All @@ -88,13 +96,7 @@ func (c converter) expandEnv(s string) (string, error) {
c.logger.Warn(msg, zap.String("variable", str))
c.loggedDeprecations[str] = struct{}{}
}
// This allows escaping environment variable substitution via $$, e.g.
// - $FOO will be substituted with env var FOO
// - $$FOO will be replaced with $FOO
// - $$$FOO will be replaced with $ + substituted env var FOO
if str == "$" {
return "$"
}

// For $ENV style environment variables os.Expand returns once it hits a character that isn't an underscore or
// an alphanumeric character - so we cannot detect those malformed environment variables.
// For ${ENV} style variables we can detect those kinds of env var names!
Expand Down

0 comments on commit e4a1f5b

Please sign in to comment.