From 109173d9cf841f1fac2a873b5d22ad6f88ab6398 Mon Sep 17 00:00:00 2001 From: Dmitrii Anoshin Date: Fri, 3 May 2024 09:40:40 -0700 Subject: [PATCH] [exporterhelper] Fix `enabled` config option for batch sender (#10076) `enabled` config option for batch sender was ignored. This PR fixes it. --- .../batch-sender-fix-enabled-config.yaml | 20 +++++++++++++++++++ exporter/exporterhelper/batch_sender_test.go | 4 ++-- exporter/exporterhelper/common.go | 4 ++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .chloggen/batch-sender-fix-enabled-config.yaml diff --git a/.chloggen/batch-sender-fix-enabled-config.yaml b/.chloggen/batch-sender-fix-enabled-config.yaml new file mode 100644 index 00000000000..5e0b5b8cbf2 --- /dev/null +++ b/.chloggen/batch-sender-fix-enabled-config.yaml @@ -0,0 +1,20 @@ +# 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. otlpreceiver) +component: exporterhelper + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix enabled config option for batch sender + +# One or more tracking issues or pull requests related to the change +issues: [10076] + +# 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/exporterhelper/batch_sender_test.go b/exporter/exporterhelper/batch_sender_test.go index 5ea63c7d820..15d05b066f4 100644 --- a/exporter/exporterhelper/batch_sender_test.go +++ b/exporter/exporterhelper/batch_sender_test.go @@ -208,7 +208,7 @@ func TestBatchSender_Shutdown(t *testing.T) { func TestBatchSender_Disabled(t *testing.T) { cfg := exporterbatcher.NewDefaultConfig() cfg.Enabled = false - cfg.MaxSizeItems = 10 + cfg.MaxSizeItems = 5 be, err := newBaseExporter(defaultSettings, defaultType, newNoopObsrepSender, WithBatcher(cfg, WithRequestBatchFuncs(fakeBatchMergeFunc, fakeBatchMergeSplitFunc))) require.NotNil(t, be) @@ -220,7 +220,7 @@ func TestBatchSender_Disabled(t *testing.T) { }) sink := newFakeRequestSink() - // should be sent right away because batching is disabled. + // should be sent right away without splitting because batching is disabled. require.NoError(t, be.send(context.Background(), &fakeRequest{items: 8, sink: sink})) assert.Equal(t, uint64(1), sink.requestsCount.Load()) assert.Equal(t, uint64(8), sink.itemsCount.Load()) diff --git a/exporter/exporterhelper/common.go b/exporter/exporterhelper/common.go index 267656b4051..aa84e9019f2 100644 --- a/exporter/exporterhelper/common.go +++ b/exporter/exporterhelper/common.go @@ -172,6 +172,10 @@ func WithRequestBatchFuncs(mf exporterbatcher.BatchMergeFunc[Request], msf expor // until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved. func WithBatcher(cfg exporterbatcher.Config, opts ...BatcherOption) Option { return func(o *baseExporter) error { + if !cfg.Enabled { + return nil + } + bs := newBatchSender(cfg, o.set, o.batchMergeFunc, o.batchMergeSplitfunc) for _, opt := range opts { if err := opt(bs); err != nil {