diff --git a/.chloggen/12948.yaml b/.chloggen/12948.yaml new file mode 100644 index 00000000000..3720992bedb --- /dev/null +++ b/.chloggen/12948.yaml @@ -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: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: exporterhelper + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Add validation error for batch config if min_size is greater than queue_size." + +# One or more tracking issues or pull requests related to the change +issues: [12948] + +# (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: [] diff --git a/exporter/exporterhelper/internal/queuebatch/config.go b/exporter/exporterhelper/internal/queuebatch/config.go index 0f6ad218899..8e19c3c7c40 100644 --- a/exporter/exporterhelper/internal/queuebatch/config.go +++ b/exporter/exporterhelper/internal/queuebatch/config.go @@ -92,9 +92,16 @@ func (cfg *Config) Validate() error { return errors.New("persistent queue configured with `storage` only supports `requests` sizer") } - // Only support items sizer for batch at this moment. - if cfg.Batch != nil && (cfg.Sizer != request.SizerTypeItems && cfg.Sizer != request.SizerTypeBytes) { - return errors.New("`batch` supports only `items` or `bytes` sizer") + if cfg.Batch != nil { + // Only support items or bytes sizer for batch at this moment. + if cfg.Sizer != request.SizerTypeItems && cfg.Sizer != request.SizerTypeBytes { + return errors.New("`batch` supports only `items` or `bytes` sizer") + } + + // Avoid situations where the queue is not able to hold any data. + if cfg.Batch.MinSize > cfg.QueueSize { + return errors.New("`min_size` must be less than or equal to `queue_size`") + } } return nil diff --git a/exporter/exporterhelper/internal/queuebatch/config_test.go b/exporter/exporterhelper/internal/queuebatch/config_test.go index 506a272b828..93490f8c902 100644 --- a/exporter/exporterhelper/internal/queuebatch/config_test.go +++ b/exporter/exporterhelper/internal/queuebatch/config_test.go @@ -50,6 +50,10 @@ func TestConfig_Validate(t *testing.T) { cfg.Sizer = request.SizerTypeRequests require.EqualError(t, cfg.Validate(), "`batch` supports only `items` or `bytes` sizer") + cfg = newTestConfig() + cfg.QueueSize = cfg.Batch.MinSize - 1 + require.EqualError(t, cfg.Validate(), "`min_size` must be less than or equal to `queue_size`") + cfg = newTestConfig() cfg.Sizer = request.SizerTypeBytes require.NoError(t, cfg.Validate())