diff --git a/.chloggen/mx-psi_as-string.yaml b/.chloggen/mx-psi_as-string.yaml new file mode 100644 index 00000000000..cc4c3b4cff1 --- /dev/null +++ b/.chloggen/mx-psi_as-string.yaml @@ -0,0 +1,26 @@ +# 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: confmap + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: When passing value to a string field through the `${:URI}` or `${URI}` syntax, the original raw string value is now preserved. + +# One or more tracking issues or pull requests related to the change +issues: [10603] + +# (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: | + - This change only applies under the `confmap.unifyEnvVarExpansion` feature gate. + +# 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 e57d3f8af53..c5d38630c33 100644 --- a/confmap/internal/e2e/types_test.go +++ b/confmap/internal/e2e/types_test.go @@ -98,27 +98,22 @@ func TestTypeCasting(t *testing.T) { { value: "\"0123\"", targetField: TargetFieldString, - expected: "0123", - }, - { - value: "\"0123\"", - targetField: TargetFieldInt, - expected: 83, + expected: "\"0123\"", }, { value: "\"0123\"", targetField: TargetFieldInlineString, - expected: "inline field with 0123 expansion", + expected: "inline field with \"0123\" expansion", }, { value: "!!str 0123", targetField: TargetFieldString, - expected: "0123", + expected: "!!str 0123", }, { value: "!!str 0123", targetField: TargetFieldInlineString, - expected: "inline field with 0123 expansion", + expected: "inline field with !!str 0123 expansion", }, { value: "t", @@ -228,27 +223,27 @@ func TestStrictTypeCasting(t *testing.T) { { value: "\"0123\"", targetField: TargetFieldString, - expected: "0123", + expected: "\"0123\"", }, { value: "\"0123\"", targetField: TargetFieldInt, - unmarshalErr: "'field' expected type 'int', got unconvertible type 'string', value: '0123'", + unmarshalErr: "'field' expected type 'int', got unconvertible type 'string', value: '\"0123\"'", }, { value: "\"0123\"", targetField: TargetFieldInlineString, - expected: "inline field with 0123 expansion", + expected: "inline field with \"0123\" expansion", }, { value: "!!str 0123", targetField: TargetFieldString, - expected: "0123", + expected: "!!str 0123", }, { value: "!!str 0123", targetField: TargetFieldInlineString, - expected: "inline field with 0123 expansion", + expected: "inline field with !!str 0123 expansion", }, { value: "t", diff --git a/confmap/provider.go b/confmap/provider.go index f774cca3834..ea94aec3f87 100644 --- a/confmap/provider.go +++ b/confmap/provider.go @@ -9,6 +9,8 @@ import ( "go.uber.org/zap" "gopkg.in/yaml.v3" + + "go.opentelemetry.io/collector/internal/featuregates" ) // ProviderSettings are the settings to initialize a Provider. @@ -138,9 +140,14 @@ func NewRetrievedFromYAML(yamlBytes []byte, opts ...RetrievedOption) (*Retrieved return nil, err } - switch v := rawConf.(type) { + switch rawConf.(type) { case string: - opts = append(opts, withStringRepresentation(v)) + if featuregates.UseUnifiedEnvVarExpansionRules.IsEnabled() { + // If rawConf is a string, we override it with the raw yamlBytes. + // This is the original ${ENV} expansion behavior. + rawConf = string(yamlBytes) + } + opts = append(opts, withStringRepresentation(string(yamlBytes))) case int, int32, int64, float32, float64, bool: opts = append(opts, withStringRepresentation(string(yamlBytes))) } diff --git a/confmap/provider_test.go b/confmap/provider_test.go index e43b5608096..791b6d81f15 100644 --- a/confmap/provider_test.go +++ b/confmap/provider_test.go @@ -85,8 +85,8 @@ func TestNewRetrievedFromYAMLString(t *testing.T) { }, { yaml: "\"string\"", - value: "string", - altStrRepr: "string", + value: "\"string\"", + altStrRepr: "\"string\"", }, { yaml: "123", diff --git a/docs/rfcs/env-vars.md b/docs/rfcs/env-vars.md index a2709412788..7f17b933a52 100644 --- a/docs/rfcs/env-vars.md +++ b/docs/rfcs/env-vars.md @@ -216,7 +216,7 @@ loading a field with the braces syntax, `env` syntax. | `0123` | integer | 83 | 83 | 83 | n/a | | `0123` | string | 0123 | 83 | 0123 | 0123 | | `0xdeadbeef` | string | 0xdeadbeef | 3735928559 | 0xdeadbeef | 0xdeadbeef | -| `"0123"` | string | "0123" | 0123 | 0123 | 0123 | -| `!!str 0123` | string | !!str 0123 | 0123 | 0123 | 0123 | +| `"0123"` | string | "0123" | 0123 | "0123" | "0123" | +| `!!str 0123` | string | !!str 0123 | 0123 | !!str 0123 | !!str 0123 | | `t` | boolean | true | true | Error: mapping string to bool | n/a | | `23` | boolean | true | true | Error: mapping integer to bool | n/a |