-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[confmap] Add strict type validation under a feature gate #10400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8c72aed
85ed3db
3b6af6c
8e050e7
751c7f0
1ba8f79
e387a98
7bbc327
0e5adbe
79b92c9
027f342
1308967
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "Adds `confmap.Retrieved.AsString` method that returns the configuration value as a string" | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [9532] | ||
|
||
# (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: [api] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "Adds `confmap.NewRetrievedFromYAML` helper to create `confmap.Retrieved` values from YAML bytes" | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [9532] | ||
|
||
# (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: [api] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# 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: "Adds alpha `confmap.strictlyTypedInput` feature gate that enables strict type checks during configuration resolution" | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [9532] | ||
|
||
# (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: | | ||
When enabled, the configuration resolution system will: | ||
- Stop doing most kinds of implicit type casting when resolving configuration values | ||
- Use the original string representation of configuration values if the ${} syntax is used in inline position | ||
|
||
# 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: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -11,6 +11,8 @@ | |||
"regexp" | ||||
"strconv" | ||||
"strings" | ||||
|
||||
"go.opentelemetry.io/collector/confmap/internal" | ||||
) | ||||
|
||||
// schemePattern defines the regexp pattern for scheme names. | ||||
|
@@ -111,7 +113,12 @@ | |||
if uri == input { | ||||
// If the value is a single URI, then the return value can be anything. | ||||
// This is the case `foo: ${file:some_extra_config.yml}`. | ||||
expanded, err := mr.expandURI(ctx, input) | ||||
ret, err := mr.expandURI(ctx, input) | ||||
if err != nil { | ||||
return input, false, err | ||||
} | ||||
|
||||
expanded, err := ret.AsRaw() | ||||
if err != nil { | ||||
return input, false, err | ||||
} | ||||
|
@@ -121,16 +128,27 @@ | |||
if err != nil { | ||||
return input, false, err | ||||
} | ||||
repl, err := toString(expanded) | ||||
|
||||
var repl string | ||||
if internal.StrictlyTypedInputGate.IsEnabled() { | ||||
repl, err = expanded.AsString() | ||||
} else { | ||||
repl, err = toString(expanded) | ||||
} | ||||
if err != nil { | ||||
return input, false, fmt.Errorf("expanding %v: %w", uri, err) | ||||
} | ||||
return strings.ReplaceAll(input, uri, repl), true, err | ||||
} | ||||
|
||||
// toString attempts to convert input to a string. | ||||
func toString(input any) (string, error) { | ||||
func toString(ret *Retrieved) (string, error) { | ||||
// This list must be kept in sync with checkRawConfType. | ||||
input, err := ret.AsRaw() | ||||
if err != nil { | ||||
return "", err | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this covered by e2e tests as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no way to hit this path today opentelemetry-collector/confmap/provider.go Line 152 in 48af1b8
|
||||
} | ||||
|
||||
val := reflect.ValueOf(input) | ||||
switch val.Kind() { | ||||
case reflect.String: | ||||
|
@@ -146,7 +164,7 @@ | |||
} | ||||
} | ||||
|
||||
func (mr *Resolver) expandURI(ctx context.Context, input string) (any, error) { | ||||
func (mr *Resolver) expandURI(ctx context.Context, input string) (*Retrieved, error) { | ||||
// strip ${ and } | ||||
uri := input[2 : len(input)-1] | ||||
|
||||
|
@@ -167,7 +185,7 @@ | |||
return nil, err | ||||
} | ||||
mr.closers = append(mr.closers, ret.Close) | ||||
return ret.AsRaw() | ||||
return ret, nil | ||||
} | ||||
|
||||
type location struct { | ||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.