Skip to content

Commit

Permalink
Promote confmap.strictlyTypedInput feature gate to beta (#10554)
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

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 <223565+codeboten@users.noreply.github.com>
  • Loading branch information
mx-psi and codeboten authored Jul 12, 2024
1 parent 08b0be7 commit 6227646
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 7 deletions.
29 changes: 29 additions & 0 deletions .chloggen/mx-psi_enable-strict-types.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# 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: Promote `confmap.strictlyTypedInput` feature gate to beta.

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

# (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 feature gate changes the following:
- Configurations relying on the implicit type casting behaviors listed on [#9532](/~https://github.com/open-telemetry/opentelemetry-collector/issues/9532) will start to fail.
- 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.
# 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: []
6 changes: 3 additions & 3 deletions confmap/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,18 +551,18 @@ func TestResolverExpandUnsupportedScheme(t *testing.T) {

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

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

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

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

func TestResolverDefaultProviderExpand(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions confmap/internal/e2e/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ func TestTypeCasting(t *testing.T) {
},
}

previousValue := featuregates.StrictlyTypedInputGate.IsEnabled()
err := featuregate.GlobalRegistry().Set(featuregates.StrictlyTypedInputID, false)
require.NoError(t, err)
defer func() {
err := featuregate.GlobalRegistry().Set(featuregates.StrictlyTypedInputID, previousValue)
require.NoError(t, err)
}()

for _, tt := range values {
t.Run(tt.value+"/"+string(tt.targetField), func(t *testing.T) {
testFile := "types_expand.yaml"
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlpexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ auth:
authenticator: nop
headers:
"can you have a . here?": "F0000000-0000-0000-0000-000000000000"
header1: 234
header1: "234"
another: "somevalue"
keepalive:
time: 20s
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ retry_on_failure:
max_elapsed_time: 10m
headers:
"can you have a . here?": "F0000000-0000-0000-0000-000000000000"
header1: 234
header1: "234"
another: "somevalue"
compression: gzip
2 changes: 1 addition & 1 deletion internal/featuregates/featuregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var UseUnifiedEnvVarExpansionRules = featuregate.GlobalRegistry().MustRegister("
const StrictlyTypedInputID = "confmap.strictlyTypedInput"

var StrictlyTypedInputGate = featuregate.GlobalRegistry().MustRegister(StrictlyTypedInputID,
featuregate.StageAlpha,
featuregate.StageBeta,
featuregate.WithRegisterFromVersion("v0.103.0"),
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."),
)
Expand Down
2 changes: 1 addition & 1 deletion otelcol/unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestPipelineConfigUnmarshalError(t *testing.T) {
},
},
}),
expectError: "'[traces].receivers[0]' has invalid keys: nop",
expectError: "'[traces].receivers': source data must be an array or slice, got map",
},
}

Expand Down

0 comments on commit 6227646

Please sign in to comment.