Skip to content

Commit 40cb530

Browse files
Deprecate BatcherConfig and WithBatcher in favor of the new QueueBatchConfig (#12748)
Signed-off-by: Alex Boten <[email protected]> Signed-off-by: Bogdan Drutu <[email protected]> Co-authored-by: Alex Boten <[email protected]>
1 parent f09817e commit 40cb530

File tree

11 files changed

+136
-56
lines changed

11 files changed

+136
-56
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: otlpexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Mark BatcherConfig as deprecated, use `sending_queue::batch` instead
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12726]
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+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [user]
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: exporterhelper
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecate BatcherConfig and WithBatcher in favor of the new QueueBatchConfig.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12748]
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+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

exporter/exporterbatcher/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
// Deprecated: [v0.123.0] use exporterhelper.BatcherConfig
11-
type Config = exporterhelper.BatcherConfig
11+
type Config = exporterhelper.BatcherConfig //nolint:staticcheck
1212

1313
// Deprecated: [v0.123.0] use exporterhelper.SizeConfig
1414
type SizeConfig = exporterhelper.SizeConfig
@@ -26,4 +26,4 @@ var SizerTypeItems = exporterhelper.RequestSizerTypeItems
2626
var SizerTypeBytes = exporterhelper.RequestSizerTypeBytes
2727

2828
// Deprecated: [v0.123.0] use exporterhelper.NewDefaultBatcherConfig
29-
var NewDefaultConfig = exporterhelper.NewDefaultBatcherConfig
29+
var NewDefaultConfig = exporterhelper.NewDefaultBatcherConfig //nolint:staticcheck

exporter/exporterhelper/internal/queue_sender.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ type SizeConfig struct {
125125
}
126126

127127
func (c *BatcherConfig) Validate() error {
128+
if !c.Enabled {
129+
return nil
130+
}
131+
128132
if c.FlushTimeout <= 0 {
129133
return errors.New("`flush_timeout` must be greater than zero")
130134
}
131135

132-
return nil
133-
}
134-
135-
func (c SizeConfig) Validate() error {
136136
if c.Sizer != request.SizerTypeItems {
137137
return fmt.Errorf("unsupported sizer type: %q", c.Sizer)
138138
}

exporter/exporterhelper/internal/queue_sender_test.go

+33-16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"errors"
99
"testing"
10+
"time"
1011

1112
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
@@ -71,31 +72,47 @@ func TestBatcherConfig_Validate(t *testing.T) {
7172
}
7273

7374
func TestSizeConfig_Validate(t *testing.T) {
74-
cfg := SizeConfig{
75-
Sizer: request.SizerTypeBytes,
76-
MaxSize: 10,
77-
MinSize: 100,
75+
cfg := BatcherConfig{
76+
Enabled: true,
77+
FlushTimeout: 200 * time.Millisecond,
78+
SizeConfig: SizeConfig{
79+
Sizer: request.SizerTypeBytes,
80+
MinSize: 100,
81+
MaxSize: 1000,
82+
},
7883
}
7984
require.EqualError(t, cfg.Validate(), "unsupported sizer type: {\"bytes\"}")
8085

81-
cfg = SizeConfig{
82-
Sizer: request.SizerTypeItems,
83-
MaxSize: -100,
84-
MinSize: 100,
86+
cfg = BatcherConfig{
87+
Enabled: true,
88+
FlushTimeout: 200 * time.Millisecond,
89+
SizeConfig: SizeConfig{
90+
Sizer: request.SizerTypeItems,
91+
MinSize: 100,
92+
MaxSize: -1000,
93+
},
8594
}
8695
require.EqualError(t, cfg.Validate(), "`max_size` must be greater than or equal to zero")
8796

88-
cfg = SizeConfig{
89-
Sizer: request.SizerTypeItems,
90-
MaxSize: 100,
91-
MinSize: -100,
97+
cfg = BatcherConfig{
98+
Enabled: true,
99+
FlushTimeout: 200 * time.Millisecond,
100+
SizeConfig: SizeConfig{
101+
Sizer: request.SizerTypeItems,
102+
MinSize: -100,
103+
MaxSize: 1000,
104+
},
92105
}
93106
require.EqualError(t, cfg.Validate(), "`min_size` must be greater than or equal to zero")
94107

95-
cfg = SizeConfig{
96-
Sizer: request.SizerTypeItems,
97-
MaxSize: 100,
98-
MinSize: 200,
108+
cfg = BatcherConfig{
109+
Enabled: true,
110+
FlushTimeout: 200 * time.Millisecond,
111+
SizeConfig: SizeConfig{
112+
Sizer: request.SizerTypeItems,
113+
MinSize: 1000,
114+
MaxSize: 100,
115+
},
99116
}
100117
require.EqualError(t, cfg.Validate(), "`max_size` must be greater than or equal to mix_size")
101118
}

exporter/exporterhelper/queue_batch.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@ func WithQueue(config QueueBatchConfig) Option {
2323
return internal.WithQueue(config)
2424
}
2525

26-
// WithBatcher enables batching for an exporter based on custom request types.
27-
// For now, it can be used only with the New[Traces|Metrics|Logs]RequestExporter exporter helpers and
28-
// WithRequestBatchFuncs provided.
29-
// This API is at the early stage of development and may change without backward compatibility
30-
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
26+
// Deprecated: [v0.123.0] use WithQueueBatch.
3127
func WithBatcher(cfg BatcherConfig) Option {
3228
return internal.WithBatcher(cfg)
3329
}
3430

3531
// QueueBatchConfig defines configuration for queueing and batching for the exporter.
3632
type QueueBatchConfig = queuebatch.Config
3733

34+
// BatchConfig defines a configuration for batching requests based on a timeout and a minimum number of items.
35+
type BatchConfig = queuebatch.BatchConfig
36+
3837
// QueueBatchEncoding defines the encoding to be used if persistent queue is configured.
3938
// Duplicate definition with queuebatch.Encoding since aliasing generics is not supported by default.
4039
type QueueBatchEncoding[T any] interface {
@@ -63,14 +62,13 @@ func WithQueueBatch(cfg QueueBatchConfig, set QueueBatchSettings) Option {
6362
// By default, the queue stores 1000 items of telemetry and is non-blocking when full.
6463
var NewDefaultQueueConfig = internal.NewDefaultQueueConfig
6564

66-
// BatcherConfig defines a configuration for batching requests based on a timeout and a minimum number of items.
67-
// Experimental: This API is at the early stage of development and may change without backward compatibility
68-
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
65+
// Deprecated: [v0.123.0] use WithQueueBatch.
6966
type BatcherConfig = internal.BatcherConfig
7067

7168
// SizeConfig sets the size limits for a batch.
7269
// Experimental: This API is at the early stage of development and may change without backward compatibility
7370
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
7471
type SizeConfig = internal.SizeConfig
7572

73+
// Deprecated: [v0.123.0] use WithQueueBatch.
7674
var NewDefaultBatcherConfig = internal.NewDefaultBatcherConfig

exporter/otlpexporter/config.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"go.opentelemetry.io/collector/component"
1515
"go.opentelemetry.io/collector/config/configgrpc"
1616
"go.opentelemetry.io/collector/config/configretry"
17+
"go.opentelemetry.io/collector/confmap"
1718
"go.opentelemetry.io/collector/exporter/exporterhelper"
1819
)
1920

@@ -26,7 +27,26 @@ type Config struct {
2627

2728
// Experimental: This configuration is at the early stage of development and may change without backward compatibility
2829
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved
29-
BatcherConfig exporterhelper.BatcherConfig `mapstructure:"batcher"`
30+
//
31+
// Deprecated: [v0.123.0] batch configuration moving to queue configuration.
32+
BatcherConfig exporterhelper.BatcherConfig `mapstructure:"batcher"` //nolint:staticcheck
33+
34+
// remove at the same time as BatcherConfig
35+
hasBatcher bool
36+
}
37+
38+
func (c *Config) Unmarshal(conf *confmap.Conf) error {
39+
if conf.IsSet("batcher") {
40+
c.BatcherConfig = exporterhelper.NewDefaultBatcherConfig() //nolint:staticcheck
41+
c.BatcherConfig.Enabled = false
42+
c.hasBatcher = true
43+
}
44+
45+
if err := conf.Unmarshal(c); err != nil {
46+
return err
47+
}
48+
49+
return nil
3050
}
3151

3252
func (c *Config) Validate() error {

exporter/otlpexporter/config_test.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,13 @@ func TestUnmarshalConfig(t *testing.T) {
5252
},
5353
QueueConfig: exporterhelper.QueueBatchConfig{
5454
Enabled: true,
55-
Sizer: exporterhelper.RequestSizerTypeRequests,
55+
Sizer: exporterhelper.RequestSizerTypeItems,
5656
NumConsumers: 2,
57-
QueueSize: 10,
58-
},
59-
BatcherConfig: exporterhelper.BatcherConfig{
60-
Enabled: true,
61-
FlushTimeout: 200 * time.Millisecond,
62-
SizeConfig: exporterhelper.SizeConfig{
63-
Sizer: exporterhelper.RequestSizerTypeItems,
64-
MinSize: 1000,
65-
MaxSize: 10000,
57+
QueueSize: 100000,
58+
Batch: &exporterhelper.BatchConfig{
59+
FlushTimeout: 200 * time.Millisecond,
60+
MinSize: 1000,
61+
MaxSize: 10000,
6662
},
6763
},
6864
ClientConfig: configgrpc.ClientConfig{

exporter/otlpexporter/factory.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ func NewFactory() exporter.Factory {
3131
}
3232

3333
func createDefaultConfig() component.Config {
34-
batcherCfg := exporterhelper.NewDefaultBatcherConfig()
35-
batcherCfg.Enabled = false
36-
3734
clientCfg := *configgrpc.NewDefaultClientConfig()
3835
// Default to gzip compression
3936
clientCfg.Compression = configcompression.TypeGzip
@@ -47,7 +44,6 @@ func createDefaultConfig() component.Config {
4744
TimeoutConfig: exporterhelper.NewDefaultTimeoutConfig(),
4845
RetryConfig: configretry.NewDefaultBackOffConfig(),
4946
QueueConfig: exporterhelper.NewDefaultQueueConfig(),
50-
BatcherConfig: batcherCfg,
5147
ClientConfig: clientCfg,
5248
}
5349
}
@@ -65,7 +61,7 @@ func createTraces(
6561
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
6662
exporterhelper.WithRetry(oCfg.RetryConfig),
6763
exporterhelper.WithQueue(oCfg.QueueConfig),
68-
exporterhelper.WithBatcher(oCfg.BatcherConfig),
64+
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
6965
exporterhelper.WithStart(oce.start),
7066
exporterhelper.WithShutdown(oce.shutdown),
7167
)
@@ -84,7 +80,7 @@ func createMetrics(
8480
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
8581
exporterhelper.WithRetry(oCfg.RetryConfig),
8682
exporterhelper.WithQueue(oCfg.QueueConfig),
87-
exporterhelper.WithBatcher(oCfg.BatcherConfig),
83+
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
8884
exporterhelper.WithStart(oce.start),
8985
exporterhelper.WithShutdown(oce.shutdown),
9086
)
@@ -103,7 +99,7 @@ func createLogs(
10399
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
104100
exporterhelper.WithRetry(oCfg.RetryConfig),
105101
exporterhelper.WithQueue(oCfg.QueueConfig),
106-
exporterhelper.WithBatcher(oCfg.BatcherConfig),
102+
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
107103
exporterhelper.WithStart(oce.start),
108104
exporterhelper.WithShutdown(oce.shutdown),
109105
)
@@ -122,7 +118,7 @@ func createProfilesExporter(
122118
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
123119
exporterhelper.WithRetry(oCfg.RetryConfig),
124120
exporterhelper.WithQueue(oCfg.QueueConfig),
125-
exporterhelper.WithBatcher(oCfg.BatcherConfig),
121+
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
126122
exporterhelper.WithStart(oce.start),
127123
exporterhelper.WithShutdown(oce.shutdown),
128124
)

exporter/otlpexporter/otlp.go

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ type baseExporter struct {
5353
func newExporter(cfg component.Config, set exporter.Settings) *baseExporter {
5454
oCfg := cfg.(*Config)
5555

56+
if oCfg.hasBatcher {
57+
set.TelemetrySettings.Logger.Warn("using deprecated field: batcher")
58+
}
59+
5660
userAgent := fmt.Sprintf("%s/%s (%s/%s)",
5761
set.BuildInfo.Description, set.BuildInfo.Version, runtime.GOOS, runtime.GOARCH)
5862

exporter/otlpexporter/testdata/config.yaml

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ tls:
55
timeout: 10s
66
sending_queue:
77
enabled: true
8+
sizer: "items"
89
num_consumers: 2
9-
queue_size: 10
10+
queue_size: 100000
11+
batch:
12+
flush_timeout: 200ms
13+
min_size: 1000
14+
max_size: 10000
1015
retry_on_failure:
1116
enabled: true
1217
initial_interval: 10s
1318
randomization_factor: 0.7
1419
multiplier: 1.3
1520
max_interval: 60s
1621
max_elapsed_time: 10m
17-
batcher:
18-
enabled: true
19-
flush_timeout: 200ms
20-
sizer: "items"
21-
min_size: 1000
22-
max_size: 10000
2322
auth:
2423
authenticator: nop
2524
headers:

0 commit comments

Comments
 (0)