Skip to content

Commit 76f52c5

Browse files
authored
[chore] fix code to support unmarshaling with embedded struct support (#31406)
**Description:** Code changes required to make open-telemetry/opentelemetry-collector#9635 pass.
1 parent 2b74c37 commit 76f52c5

File tree

6 files changed

+4
-16
lines changed

6 files changed

+4
-16
lines changed

cmd/mdatagen/metricdata.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (d *gauge) Unmarshal(parser *confmap.Conf) error {
125125
if err := d.MetricValueType.Unmarshal(parser); err != nil {
126126
return err
127127
}
128-
return parser.Unmarshal(d)
128+
return parser.Unmarshal(d, confmap.WithIgnoreUnused())
129129
}
130130

131131
func (d gauge) Type() string {
@@ -155,7 +155,7 @@ func (d *sum) Unmarshal(parser *confmap.Conf) error {
155155
if err := d.MetricValueType.Unmarshal(parser); err != nil {
156156
return err
157157
}
158-
return parser.Unmarshal(d)
158+
return parser.Unmarshal(d, confmap.WithIgnoreUnused())
159159
}
160160

161161
// TODO: Currently, this func will not be called because of https://github.com/open-telemetry/opentelemetry-collector/issues/6671. Uncomment function and

pkg/stanza/operator/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (c *Config) Unmarshal(component *confmap.Conf) error {
107107
}
108108

109109
builder := builderFunc()
110-
if err := component.Unmarshal(builder); err != nil {
110+
if err := component.Unmarshal(builder, confmap.WithIgnoreUnused()); err != nil {
111111
return fmt.Errorf("unmarshal to %s: %w", typeString, err)
112112
}
113113

pkg/stanza/operator/helper/time.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type TimeParser struct {
4848
// Unmarshal starting from default settings
4949
func (t *TimeParser) Unmarshal(component *confmap.Conf) error {
5050
cfg := NewTimeParser()
51-
err := component.Unmarshal(&cfg)
51+
err := component.Unmarshal(&cfg, confmap.WithIgnoreUnused())
5252
if err != nil {
5353
return err
5454
}

pkg/stanza/operator/parser/scope/config_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ func TestConfig(t *testing.T) {
3535
return cfg
3636
}(),
3737
},
38-
{
39-
Name: "no_nested",
40-
ExpectErr: true,
41-
},
4238
},
4339
}.Run(t)
4440
}

pkg/stanza/operator/parser/severity/config_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ func TestUnmarshal(t *testing.T) {
4646
return cfg
4747
}(),
4848
},
49-
{
50-
Name: "no_nested",
51-
ExpectErr: true,
52-
},
5349
},
5450
}.Run(t)
5551
}

pkg/stanza/operator/parser/time/config_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ func TestUnmarshal(t *testing.T) {
4949
return cfg
5050
}(),
5151
},
52-
{
53-
Name: "no_nested",
54-
ExpectErr: true,
55-
},
5652
},
5753
}.Run(t)
5854
}

0 commit comments

Comments
 (0)