Closed
Description
Component(s)
pkg/stanza
What happened?
Description
The TimeParser
struct seems to ignore the original configuration if the struct was initialized with something other than the default values:
opentelemetry-collector-contrib/pkg/stanza/operator/helper/time.go
Lines 49 to 57 in b25b78a
Steps to Reproduce
This test reproduces it
func TestUnmarshal(t *testing.T) {
conf := confmap.NewFromStringMap(map[string]any{
"location": "America/Shiprock",
})
tp := TimeParser{
Layout: "1/2/2006 15:04:05",
}
require.NoError(t, tp.Unmarshal(conf))
assert.Equal(t, "America/Shiprock", tp.Location) // ok
assert.Equal(t, "strptime", tp.LayoutType) // ok, although weird
assert.Equal(t, "1/2/2006 15:04:05", tp.Layout) // FAIL --> empty
}
Expected Result
All assertions pass
Actual Result
The last assertion fails
Collector version
Tested as of b25b78a
Environment information
No response
OpenTelemetry Collector configuration
No response
Log output
No response
Additional context
I think NewTimeParser
should be part of the default configuration of time parser instead of this, and we should do the 'set to nil' trick from https://github.com/open-telemetry/opentelemetry-collector/blob/c72092e00151ce8e4cfef32c73b3a80d54076278/receiver/otlpreceiver/config.go#L68-L70 if we want to only set default config if the key exists.
Activity