Skip to content

Commit

Permalink
[chore] reuse struct when parsing to avoid recursive parsing (#31727)
Browse files Browse the repository at this point in the history
**Description:** 
This is a companion PR to handle recursive state of unmarshalers with
open-telemetry/opentelemetry-collector#9750.
Changing this behavior will allow the confmap.Conf object to recognize
that it has already run the `Unmarshal` method on the struct, and run
the mapstructure decoding of fields.
  • Loading branch information
atoulme authored Mar 27, 2024
1 parent f29d215 commit b6868b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions exporter/datadogexporter/config_warnings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
)

Expand Down Expand Up @@ -79,7 +80,7 @@ func TestSendAggregations(t *testing.T) {
t.Run(testInstance.name, func(t *testing.T) {
f := NewFactory()
cfg := f.CreateDefaultConfig().(*Config)
err := cfg.Unmarshal(testInstance.cfgMap)
err := component.UnmarshalConfig(testInstance.cfgMap, cfg)
if err != nil || testInstance.err != "" {
assert.EqualError(t, err, testInstance.err)
} else {
Expand Down Expand Up @@ -156,7 +157,7 @@ func TestPeerTags(t *testing.T) {
t.Run(testInstance.name, func(t *testing.T) {
f := NewFactory()
cfg := f.CreateDefaultConfig().(*Config)
err := cfg.Unmarshal(testInstance.cfgMap)
err := component.UnmarshalConfig(testInstance.cfgMap, cfg)
if err != nil || testInstance.err != "" {
assert.EqualError(t, err, testInstance.err)
} else {
Expand Down
3 changes: 2 additions & 1 deletion exporter/datasetexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand All @@ -22,7 +23,7 @@ func TestConfigUnmarshalUnknownAttributes(t *testing.T) {
"api_key": "secret",
"unknown_attribute": "some value",
})
err := config.Unmarshal(configMap)
err := component.UnmarshalConfig(configMap, config)

unmarshalErr := fmt.Errorf("1 error(s) decoding:\n\n* '' has invalid keys: unknown_attribute")
expectedError := fmt.Errorf("cannot unmarshal config: %w", unmarshalErr)
Expand Down
2 changes: 1 addition & 1 deletion exporter/signalfxexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func TestUnmarshalExcludeMetrics(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.NoError(t, tt.cfg.Unmarshal(confmap.NewFromStringMap(map[string]any{})))
require.NoError(t, component.UnmarshalConfig(confmap.NewFromStringMap(map[string]any{}), tt.cfg))
assert.Len(t, tt.cfg.ExcludeMetrics, tt.excludeMetricsLen)
})
}
Expand Down

0 comments on commit b6868b1

Please sign in to comment.