Skip to content

queuebatch::Config overrides the default values for batch::sizer with sizer #13860

@lahsivjar

Description

@lahsivjar

Component(s)

exporter/exporterhelper

What happened?

Describe the bug

The bug occurs when a default value for batch is provided in the queuebatch::Config and occurs due to this piece of code in the Unmarshal method of the config. For example, if default values for batch are provided with the sizer set to bytes and the config yaml further sets something in the batch then the above code overrides the batch sizer to be the same as the queue sizer (even if it is empty or invalid) and then merges it with the default value overriding the default.

Steps to reproduce

func TestBatchConfigUnmarshal(t *testing.T) {
	cm := confmap.NewFromStringMap(map[string]any{
		"enabled": true,
		"sizer":   "requests",
		"batch": map[string]any{
			"flush_timeout": time.Minute,
		},
	})

	defCfg := Config{
		Batch: configoptional.Default(BatchConfig{
			Sizer: request.SizerTypeBytes,
		}),
	}
	require.NoError(t, cm.Unmarshal(&defCfg))
	assert.Equal(t, true, defCfg.Enabled)
	assert.Equal(t, request.SizerTypeBytes, defCfg.Batch.Get().Sizer)
}

Above test case fails with following error descirbing the bug:

|| 	Error:      	Not equal: 
|| 	            	expected: request.SizerType{val:"bytes"}
|| 	            	actual  : request.SizerType{val:"requests"}
|| 	            	
|| 	            	Diff:
|| 	            	--- Expected
|| 	            	+++ Actual
|| 	            	@@ -1,3 +1,3 @@
|| 	            	 (request.SizerType) {
|| 	            	- val: (string) (len=5) "bytes"
|| 	            	+ val: (string) (len=8) "requests"
|| 	            	 }
|| 	Test:       	TestBatchConfigUnmarshal

What did you expect to see?

Default should not be overridden if the provided config does not explicitly do so.

What did you see instead?

Defaults are overridden.

Collector version

v0.135.0

Environment information

Environment

OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

Log output

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions