From b29fff82e4edd7244a8f75c4ae7254b4cde0a9d2 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Thu, 20 Feb 2025 18:55:35 +0530 Subject: [PATCH 1/6] call validate on batcher --- exporter/elasticsearchexporter/config.go | 11 +++++++ exporter/elasticsearchexporter/config_test.go | 10 +++++++ otel.yml | 29 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 otel.yml diff --git a/exporter/elasticsearchexporter/config.go b/exporter/elasticsearchexporter/config.go index 3d4756d4ef32b..c4cdb300c847b 100644 --- a/exporter/elasticsearchexporter/config.go +++ b/exporter/elasticsearchexporter/config.go @@ -274,6 +274,17 @@ func (cfg *Config) Validate() error { if cfg.Retry.MaxRetries < 0 { return errors.New("retry::max_retries should be non-negative") } + if cfg.Batcher.Enabled != nil { + batcherConfig := exporterbatcher.Config{ + Enabled: *cfg.Batcher.Enabled, + FlushTimeout: cfg.Batcher.FlushTimeout, + MinSizeConfig: cfg.Batcher.MinSizeConfig, + MaxSizeConfig: cfg.Batcher.MaxSizeConfig, + } + if err := batcherConfig.Validate(); err != nil { + return err + } + } return nil } diff --git a/exporter/elasticsearchexporter/config_test.go b/exporter/elasticsearchexporter/config_test.go index d43aa21ac6e5f..22679dbb08abb 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/otel.yml b/otel.yml new file mode 100644 index 0000000000000..8443797187afd --- /dev/null +++ b/otel.yml @@ -0,0 +1,29 @@ +exporters: + elasticsearch: + endpoints: [https://7282951ca2294b1eb34e6bbe3a727140.us-central1.gcp.cloud.es.io:443] + timeout: 10s + username: fo + password: bar + sending_queue: + enabled: true + num_consumers: 2 + queue_size: 10 + batcher: + enabled: true + max_size_items: 1600 + min_size_items: 5000 + + +receivers: + otlp: + protocols: + http: + endpoint: "localhost:4318" + grpc: + endpoint: "localhost:4317" + +service: + pipelines: + logs: + receivers: [otlp] + exporters: [elasticsearch] From 8387a2fde9d45a339a36532dd969309c2a9d7ed3 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Thu, 20 Feb 2025 18:59:56 +0530 Subject: [PATCH 2/6] delete otel --- otel.yml | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 otel.yml diff --git a/otel.yml b/otel.yml deleted file mode 100644 index 8443797187afd..0000000000000 --- a/otel.yml +++ /dev/null @@ -1,29 +0,0 @@ -exporters: - elasticsearch: - endpoints: [https://7282951ca2294b1eb34e6bbe3a727140.us-central1.gcp.cloud.es.io:443] - timeout: 10s - username: fo - password: bar - sending_queue: - enabled: true - num_consumers: 2 - queue_size: 10 - batcher: - enabled: true - max_size_items: 1600 - min_size_items: 5000 - - -receivers: - otlp: - protocols: - http: - endpoint: "localhost:4318" - grpc: - endpoint: "localhost:4317" - -service: - pipelines: - logs: - receivers: [otlp] - exporters: [elasticsearch] From 95ee070d0759645930eb30b58d96865b146c4cc8 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Thu, 20 Feb 2025 19:04:24 +0530 Subject: [PATCH 3/6] changelog --- .chloggen/elasticexporte-batcher.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/elasticexporte-batcher.yaml diff --git a/.chloggen/elasticexporte-batcher.yaml b/.chloggen/elasticexporte-batcher.yaml new file mode 100644 index 0000000000000..7cc4472d35bb1 --- /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: Fix batcher validation 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: [] From fab6d5bc1820f767644bac5d5589cf9d5e9c47f3 Mon Sep 17 00:00:00 2001 From: Vihas Makwana <121151420+VihasMakwana@users.noreply.github.com> Date: Thu, 20 Feb 2025 20:17:57 +0530 Subject: [PATCH 4/6] Update .chloggen/elasticexporte-batcher.yaml Co-authored-by: Carson Ip --- .chloggen/elasticexporte-batcher.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/elasticexporte-batcher.yaml b/.chloggen/elasticexporte-batcher.yaml index 7cc4472d35bb1..93187386474fa 100644 --- a/.chloggen/elasticexporte-batcher.yaml +++ b/.chloggen/elasticexporte-batcher.yaml @@ -7,7 +7,7 @@ change_type: bug_fix component: elasticsearchexporter # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Fix batcher validation for exporter +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] From 068ab6d0daa3d211fa3e2b513c6f2e377383e24c Mon Sep 17 00:00:00 2001 From: Vihas Makwana <121151420+VihasMakwana@users.noreply.github.com> Date: Thu, 20 Feb 2025 20:28:58 +0530 Subject: [PATCH 5/6] Update exporter/elasticsearchexporter/config.go Co-authored-by: Carson Ip --- exporter/elasticsearchexporter/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/elasticsearchexporter/config.go b/exporter/elasticsearchexporter/config.go index c4cdb300c847b..8f6a09b309806 100644 --- a/exporter/elasticsearchexporter/config.go +++ b/exporter/elasticsearchexporter/config.go @@ -282,7 +282,7 @@ func (cfg *Config) Validate() error { MaxSizeConfig: cfg.Batcher.MaxSizeConfig, } if err := batcherConfig.Validate(); err != nil { - return err + return fmt.Errorf("invalid batcher config: %w", err) } } From 4b4f1b13fb2314a1e39644ea496381a71a255e4a Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Fri, 21 Feb 2025 14:18:37 +0530 Subject: [PATCH 6/6] helper method to convert to batcher config --- exporter/elasticsearchexporter/config.go | 22 ++++++++++++++-------- exporter/elasticsearchexporter/factory.go | 10 ++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/exporter/elasticsearchexporter/config.go b/exporter/elasticsearchexporter/config.go index 8f6a09b309806..64cbd94fbd807 100644 --- a/exporter/elasticsearchexporter/config.go +++ b/exporter/elasticsearchexporter/config.go @@ -274,14 +274,8 @@ func (cfg *Config) Validate() error { if cfg.Retry.MaxRetries < 0 { return errors.New("retry::max_retries should be non-negative") } - if cfg.Batcher.Enabled != nil { - batcherConfig := exporterbatcher.Config{ - Enabled: *cfg.Batcher.Enabled, - FlushTimeout: cfg.Batcher.FlushTimeout, - MinSizeConfig: cfg.Batcher.MinSizeConfig, - MaxSizeConfig: cfg.Batcher.MaxSizeConfig, - } - if err := batcherConfig.Validate(); err != nil { + if batcherCfg, ok := cfg.exporterbatcherConfig(); ok { + if err := batcherCfg.Validate(); err != nil { return fmt.Errorf("invalid batcher config: %w", err) } } @@ -325,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/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. //