Skip to content

Commit 6227646

Browse files
mx-psicodeboten
andauthored
Promote confmap.strictlyTypedInput feature gate to beta (#10554)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Makes type resolution strict and conforming to the behavior described in [the env vars RFC](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/env-vars.md) Depends on: - #10553 - #10555 - #10559 - open-telemetry/opentelemetry-collector-contrib/pull/33950 <!-- Issue number if applicable --> #### Link to tracking issue Fixes #9532, Fixes #8565 --------- Co-authored-by: Alex Boten <[email protected]>
1 parent 08b0be7 commit 6227646

File tree

7 files changed

+44
-7
lines changed

7 files changed

+44
-7
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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: breaking
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: Promote `confmap.strictlyTypedInput` feature gate to beta.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [10552]
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+
This feature gate changes the following:
20+
- Configurations relying on the implicit type casting behaviors listed on [#9532](https://github.com/open-telemetry/opentelemetry-collector/issues/9532) will start to fail.
21+
- Configurations using URI expansion (i.e. `field: ${env:ENV}`) for string-typed fields will use the value passed in `ENV` verbatim without intermediate type casting.
22+
23+
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: []

confmap/expand_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,18 @@ func TestResolverExpandUnsupportedScheme(t *testing.T) {
551551

552552
func TestResolverExpandStringValueInvalidReturnValue(t *testing.T) {
553553
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
554-
return NewRetrieved(map[string]any{"test": "localhost:${test:PORT}"})
554+
return NewRetrievedFromYAML([]byte(`test: "localhost:${test:PORT}"`))
555555
})
556556

557557
testProvider := newFakeProvider("test", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
558-
return NewRetrieved([]any{1243})
558+
return NewRetrievedFromYAML([]byte("[1243]"))
559559
})
560560

561561
resolver, err := NewResolver(ResolverSettings{URIs: []string{"input:"}, ProviderFactories: []ProviderFactory{provider, testProvider}, ConverterFactories: nil})
562562
require.NoError(t, err)
563563

564564
_, err = resolver.Resolve(context.Background())
565-
assert.EqualError(t, err, `expanding ${test:PORT}: expected convertable to string value type, got ['ӛ']([]interface {})`)
565+
assert.EqualError(t, err, `expanding ${test:PORT}: retrieved value does not have unambiguous string representation: [1243]`)
566566
}
567567

568568
func TestResolverDefaultProviderExpand(t *testing.T) {

confmap/internal/e2e/types_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ func TestTypeCasting(t *testing.T) {
132132
},
133133
}
134134

135+
previousValue := featuregates.StrictlyTypedInputGate.IsEnabled()
136+
err := featuregate.GlobalRegistry().Set(featuregates.StrictlyTypedInputID, false)
137+
require.NoError(t, err)
138+
defer func() {
139+
err := featuregate.GlobalRegistry().Set(featuregates.StrictlyTypedInputID, previousValue)
140+
require.NoError(t, err)
141+
}()
142+
135143
for _, tt := range values {
136144
t.Run(tt.value+"/"+string(tt.targetField), func(t *testing.T) {
137145
testFile := "types_expand.yaml"

exporter/otlpexporter/testdata/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ auth:
1818
authenticator: nop
1919
headers:
2020
"can you have a . here?": "F0000000-0000-0000-0000-000000000000"
21-
header1: 234
21+
header1: "234"
2222
another: "somevalue"
2323
keepalive:
2424
time: 20s

exporter/otlphttpexporter/testdata/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ retry_on_failure:
2020
max_elapsed_time: 10m
2121
headers:
2222
"can you have a . here?": "F0000000-0000-0000-0000-000000000000"
23-
header1: 234
23+
header1: "234"
2424
another: "somevalue"
2525
compression: gzip

internal/featuregates/featuregates.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var UseUnifiedEnvVarExpansionRules = featuregate.GlobalRegistry().MustRegister("
1313
const StrictlyTypedInputID = "confmap.strictlyTypedInput"
1414

1515
var StrictlyTypedInputGate = featuregate.GlobalRegistry().MustRegister(StrictlyTypedInputID,
16-
featuregate.StageAlpha,
16+
featuregate.StageBeta,
1717
featuregate.WithRegisterFromVersion("v0.103.0"),
1818
featuregate.WithRegisterDescription("Makes type casting rules during configuration unmarshaling stricter. See https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/env-vars.md for more details."),
1919
)

otelcol/unmarshaler_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestPipelineConfigUnmarshalError(t *testing.T) {
128128
},
129129
},
130130
}),
131-
expectError: "'[traces].receivers[0]' has invalid keys: nop",
131+
expectError: "'[traces].receivers': source data must be an array or slice, got map",
132132
},
133133
}
134134

0 commit comments

Comments
 (0)