Skip to content

Commit 675e968

Browse files
authored
[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 <[email protected]>
1 parent e85067d commit 675e968

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: coralogixexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add new batching capabilities to the Coralogix exporter.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [38081]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
This change adds a new batching capabilities to the Coralogix exporter.
20+
This change is triggered by https://github.com/open-telemetry/opentelemetry-collector/issues/8122.
21+
22+
The new batching capabilities are disabled by default.
23+
To enable them, you need to set the following configuration:
24+
25+
```yaml
26+
exporters:
27+
coralogix:
28+
batcher:
29+
enabled: true # Enable batching
30+
flush_timeout: 3s # Flush timeout
31+
min_size_items: 8888 # Minimum number of items to flush
32+
max_size_items: 10000 # Maximum number of items to batch
33+
```
34+
35+
# If your change doesn't affect end users or the exported elements of any package,
36+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
37+
# Optional: The change log or logs in which this entry should be included.
38+
# e.g. '[user]' or '[user, api]'
39+
# Include 'user' if the change is relevant to end users.
40+
# Include 'api' if there is a change to a library API.
41+
# Default: '[user]'
42+
change_logs: []

exporter/coralogixexporter/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"go.opentelemetry.io/collector/config/configgrpc"
1111
"go.opentelemetry.io/collector/config/configopaque"
1212
"go.opentelemetry.io/collector/config/configretry"
13+
"go.opentelemetry.io/collector/exporter/exporterbatcher"
1314
"go.opentelemetry.io/collector/exporter/exporterhelper"
1415
"go.opentelemetry.io/collector/pdata/pcommon"
1516
)
@@ -59,6 +60,10 @@ type Config struct {
5960
// Default Coralogix application and subsystem name values.
6061
AppName string `mapstructure:"application_name"`
6162
SubSystem string `mapstructure:"subsystem_name"`
63+
64+
// Reference:
65+
// https://github.com/open-telemetry/opentelemetry-collector/issues/8122
66+
BatcherConfig exporterbatcher.Config `mapstructure:"batcher"`
6267
}
6368

6469
func isEmpty(endpoint string) bool {

exporter/coralogixexporter/config_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"path/filepath"
99
"testing"
10+
"time"
1011

1112
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
@@ -19,6 +20,7 @@ import (
1920
"go.opentelemetry.io/collector/config/configtls"
2021
"go.opentelemetry.io/collector/confmap/confmaptest"
2122
"go.opentelemetry.io/collector/confmap/xconfmap"
23+
"go.opentelemetry.io/collector/exporter/exporterbatcher"
2224
"go.opentelemetry.io/collector/exporter/exporterhelper"
2325
"go.opentelemetry.io/collector/exporter/exportertest"
2426
"go.opentelemetry.io/collector/pdata/pcommon"
@@ -89,6 +91,13 @@ func TestLoadConfig(t *testing.T) {
8991
},
9092
BalancerName: "",
9193
},
94+
BatcherConfig: exporterbatcher.Config{
95+
Enabled: false,
96+
FlushTimeout: 200 * time.Millisecond,
97+
MinSizeConfig: exporterbatcher.MinSizeConfig{
98+
MinSizeItems: 8192,
99+
},
100+
},
92101
},
93102
},
94103
{
@@ -146,6 +155,13 @@ func TestLoadConfig(t *testing.T) {
146155
},
147156
BalancerName: "",
148157
},
158+
BatcherConfig: exporterbatcher.Config{
159+
Enabled: true,
160+
FlushTimeout: 3 * time.Second,
161+
MinSizeConfig: exporterbatcher.MinSizeConfig{
162+
MinSizeItems: 8888,
163+
},
164+
},
149165
},
150166
},
151167
}
@@ -315,3 +331,38 @@ func TestGetMetadataFromResource(t *testing.T) {
315331
assert.Equal(t, "application", appName)
316332
assert.Equal(t, "subsystem", subSystemName)
317333
}
334+
335+
func TestCreateExportersWithBatcher(t *testing.T) {
336+
factory := NewFactory()
337+
cfg := factory.CreateDefaultConfig().(*Config)
338+
cfg.Domain = "localhost"
339+
cfg.PrivateKey = "test-key"
340+
cfg.AppName = "test-app"
341+
cfg.BatcherConfig.Enabled = true
342+
cfg.BatcherConfig.FlushTimeout = 1 * time.Second
343+
cfg.BatcherConfig.MinSizeItems = 100
344+
345+
// Test traces exporter
346+
t.Run("traces_with_batcher", func(t *testing.T) {
347+
set := exportertest.NewNopSettingsWithType(metadata.Type)
348+
exp, err := factory.CreateTraces(context.Background(), set, cfg)
349+
require.NoError(t, err)
350+
require.NotNil(t, exp)
351+
})
352+
353+
// Test metrics exporter
354+
t.Run("metrics_with_batcher", func(t *testing.T) {
355+
set := exportertest.NewNopSettingsWithType(metadata.Type)
356+
exp, err := factory.CreateMetrics(context.Background(), set, cfg)
357+
require.NoError(t, err)
358+
require.NotNil(t, exp)
359+
})
360+
361+
// Test logs exporter
362+
t.Run("logs_with_batcher", func(t *testing.T) {
363+
set := exportertest.NewNopSettingsWithType(metadata.Type)
364+
exp, err := factory.CreateLogs(context.Background(), set, cfg)
365+
require.NoError(t, err)
366+
require.NotNil(t, exp)
367+
})
368+
}

exporter/coralogixexporter/factory.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"go.opentelemetry.io/collector/config/configretry"
1515
"go.opentelemetry.io/collector/consumer"
1616
"go.opentelemetry.io/collector/exporter"
17+
"go.opentelemetry.io/collector/exporter/exporterbatcher"
1718
"go.opentelemetry.io/collector/exporter/exporterhelper"
1819
"go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper"
1920
"go.opentelemetry.io/collector/exporter/xexporter"
@@ -34,6 +35,9 @@ func NewFactory() exporter.Factory {
3435
}
3536

3637
func createDefaultConfig() component.Config {
38+
batcherConfig := exporterbatcher.NewDefaultConfig()
39+
batcherConfig.Enabled = false
40+
3741
return &Config{
3842
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
3943
BackOffConfig: configretry.NewDefaultBackOffConfig(),
@@ -59,8 +63,9 @@ func createDefaultConfig() component.Config {
5963
Endpoint: "https://",
6064
Compression: configcompression.TypeGzip,
6165
},
62-
PrivateKey: "",
63-
AppName: "",
66+
PrivateKey: "",
67+
AppName: "",
68+
BatcherConfig: batcherConfig,
6469
}
6570
}
6671

@@ -83,6 +88,7 @@ func createTraceExporter(ctx context.Context, set exporter.Settings, config comp
8388
exporterhelper.WithQueue(cfg.QueueSettings),
8489
exporterhelper.WithStart(exporter.start),
8590
exporterhelper.WithShutdown(exporter.shutdown),
91+
exporterhelper.WithBatcher(cfg.BatcherConfig),
8692
)
8793
}
8894

@@ -107,6 +113,7 @@ func createMetricsExporter(
107113
exporterhelper.WithQueue(oCfg.QueueSettings),
108114
exporterhelper.WithStart(oce.start),
109115
exporterhelper.WithShutdown(oce.shutdown),
116+
exporterhelper.WithBatcher(oCfg.BatcherConfig),
110117
)
111118
}
112119

@@ -131,6 +138,7 @@ func createLogsExporter(
131138
exporterhelper.WithQueue(oCfg.QueueSettings),
132139
exporterhelper.WithStart(oce.start),
133140
exporterhelper.WithShutdown(oce.shutdown),
141+
exporterhelper.WithBatcher(oCfg.BatcherConfig),
134142
)
135143
}
136144

@@ -155,5 +163,6 @@ func createProfilesExporter(
155163
exporterhelper.WithQueue(oCfg.QueueSettings),
156164
exporterhelper.WithStart(oce.start),
157165
exporterhelper.WithShutdown(oce.shutdown),
166+
exporterhelper.WithBatcher(oCfg.BatcherConfig),
158167
)
159168
}

exporter/coralogixexporter/testdata/config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ coralogix/all:
3737
application_name: "APP_NAME"
3838
subsystem_name: "SUBSYSTEM_NAME"
3939
timeout: 5s
40+
batcher:
41+
enabled: true
42+
flush_timeout: 3s
43+
min_size_items: 8888
44+
4045

4146
coralogix/domain:
4247
domain: "coralogix.com"

0 commit comments

Comments
 (0)