Skip to content

Commit

Permalink
[confmap] Allow using map[string]any as string (#10615)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

<!-- Issue number if applicable -->

Allow using strings parseable in YAML as `map[string]any` in inline
position

#### Link to tracking issue

Relates to #10605 (does not fix it since it's not in inline position)
  • Loading branch information
mx-psi authored Jul 16, 2024
1 parent f2c56a3 commit e8a911b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_make-map-string-any-convertible.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: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Allow using `map[string]any` values in string interpolation

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

# (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: []
4 changes: 2 additions & 2 deletions confmap/internal/e2e/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ func TestStrictTypeCasting(t *testing.T) {
{
value: "{\"field\": 123}",
targetField: TargetFieldInlineString,
resolveErr: "retrieved value does not have unambiguous string representation",
expected: "inline field with {\"field\": 123} expansion",
},
{
value: "1111:1111:1111:1111:1111::",
targetField: TargetFieldInlineString,
resolveErr: "retrieved value does not have unambiguous string representation",
expected: "inline field with 1111:1111:1111:1111:1111:: expansion",
},
{
value: "1111:1111:1111:1111:1111::",
Expand Down
2 changes: 1 addition & 1 deletion confmap/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func NewRetrievedFromYAML(yamlBytes []byte, opts ...RetrievedOption) (*Retrieved
switch v := rawConf.(type) {
case string:
opts = append(opts, withStringRepresentation(v))
case int, int32, int64, float32, float64, bool:
case int, int32, int64, float32, float64, bool, map[string]any:
opts = append(opts, withStringRepresentation(string(yamlBytes)))
}

Expand Down
5 changes: 2 additions & 3 deletions confmap/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ func TestNewRetrievedFromYAMLString(t *testing.T) {
value: 0.123,
},
{
yaml: "{key: value}",
value: map[string]any{"key": "value"},
strReprErr: "retrieved value does not have unambiguous string representation",
yaml: "{key: value}",
value: map[string]any{"key": "value"},
},
}

Expand Down

0 comments on commit e8a911b

Please sign in to comment.