Skip to content

Commit

Permalink
[exporter/coralogix] Add new batch options to Coralogix exporter (ope…
Browse files Browse the repository at this point in the history
…n-telemetry#38082)

#### Description
Add batching capabilities to the Coralogix exporter.

#### Link to tracking issue
Fixes open-telemetry#38081

Signed-off-by: Israel Blancas <iblancasa@gmail.com>
  • Loading branch information
iblancasa authored Feb 21, 2025
1 parent e85067d commit 675e968
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 2 deletions.
42 changes: 42 additions & 0 deletions .chloggen/38081-add-new-batching-coralogix-exporter.yaml
Original file line number Diff line number Diff line change
@@ -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: []
5 changes: 5 additions & 0 deletions exporter/coralogixexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
51 changes: 51 additions & 0 deletions exporter/coralogixexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -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"
Expand Down Expand Up @@ -89,6 +91,13 @@ func TestLoadConfig(t *testing.T) {
},
BalancerName: "",
},
BatcherConfig: exporterbatcher.Config{
Enabled: false,
FlushTimeout: 200 * time.Millisecond,
MinSizeConfig: exporterbatcher.MinSizeConfig{
MinSizeItems: 8192,
},
},
},
},
{
Expand Down Expand Up @@ -146,6 +155,13 @@ func TestLoadConfig(t *testing.T) {
},
BalancerName: "",
},
BatcherConfig: exporterbatcher.Config{
Enabled: true,
FlushTimeout: 3 * time.Second,
MinSizeConfig: exporterbatcher.MinSizeConfig{
MinSizeItems: 8888,
},
},
},
},
}
Expand Down Expand Up @@ -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)
})
}
13 changes: 11 additions & 2 deletions exporter/coralogixexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(),
Expand All @@ -59,8 +63,9 @@ func createDefaultConfig() component.Config {
Endpoint: "https://",
Compression: configcompression.TypeGzip,
},
PrivateKey: "",
AppName: "",
PrivateKey: "",
AppName: "",
BatcherConfig: batcherConfig,
}
}

Expand All @@ -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),
)
}

Expand All @@ -107,6 +113,7 @@ func createMetricsExporter(
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
)
}

Expand All @@ -131,6 +138,7 @@ func createLogsExporter(
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
)
}

Expand All @@ -155,5 +163,6 @@ func createProfilesExporter(
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
)
}
5 changes: 5 additions & 0 deletions exporter/coralogixexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 675e968

Please # to comment.