From 13f1e0fe5b8c34723b72e0b1677d2e48cf41e751 Mon Sep 17 00:00:00 2001 From: Dmitry Anoshin Date: Wed, 9 Jul 2025 21:06:48 -0700 Subject: [PATCH] [exporter/splunk_hec] Deprecate 'batcher' config for now Deprecate 'batcher' config with a warning, do not remove the section yet. --- .chloggen/deprecated-batcher-splunkhec.yaml | 20 ++++++++++ .chloggen/rm-batcher-splunk.yaml | 13 ++----- exporter/splunkhecexporter/config.go | 42 +++++++++++++++++++++ exporter/splunkhecexporter/config_test.go | 2 +- exporter/splunkhecexporter/factory.go | 13 +++++-- 5 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 .chloggen/deprecated-batcher-splunkhec.yaml diff --git a/.chloggen/deprecated-batcher-splunkhec.yaml b/.chloggen/deprecated-batcher-splunkhec.yaml new file mode 100644 index 0000000000000..043eb04f11cc1 --- /dev/null +++ b/.chloggen/deprecated-batcher-splunkhec.yaml @@ -0,0 +1,20 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: splunkhecexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Update 'batcher' config to use internal deprecated struct instead of the one removed from the core. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [41224] + +# 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: [api] diff --git a/.chloggen/rm-batcher-splunk.yaml b/.chloggen/rm-batcher-splunk.yaml index afc2038d1405d..85a216c690abe 100644 --- a/.chloggen/rm-batcher-splunk.yaml +++ b/.chloggen/rm-batcher-splunk.yaml @@ -1,21 +1,14 @@ -# Use this changelog template to create an entry for release notes. - # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' -change_type: breaking +change_type: deprecation # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) component: splunkhecexporter # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Remove deprecated batcher config for splunkhecexporter, use sending_queue::batch +note: Deprecate 'batcher' config, use 'sending_queue::batch' instead # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. -issues: [39961] - -# (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: +issues: [41224] # 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. diff --git a/exporter/splunkhecexporter/config.go b/exporter/splunkhecexporter/config.go index 803ccfa5274e3..695016dc213ec 100644 --- a/exporter/splunkhecexporter/config.go +++ b/exporter/splunkhecexporter/config.go @@ -13,6 +13,7 @@ import ( "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configopaque" "go.opentelemetry.io/collector/config/configretry" + "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/exporter/exporterhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" @@ -62,11 +63,22 @@ type HecTelemetry struct { ExtraAttributes map[string]string `mapstructure:"extra_attributes"` } +type DeprecatedBatchConfig struct { + Enabled bool `mapstructure:"enabled"` + FlushTimeout time.Duration `mapstructure:"flush_timeout"` + Sizer exporterhelper.RequestSizerType `mapstructure:"sizer"` + MinSize int64 `mapstructure:"min_size"` + MaxSize int64 `mapstructure:"max_size"` + isSet bool `mapstructure:"-"` +} + // Config defines configuration for Splunk exporter. type Config struct { confighttp.ClientConfig `mapstructure:",squash"` QueueSettings exporterhelper.QueueBatchConfig `mapstructure:"sending_queue"` configretry.BackOffConfig `mapstructure:"retry_on_failure"` + // DeprecatedBatcher is the deprecated batcher configuration. + DeprecatedBatcher DeprecatedBatchConfig `mapstructure:"batcher"` // LogDataEnabled can be used to disable sending logs by the exporter. LogDataEnabled bool `mapstructure:"log_data_enabled"` @@ -140,6 +152,36 @@ type Config struct { Telemetry HecTelemetry `mapstructure:"telemetry"` } +func (cfg *Config) Unmarshal(conf *confmap.Conf) error { + if err := conf.Unmarshal(cfg); err != nil { + return err + } + if conf.IsSet("batcher") { + cfg.DeprecatedBatcher.isSet = true + if cfg.QueueSettings.Batch != nil { + return errors.New(`deprecated "batcher" cannot be set along with "sending_queue::batch"`) + } + if cfg.DeprecatedBatcher.Enabled { + cfg.QueueSettings.Batch = &exporterhelper.BatchConfig{ + FlushTimeout: cfg.DeprecatedBatcher.FlushTimeout, + // TODO: uncomment once core dependency is updated + // Sizer: cfg.DeprecatedBatcher.Sizer, + MinSize: cfg.DeprecatedBatcher.MinSize, + MaxSize: cfg.DeprecatedBatcher.MaxSize, + } + + // If the deprecated batcher is enabled without a queue, enable blocking queue to replicate the + // behavior of the deprecated batcher. + if !cfg.QueueSettings.Enabled { + cfg.QueueSettings.Enabled = true + cfg.QueueSettings.WaitForResult = true + } + } + } + + return nil +} + func (cfg *Config) getURL() (out *url.URL, err error) { out, err = url.Parse(cfg.Endpoint) if err != nil { diff --git a/exporter/splunkhecexporter/config_test.go b/exporter/splunkhecexporter/config_test.go index 542af2d88df82..206dcef7dedbc 100644 --- a/exporter/splunkhecexporter/config_test.go +++ b/exporter/splunkhecexporter/config_test.go @@ -242,7 +242,7 @@ func TestConfig_Validate(t *testing.T) { if tt.wantErr == "" { require.NoError(t, err) } else { - require.EqualError(t, err, tt.wantErr) + require.ErrorContains(t, err, tt.wantErr) } }) } diff --git a/exporter/splunkhecexporter/factory.go b/exporter/splunkhecexporter/factory.go index bfba12675362e..cb3b0d231445f 100644 --- a/exporter/splunkhecexporter/factory.go +++ b/exporter/splunkhecexporter/factory.go @@ -14,6 +14,7 @@ import ( "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" conventions "go.opentelemetry.io/otel/semconv/v1.27.0" + "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/splunkhecexporter/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" @@ -114,7 +115,7 @@ func createTracesExporter( config component.Config, ) (exporter.Traces, error) { cfg := config.(*Config) - + showDeprecationWarnings(cfg, set.Logger) c := newTracesClient(set, cfg) e, err := exporterhelper.NewTraces( @@ -147,7 +148,7 @@ func createMetricsExporter( config component.Config, ) (exporter.Metrics, error) { cfg := config.(*Config) - + showDeprecationWarnings(cfg, set.Logger) c := newMetricsClient(set, cfg) e, err := exporterhelper.NewMetrics( @@ -180,7 +181,7 @@ func createLogsExporter( config component.Config, ) (exporter exporter.Logs, err error) { cfg := config.(*Config) - + showDeprecationWarnings(cfg, set.Logger) c := newLogsClient(set, cfg) logsExporter, err := exporterhelper.NewLogs( @@ -211,3 +212,9 @@ func createLogsExporter( return wrapped, nil } + +func showDeprecationWarnings(cfg *Config, logger *zap.Logger) { + if cfg.DeprecatedBatcher.isSet { + logger.Warn("The 'batcher' field is deprecated and will be removed in a future release. Use 'sending_queue::batch' instead.") + } +}