Skip to content

Commit 9c94725

Browse files
committed
[confmap] Allow using any type as a string
1 parent 6f27297 commit 9c94725

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: confmap
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Allow using any YAML structure as a string when loading configuration.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [10800]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
Previous to this change, slices could not be used as strings in configuration.
20+
21+
# Optional: The change log or logs in which this entry should be included.
22+
# e.g. '[user]' or '[user, api]'
23+
# Include 'user' if the change is relevant to end users.
24+
# Include 'api' if there is a change to a library API.
25+
# Default: '[user]'
26+
change_logs: []

confmap/expand_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -542,22 +542,6 @@ func TestResolverExpandUnsupportedScheme(t *testing.T) {
542542
assert.EqualError(t, err, `scheme "unsupported" is not supported for uri "unsupported:VALUE"`)
543543
}
544544

545-
func TestResolverExpandStringValueInvalidReturnValue(t *testing.T) {
546-
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
547-
return NewRetrievedFromYAML([]byte(`test: "localhost:${test:PORT}"`))
548-
})
549-
550-
testProvider := newFakeProvider("test", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
551-
return NewRetrievedFromYAML([]byte("[1243]"))
552-
})
553-
554-
resolver, err := NewResolver(ResolverSettings{URIs: []string{"input:"}, ProviderFactories: []ProviderFactory{provider, testProvider}, ConverterFactories: nil})
555-
require.NoError(t, err)
556-
557-
_, err = resolver.Resolve(context.Background())
558-
assert.EqualError(t, err, `expanding ${test:PORT}: retrieved value does not have unambiguous string representation: [1243]`)
559-
}
560-
561545
func TestResolverDefaultProviderExpand(t *testing.T) {
562546
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
563547
return NewRetrieved(map[string]any{"foo": "${HOST}"})

confmap/internal/e2e/types_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,16 @@ func TestStrictTypeCasting(t *testing.T) {
383383
targetField: TargetFieldSlice,
384384
expected: []any{"filelog", "windowseventlog/application"},
385385
},
386+
{
387+
value: `[filelog,windowseventlog/application]`,
388+
targetField: TargetFieldString,
389+
expected: "[filelog,windowseventlog/application]",
390+
},
391+
{
392+
value: `[filelog,windowseventlog/application]`,
393+
targetField: TargetFieldInlineString,
394+
expected: "inline field with [filelog,windowseventlog/application] expansion",
395+
},
386396
}
387397

388398
previousValue := globalgates.StrictlyTypedInputGate.IsEnabled()

confmap/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func NewRetrievedFromYAML(yamlBytes []byte, opts ...RetrievedOption) (*Retrieved
152152
val = string(yamlBytes)
153153
}
154154
return NewRetrieved(val, append(opts, withStringRepresentation(val))...)
155-
case int, int32, int64, float32, float64, bool, map[string]any:
155+
default:
156156
opts = append(opts, withStringRepresentation(string(yamlBytes)))
157157
}
158158

0 commit comments

Comments
 (0)