Skip to content

Commit

Permalink
[confmap] Remove deprecated confmap.WithErrorUnused (#9503)
Browse files Browse the repository at this point in the history
**Description:**
Remove deprecated `confmap.WithErrorUnused`

**Link to tracking Issue:**
Fixes #9484

---------

Co-authored-by: Pablo Baeyens <pablo.baeyens@datadoghq.com>
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
  • Loading branch information
3 people committed Feb 8, 2024
1 parent b6d7aad commit cf51a35
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
25 changes: 25 additions & 0 deletions .chloggen/remove_withErrorUnused.yaml
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: 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: Remove deprecated `confmap.WithErrorUnused`

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

# (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]
4 changes: 2 additions & 2 deletions cmd/mdatagen/internal/metadata/generated_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (m *metric) Unmarshal(parser *confmap.Conf) error {
if !parser.IsSet("enabled") {
return errors.New("missing required field: `enabled`")
}
err := parser.Unmarshal(m, confmap.WithErrorUnused())
err := parser.Unmarshal(m)
if err != nil {
return err
}
Expand Down Expand Up @@ -253,7 +253,7 @@ func loadMetadata(filePath string) (metadata, error) {
}

md := metadata{ScopeName: scopeName(filePath), ShortFolderName: shortFolderName(filePath)}
if err := conf.Unmarshal(&md, confmap.WithErrorUnused()); err != nil {
if err := conf.Unmarshal(&md); err != nil {
return md, err
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/mdatagen/metricdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (d *gauge) Unmarshal(parser *confmap.Conf) error {
if err := d.MetricValueType.Unmarshal(parser); err != nil {
return err
}
return parser.Unmarshal(d, confmap.WithErrorUnused())
return parser.Unmarshal(d)
}

func (d gauge) Type() string {
Expand Down Expand Up @@ -155,7 +155,7 @@ func (d *sum) Unmarshal(parser *confmap.Conf) error {
if err := d.MetricValueType.Unmarshal(parser); err != nil {
return err
}
return parser.Unmarshal(d, confmap.WithErrorUnused())
return parser.Unmarshal(d)
}

// TODO: Currently, this func will not be called because of https://github.com/open-telemetry/opentelemetry-collector/issues/6671. Uncomment function and
Expand All @@ -166,7 +166,7 @@ func (d *sum) Unmarshal(parser *confmap.Conf) error {
// if !parser.IsSet("monotonic") {
// return errors.New("missing required field: `monotonic`")
// }
// return parser.Unmarshal(m, confmap.WithErrorUnused())
// return parser.Unmarshal(m)
// }

func (d sum) Type() string {
Expand Down
4 changes: 2 additions & 2 deletions cmd/mdatagen/templates/config.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error {
if parser == nil {
return nil
}
err := parser.Unmarshal(ms, confmap.WithErrorUnused())
err := parser.Unmarshal(ms)
if err != nil {
return err
}
Expand Down Expand Up @@ -57,7 +57,7 @@ func (rac *ResourceAttributeConfig) Unmarshal(parser *confmap.Conf) error {
if parser == nil {
return nil
}
err := parser.Unmarshal(rac, confmap.WithErrorUnused())
err := parser.Unmarshal(rac)
if err != nil {
return err
}
Expand Down
10 changes: 0 additions & 10 deletions confmap/confmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ type unmarshalOption struct {
ignoreUnused bool
}

// WithErrorUnused sets an option to error when there are existing
// keys in the original Conf that were unused in the decoding process
// (extra keys). This option is enabled by default and can be disabled with `WithIgnoreUnused`.
// Deprecated: [v0.92.0] this is now enabled by default. Use `WithIgnoreUnused` to disable.
func WithErrorUnused() UnmarshalOption {
return unmarshalOptionFunc(func(uo *unmarshalOption) {
uo.ignoreUnused = false
})
}

// WithIgnoreUnused sets an option to ignore errors if existing
// keys in the original Conf were unused in the decoding process
// (extra keys).
Expand Down
2 changes: 1 addition & 1 deletion confmap/confmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestExpandNilStructPointersHookFuncDefaultNotNilConfigNil(t *testing.T) {
assert.Equal(t, &Struct{}, cfg.MapStruct["struct"])
}

func TestUnmarshalWithErrorUnused(t *testing.T) {
func TestUnmarshalWithIgnoreUnused(t *testing.T) {
stringMap := map[string]any{
"boolean": true,
"string": "this is a string",
Expand Down

0 comments on commit cf51a35

Please sign in to comment.