From e8a911bbdbdb1ca121354c0f822faaad8ce61d24 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Tue, 16 Jul 2024 17:25:20 +0200 Subject: [PATCH] [confmap] Allow using map[string]any as string (#10615) #### Description 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) --- ...x-psi_make-map-string-any-convertible.yaml | 25 +++++++++++++++++++ confmap/internal/e2e/types_test.go | 4 +-- confmap/provider.go | 2 +- confmap/provider_test.go | 5 ++-- 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 .chloggen/mx-psi_make-map-string-any-convertible.yaml diff --git a/.chloggen/mx-psi_make-map-string-any-convertible.yaml b/.chloggen/mx-psi_make-map-string-any-convertible.yaml new file mode 100644 index 00000000000..0eea7c1a695 --- /dev/null +++ b/.chloggen/mx-psi_make-map-string-any-convertible.yaml @@ -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: [] diff --git a/confmap/internal/e2e/types_test.go b/confmap/internal/e2e/types_test.go index bf7f516138d..aee111de7c3 100644 --- a/confmap/internal/e2e/types_test.go +++ b/confmap/internal/e2e/types_test.go @@ -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::", diff --git a/confmap/provider.go b/confmap/provider.go index f774cca3834..161e2473971 100644 --- a/confmap/provider.go +++ b/confmap/provider.go @@ -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))) } diff --git a/confmap/provider_test.go b/confmap/provider_test.go index e43b5608096..ebbd5562ec3 100644 --- a/confmap/provider_test.go +++ b/confmap/provider_test.go @@ -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"}, }, }