From df40aae48a3a3c5c7aefeaf9edc3533d463399e4 Mon Sep 17 00:00:00 2001 From: Eric L <100242256+splunkericl@users.noreply.github.com> Date: Fri, 3 May 2024 22:53:05 -0700 Subject: [PATCH] add batcher config to splunkhec exporter (#32563) **Description:** Add a new feature in splunk hec exporter - utilitize batching framework https://github.com/open-telemetry/opentelemetry-collector/pull/9738 in splunk hec exporter - adds batcher config in splunk hec exporter config and append it as exporter option if enabled **Link to tracking Issue:** Resolves https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32545 **Testing:** Added unit test for the config **Documentation:** Updated the README file --- .../exporter-splunkhec-addbatcherconfig.yaml | 27 +++++++++++++++++++ exporter/splunkhecexporter/README.md | 1 + exporter/splunkhecexporter/config.go | 5 ++++ exporter/splunkhecexporter/config_test.go | 11 ++++++++ exporter/splunkhecexporter/factory.go | 17 +++++++++--- .../splunkhecexporter/testdata/config.yaml | 5 ++++ 6 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 .chloggen/exporter-splunkhec-addbatcherconfig.yaml diff --git a/.chloggen/exporter-splunkhec-addbatcherconfig.yaml b/.chloggen/exporter-splunkhec-addbatcherconfig.yaml new file mode 100644 index 000000000000..19d2c256485d --- /dev/null +++ b/.chloggen/exporter-splunkhec-addbatcherconfig.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: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: exporter/splunkhec + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: add experimental exporter batcher config + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [32545] + +# (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: [user] diff --git a/exporter/splunkhecexporter/README.md b/exporter/splunkhecexporter/README.md index 57d17eff7466..51065bd7fd24 100644 --- a/exporter/splunkhecexporter/README.md +++ b/exporter/splunkhecexporter/README.md @@ -66,6 +66,7 @@ The following configuration options can also be configured: - `telemetry/enabled` (default: false): Specifies whether to enable telemetry inside splunk hec exporter. - `telemetry/override_metrics_names` (default: empty map): Specifies the metrics name to overrides in splunk hec exporter. - `telemetry/extra_attributes` (default: empty map): Specifies the extra metrics attributes in splunk hec exporter. +- `batcher`(Experimental, disabled by default): Specifies batching configuration on the exporter. Information about the configuration can be found [here](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md) In addition, this exporter offers queued retry which is enabled by default. Information about queued retry configuration parameters can be found diff --git a/exporter/splunkhecexporter/config.go b/exporter/splunkhecexporter/config.go index 9d2e73a722bc..168fb6aced26 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/exporter/exporterbatcher" "go.opentelemetry.io/collector/exporter/exporterhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" @@ -68,6 +69,10 @@ type Config struct { exporterhelper.QueueSettings `mapstructure:"sending_queue"` configretry.BackOffConfig `mapstructure:"retry_on_failure"` + // Experimental: This configuration is at the early stage of development and may change without backward compatibility + // until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved. + BatcherConfig exporterbatcher.Config `mapstructure:"batcher"` + // LogDataEnabled can be used to disable sending logs by the exporter. LogDataEnabled bool `mapstructure:"log_data_enabled"` diff --git a/exporter/splunkhecexporter/config_test.go b/exporter/splunkhecexporter/config_test.go index 996c59a27c39..5fcfd021cd18 100644 --- a/exporter/splunkhecexporter/config_test.go +++ b/exporter/splunkhecexporter/config_test.go @@ -16,6 +16,7 @@ import ( "go.opentelemetry.io/collector/config/configretry" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/confmap/confmaptest" + "go.opentelemetry.io/collector/exporter/exporterbatcher" "go.opentelemetry.io/collector/exporter/exporterhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/splunkhecexporter/internal/metadata" @@ -90,6 +91,16 @@ func TestLoadConfig(t *testing.T) { NumConsumers: 2, QueueSize: 10, }, + BatcherConfig: exporterbatcher.Config{ + Enabled: true, + FlushTimeout: time.Second, + MinSizeConfig: exporterbatcher.MinSizeConfig{ + MinSizeItems: 1, + }, + MaxSizeConfig: exporterbatcher.MaxSizeConfig{ + MaxSizeItems: 10, + }, + }, HecToOtelAttrs: splunk.HecToOtelAttrs{ Source: "mysource", SourceType: "mysourcetype", diff --git a/exporter/splunkhecexporter/factory.go b/exporter/splunkhecexporter/factory.go index b67baa3d4dce..56435c64ef6f 100644 --- a/exporter/splunkhecexporter/factory.go +++ b/exporter/splunkhecexporter/factory.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/collector/config/configretry" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/exporter/exporterbatcher" "go.opentelemetry.io/collector/exporter/exporterhelper" conventions "go.opentelemetry.io/collector/semconv/v1.6.1" @@ -58,6 +59,9 @@ func NewFactory() exporter.Factory { } func createDefaultConfig() component.Config { + batcherCfg := exporterbatcher.NewDefaultConfig() + batcherCfg.Enabled = false + defaultMaxConns := defaultMaxIdleCons defaultIdleConnTimeout := defaultIdleConnTimeout return &Config{ @@ -74,6 +78,7 @@ func createDefaultConfig() component.Config { SplunkAppName: defaultSplunkAppName, BackOffConfig: configretry.NewDefaultBackOffConfig(), QueueSettings: exporterhelper.NewDefaultQueueSettings(), + BatcherConfig: batcherCfg, DisableCompression: false, MaxContentLengthLogs: defaultContentLengthLogsLimit, MaxContentLengthMetrics: defaultContentLengthMetricsLimit, @@ -119,7 +124,9 @@ func createTracesExporter( exporterhelper.WithRetry(cfg.BackOffConfig), exporterhelper.WithQueue(cfg.QueueSettings), exporterhelper.WithStart(c.start), - exporterhelper.WithShutdown(c.stop)) + exporterhelper.WithShutdown(c.stop), + exporterhelper.WithBatcher(cfg.BatcherConfig), + ) if err != nil { return nil, err @@ -152,7 +159,9 @@ func createMetricsExporter( exporterhelper.WithRetry(cfg.BackOffConfig), exporterhelper.WithQueue(cfg.QueueSettings), exporterhelper.WithStart(c.start), - exporterhelper.WithShutdown(c.stop)) + exporterhelper.WithShutdown(c.stop), + exporterhelper.WithBatcher(cfg.BatcherConfig), + ) if err != nil { return nil, err } @@ -184,7 +193,9 @@ func createLogsExporter( exporterhelper.WithRetry(cfg.BackOffConfig), exporterhelper.WithQueue(cfg.QueueSettings), exporterhelper.WithStart(c.start), - exporterhelper.WithShutdown(c.stop)) + exporterhelper.WithShutdown(c.stop), + exporterhelper.WithBatcher(cfg.BatcherConfig), + ) if err != nil { return nil, err diff --git a/exporter/splunkhecexporter/testdata/config.yaml b/exporter/splunkhecexporter/testdata/config.yaml index c8d8b59489e2..54b7040dbf8d 100644 --- a/exporter/splunkhecexporter/testdata/config.yaml +++ b/exporter/splunkhecexporter/testdata/config.yaml @@ -26,6 +26,11 @@ splunk_hec/allsettings: initial_interval: 10s max_interval: 60s max_elapsed_time: 10m + batcher: + enabled: true + flush_timeout: 1s + min_size_items: 1 + max_size_items: 10 splunk_app_name: "OpenTelemetry-Collector Splunk Exporter" splunk_app_version: "v0.0.1" hec_metadata_to_otel_attrs: