-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[confmap] Store original string in confmap.Conf (#10618)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description <!-- Issue number if applicable --> - Adds new `expandedValue` struct that holds the original string representation if available for values resolved from a provider. - Removes any mention of `expandedValue` in the public API by adding a `sanitize` step before returning any `Get`s or `ToStringMap`s. - Adds new decoding hook that checks if the target field is of `string` type and uses the string representation in that case. #### Link to tracking issue Fixes #10605, Fixes #10405, Fixes #10659 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> This changes the behavior in some cases, I update the test cases. #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> | ENV value | ${ENV} before unification | ${ENV} in v0.105.0 (also ${env:ENV} before unification) | Value after this PR | |----------------------------|----------------------------|---------------------------------------------------------|----------------------------| | foo\nbar | foo\nbar | foo bar | foo\nbar | | 1111:1111:1111:1111:1111:: | 1111:1111:1111:1111:1111:: | **Error** | 1111:1111:1111:1111:1111:: | | "0123" | "0123" | 0123 | "0123" |
- Loading branch information
Showing
10 changed files
with
476 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 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: When passing configuration for a string field using any provider, use the verbatim string representation as the value. | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [10605, 10405] | ||
|
||
# (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 matches the behavior of `${ENV}` syntax prior to the promotion of the `confmap.unifyEnvVarExpansion` feature gate | ||
to beta. It changes the behavior of the `${env:ENV}` syntax with escaped strings. | ||
# 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: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2etest | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// targetNested tests the following property: | ||
// > Passing a value of type T directly through an environment variable | ||
// > should be equivalent to passing it through a nested environment variable. | ||
func targetNested[T any](t *testing.T, value string) { | ||
resolver := NewResolver(t, "types_expand.yaml") | ||
|
||
// Use os.Setenv so we can check the error and return instead of failing the fuzzing. | ||
os.Setenv("ENV", "${env:ENV2}") // nolint:tenv | ||
defer os.Unsetenv("ENV") | ||
err := os.Setenv("ENV2", value) // nolint:tenv | ||
defer os.Unsetenv("ENV2") | ||
if err != nil { | ||
return | ||
} | ||
confNested, errResolveNested := resolver.Resolve(context.Background()) | ||
|
||
err = os.Setenv("ENV", value) // nolint:tenv | ||
if err != nil { | ||
return | ||
} | ||
confSimple, errResolveSimple := resolver.Resolve(context.Background()) | ||
require.Equal(t, errResolveNested, errResolveSimple) | ||
if errResolveNested != nil { | ||
return | ||
} | ||
|
||
var cfgNested TargetConfig[T] | ||
errNested := confNested.Unmarshal(cfgNested) | ||
|
||
var cfgSimple TargetConfig[T] | ||
errSimple := confSimple.Unmarshal(cfgSimple) | ||
|
||
require.Equal(t, errNested, errSimple) | ||
if errNested != nil { | ||
return | ||
} | ||
assert.Equal(t, cfgNested, cfgSimple) | ||
} | ||
|
||
// testStrings for fuzzing targets | ||
var testStrings = []string{ | ||
"123", | ||
"opentelemetry", | ||
"!!str 123", | ||
"\"0123\"", | ||
"\"", | ||
"1111:1111:1111:1111:1111::", | ||
"{field: value}", | ||
"0xdeadbeef", | ||
"0b101", | ||
"field:", | ||
"2006-01-02T15:04:05Z07:00", | ||
} | ||
|
||
func FuzzNestedString(f *testing.F) { | ||
for _, value := range testStrings { | ||
f.Add(value) | ||
} | ||
f.Fuzz(targetNested[string]) | ||
} | ||
|
||
func FuzzNestedInt(f *testing.F) { | ||
for _, value := range testStrings { | ||
f.Add(value) | ||
} | ||
f.Fuzz(targetNested[int]) | ||
} | ||
|
||
func FuzzNestedMap(f *testing.F) { | ||
for _, value := range testStrings { | ||
f.Add(value) | ||
} | ||
f.Fuzz(targetNested[map[string]any]) | ||
} |
Oops, something went wrong.