From 675e968d2099d63e09685058980868d41ebfb79b Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Fri, 21 Feb 2025 17:56:45 +0100 Subject: [PATCH] [exporter/coralogix] Add new batch options to Coralogix exporter (#38082) #### Description Add batching capabilities to the Coralogix exporter. #### Link to tracking issue Fixes #38081 Signed-off-by: Israel Blancas --- ...1-add-new-batching-coralogix-exporter.yaml | 42 +++++++++++++++ exporter/coralogixexporter/config.go | 5 ++ exporter/coralogixexporter/config_test.go | 51 +++++++++++++++++++ exporter/coralogixexporter/factory.go | 13 ++++- .../coralogixexporter/testdata/config.yaml | 5 ++ 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 .chloggen/38081-add-new-batching-coralogix-exporter.yaml diff --git a/.chloggen/38081-add-new-batching-coralogix-exporter.yaml b/.chloggen/38081-add-new-batching-coralogix-exporter.yaml new file mode 100644 index 000000000000..7652d5f3e333 --- /dev/null +++ b/.chloggen/38081-add-new-batching-coralogix-exporter.yaml @@ -0,0 +1,42 @@ +# 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: coralogixexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add new batching capabilities to the Coralogix exporter. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [38081] + +# (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: | + This change adds a new batching capabilities to the Coralogix exporter. + This change is triggered by https://github.com/open-telemetry/opentelemetry-collector/issues/8122. + + The new batching capabilities are disabled by default. + To enable them, you need to set the following configuration: + + ```yaml + exporters: + coralogix: + batcher: + enabled: true # Enable batching + flush_timeout: 3s # Flush timeout + min_size_items: 8888 # Minimum number of items to flush + max_size_items: 10000 # Maximum number of items to batch + ``` + +# 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: [] diff --git a/exporter/coralogixexporter/config.go b/exporter/coralogixexporter/config.go index 290630ad0122..b1eb7f9de3aa 100644 --- a/exporter/coralogixexporter/config.go +++ b/exporter/coralogixexporter/config.go @@ -10,6 +10,7 @@ import ( "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configopaque" "go.opentelemetry.io/collector/config/configretry" + "go.opentelemetry.io/collector/exporter/exporterbatcher" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/pdata/pcommon" ) @@ -59,6 +60,10 @@ type Config struct { // Default Coralogix application and subsystem name values. AppName string `mapstructure:"application_name"` SubSystem string `mapstructure:"subsystem_name"` + + // Reference: + // https://github.com/open-telemetry/opentelemetry-collector/issues/8122 + BatcherConfig exporterbatcher.Config `mapstructure:"batcher"` } func isEmpty(endpoint string) bool { diff --git a/exporter/coralogixexporter/config_test.go b/exporter/coralogixexporter/config_test.go index 82a9d49f66cc..24e68b8507db 100644 --- a/exporter/coralogixexporter/config_test.go +++ b/exporter/coralogixexporter/config_test.go @@ -7,6 +7,7 @@ import ( "context" "path/filepath" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -19,6 +20,7 @@ import ( "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/confmap/xconfmap" + "go.opentelemetry.io/collector/exporter/exporterbatcher" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/exporter/exportertest" "go.opentelemetry.io/collector/pdata/pcommon" @@ -89,6 +91,13 @@ func TestLoadConfig(t *testing.T) { }, BalancerName: "", }, + BatcherConfig: exporterbatcher.Config{ + Enabled: false, + FlushTimeout: 200 * time.Millisecond, + MinSizeConfig: exporterbatcher.MinSizeConfig{ + MinSizeItems: 8192, + }, + }, }, }, { @@ -146,6 +155,13 @@ func TestLoadConfig(t *testing.T) { }, BalancerName: "", }, + BatcherConfig: exporterbatcher.Config{ + Enabled: true, + FlushTimeout: 3 * time.Second, + MinSizeConfig: exporterbatcher.MinSizeConfig{ + MinSizeItems: 8888, + }, + }, }, }, } @@ -315,3 +331,38 @@ func TestGetMetadataFromResource(t *testing.T) { assert.Equal(t, "application", appName) assert.Equal(t, "subsystem", subSystemName) } + +func TestCreateExportersWithBatcher(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig().(*Config) + cfg.Domain = "localhost" + cfg.PrivateKey = "test-key" + cfg.AppName = "test-app" + cfg.BatcherConfig.Enabled = true + cfg.BatcherConfig.FlushTimeout = 1 * time.Second + cfg.BatcherConfig.MinSizeItems = 100 + + // Test traces exporter + t.Run("traces_with_batcher", func(t *testing.T) { + set := exportertest.NewNopSettingsWithType(metadata.Type) + exp, err := factory.CreateTraces(context.Background(), set, cfg) + require.NoError(t, err) + require.NotNil(t, exp) + }) + + // Test metrics exporter + t.Run("metrics_with_batcher", func(t *testing.T) { + set := exportertest.NewNopSettingsWithType(metadata.Type) + exp, err := factory.CreateMetrics(context.Background(), set, cfg) + require.NoError(t, err) + require.NotNil(t, exp) + }) + + // Test logs exporter + t.Run("logs_with_batcher", func(t *testing.T) { + set := exportertest.NewNopSettingsWithType(metadata.Type) + exp, err := factory.CreateLogs(context.Background(), set, cfg) + require.NoError(t, err) + require.NotNil(t, exp) + }) +} diff --git a/exporter/coralogixexporter/factory.go b/exporter/coralogixexporter/factory.go index 32cb576c165d..762d73b454c2 100644 --- a/exporter/coralogixexporter/factory.go +++ b/exporter/coralogixexporter/factory.go @@ -14,6 +14,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" "go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper" "go.opentelemetry.io/collector/exporter/xexporter" @@ -34,6 +35,9 @@ func NewFactory() exporter.Factory { } func createDefaultConfig() component.Config { + batcherConfig := exporterbatcher.NewDefaultConfig() + batcherConfig.Enabled = false + return &Config{ QueueSettings: exporterhelper.NewDefaultQueueConfig(), BackOffConfig: configretry.NewDefaultBackOffConfig(), @@ -59,8 +63,9 @@ func createDefaultConfig() component.Config { Endpoint: "https://", Compression: configcompression.TypeGzip, }, - PrivateKey: "", - AppName: "", + PrivateKey: "", + AppName: "", + BatcherConfig: batcherConfig, } } @@ -83,6 +88,7 @@ func createTraceExporter(ctx context.Context, set exporter.Settings, config comp exporterhelper.WithQueue(cfg.QueueSettings), exporterhelper.WithStart(exporter.start), exporterhelper.WithShutdown(exporter.shutdown), + exporterhelper.WithBatcher(cfg.BatcherConfig), ) } @@ -107,6 +113,7 @@ func createMetricsExporter( exporterhelper.WithQueue(oCfg.QueueSettings), exporterhelper.WithStart(oce.start), exporterhelper.WithShutdown(oce.shutdown), + exporterhelper.WithBatcher(oCfg.BatcherConfig), ) } @@ -131,6 +138,7 @@ func createLogsExporter( exporterhelper.WithQueue(oCfg.QueueSettings), exporterhelper.WithStart(oce.start), exporterhelper.WithShutdown(oce.shutdown), + exporterhelper.WithBatcher(oCfg.BatcherConfig), ) } @@ -155,5 +163,6 @@ func createProfilesExporter( exporterhelper.WithQueue(oCfg.QueueSettings), exporterhelper.WithStart(oce.start), exporterhelper.WithShutdown(oce.shutdown), + exporterhelper.WithBatcher(oCfg.BatcherConfig), ) } diff --git a/exporter/coralogixexporter/testdata/config.yaml b/exporter/coralogixexporter/testdata/config.yaml index 162c5839fc7d..d45bef5bc381 100644 --- a/exporter/coralogixexporter/testdata/config.yaml +++ b/exporter/coralogixexporter/testdata/config.yaml @@ -37,6 +37,11 @@ coralogix/all: application_name: "APP_NAME" subsystem_name: "SUBSYSTEM_NAME" timeout: 5s + batcher: + enabled: true + flush_timeout: 3s + min_size_items: 8888 + coralogix/domain: domain: "coralogix.com"