diff --git a/.chloggen/elasticexporte-batcher.yaml b/.chloggen/elasticexporte-batcher.yaml new file mode 100644 index 0000000000000..93187386474fa --- /dev/null +++ b/.chloggen/elasticexporte-batcher.yaml @@ -0,0 +1,27 @@ +# 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. filelogreceiver) +component: elasticsearchexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Validate batcher config for exporter + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [38072] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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/elasticsearchexporter/config.go b/exporter/elasticsearchexporter/config.go index 3d4756d4ef32b..64cbd94fbd807 100644 --- a/exporter/elasticsearchexporter/config.go +++ b/exporter/elasticsearchexporter/config.go @@ -274,6 +274,11 @@ func (cfg *Config) Validate() error { if cfg.Retry.MaxRetries < 0 { return errors.New("retry::max_retries should be non-negative") } + if batcherCfg, ok := cfg.exporterbatcherConfig(); ok { + if err := batcherCfg.Validate(); err != nil { + return fmt.Errorf("invalid batcher config: %w", err) + } + } return nil } @@ -314,6 +319,18 @@ func (cfg *Config) endpoints() ([]string, error) { return endpoints, nil } +func (cfg *Config) exporterbatcherConfig() (exporterbatcher.Config, bool) { + if cfg.Batcher.Enabled == nil { + return exporterbatcher.Config{}, false + } + return exporterbatcher.Config{ + Enabled: *cfg.Batcher.Enabled, + FlushTimeout: cfg.Batcher.FlushTimeout, + MinSizeConfig: cfg.Batcher.MinSizeConfig, + MaxSizeConfig: cfg.Batcher.MaxSizeConfig, + }, true +} + func validateEndpoint(endpoint string) error { if endpoint == "" { return errConfigEmptyEndpoint diff --git a/exporter/elasticsearchexporter/config_test.go b/exporter/elasticsearchexporter/config_test.go index b432ed49f68de..076772386803f 100644 --- a/exporter/elasticsearchexporter/config_test.go +++ b/exporter/elasticsearchexporter/config_test.go @@ -425,6 +425,16 @@ func TestConfig_Validate(t *testing.T) { }), err: `must not specify both retry::max_requests and retry::max_retries`, }, + "batcher max_size_items less than min_size_items": { + config: withDefaultConfig(func(cfg *Config) { + cfg.Endpoints = []string{"http://test:9200"} + cfg.Batcher.MaxSizeItems = 1000 + cfg.Batcher.MinSizeItems = 2000 + enableBatcher := true + cfg.Batcher.Enabled = &enableBatcher + }), + err: `max_size_items must be greater than or equal to min_size_items`, + }, } for name, tt := range tests { diff --git a/exporter/elasticsearchexporter/factory.go b/exporter/elasticsearchexporter/factory.go index e367ba59b2a29..811fe8313237f 100644 --- a/exporter/elasticsearchexporter/factory.go +++ b/exporter/elasticsearchexporter/factory.go @@ -201,14 +201,8 @@ func exporterhelperOptions( exporterhelper.WithShutdown(shutdown), exporterhelper.WithQueue(cfg.QueueSettings), } - if cfg.Batcher.Enabled != nil { - batcherConfig := exporterbatcher.Config{ - Enabled: *cfg.Batcher.Enabled, - FlushTimeout: cfg.Batcher.FlushTimeout, - MinSizeConfig: cfg.Batcher.MinSizeConfig, - MaxSizeConfig: cfg.Batcher.MaxSizeConfig, - } - opts = append(opts, exporterhelper.WithBatcher(batcherConfig)) + if batcherCfg, ok := cfg.exporterbatcherConfig(); ok { + opts = append(opts, exporterhelper.WithBatcher(batcherCfg)) // Effectively disable timeout_sender because timeout is enforced in bulk indexer. //