Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .chloggen/deprecated-batcher-splunkhec.yaml
Original file line number Diff line number Diff line change
@@ -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]
13 changes: 3 additions & 10 deletions .chloggen/rm-batcher-splunk.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
42 changes: 42 additions & 0 deletions exporter/splunkhecexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion exporter/splunkhecexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down
13 changes: 10 additions & 3 deletions exporter/splunkhecexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.")
}
}