Skip to content

Commit 3a14a05

Browse files
committed
Deprecate BatcherConfig and WithBatcher in favor of the new QueueBatchConfig
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 47a29f7 commit 3a14a05

File tree

9 files changed

+87
-54
lines changed

9 files changed

+87
-54
lines changed

.chloggen/codeboten_deprecate-batcher-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ subtext:
2222
# Include 'user' if the change is relevant to end users.
2323
# Include 'api' if there is a change to a library API.
2424
# Default: '[user]'
25-
change_logs: []
25+
change_logs: []
+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/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

+5-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,9 +62,7 @@ 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.

exporter/otlpexporter/config.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,22 @@ type Config struct {
3030
//
3131
// Deprecated: [v0.123.0] batch configuration moving to queue configuration.
3232
BatcherConfig exporterhelper.BatcherConfig `mapstructure:"batcher"`
33+
3334
// remove at the same time as BatcherConfig
3435
hasBatcher bool
3536
}
3637

3738
func (c *Config) Unmarshal(conf *confmap.Conf) error {
39+
if conf.IsSet("batcher") {
40+
c.BatcherConfig = exporterhelper.NewDefaultBatcherConfig()
41+
c.BatcherConfig.Enabled = false
42+
c.hasBatcher = true
43+
}
44+
3845
if err := conf.Unmarshal(c); err != nil {
3946
return err
4047
}
4148

42-
if conf.IsSet("batcher") {
43-
fmt.Println("in here for sure")
44-
c.hasBatcher = true
45-
}
4649
return nil
4750
}
4851

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
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
}

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)