Skip to content

Commit 17f5d46

Browse files
committed
Deprecated everything in exporterbatcher, alias from exporterhelper
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent cb90fb5 commit 17f5d46

40 files changed

+378
-363
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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: exporterbatcher
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecated Config, SizeConfig, SizerType, SizerType[Requests|Items|Bytes], NewDefaultConfig. Use alias from exporterhelper.
11+
12+
13+
# One or more tracking issues or pull requests related to the change
14+
issues: [12707]
15+
16+
# (Optional) One or more lines of additional information to render under the primary note.
17+
# These lines will be padded with 2 spaces and then inserted directly into the document.
18+
# Use pipe (|) for multiline entries.
19+
subtext:
20+
21+
# Optional: The change log or logs in which this entry should be included.
22+
# e.g. '[user]' or '[user, api]'
23+
# Include 'user' if the change is relevant to end users.
24+
# Include 'api' if there is a change to a library API.
25+
# Default: '[user]'
26+
change_logs: [api]

exporter/exporterbatcher/config.go

+15-55
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,26 @@
44
package exporterbatcher // import "go.opentelemetry.io/collector/exporter/exporterbatcher"
55

66
import (
7-
"errors"
8-
"fmt"
9-
"time"
7+
"go.opentelemetry.io/collector/exporter/exporterhelper"
108
)
119

12-
// Config defines a configuration for batching requests based on a timeout and a minimum number of items.
13-
// Experimental: This API is at the early stage of development and may change without backward compatibility
14-
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
15-
type Config struct {
16-
// Enabled indicates whether to not enqueue batches before sending to the consumerSender.
17-
Enabled bool `mapstructure:"enabled"`
10+
// Deprecated: [v0.123.0] use exporterhelper.BatcherConfig
11+
type Config = exporterhelper.BatcherConfig
1812

19-
// FlushTimeout sets the time after which a batch will be sent regardless of its size.
20-
FlushTimeout time.Duration `mapstructure:"flush_timeout"`
13+
// Deprecated: [v0.123.0] use exporterhelper.SizeConfig
14+
type SizeConfig = exporterhelper.SizeConfig
2115

22-
// SizeConfig sets the size limits for a batch.
23-
SizeConfig `mapstructure:",squash"`
24-
}
16+
// Deprecated: [v0.123.0] use exporterhelper.RequestSizerType
17+
type SizerType = exporterhelper.RequestSizerType
2518

26-
// SizeConfig sets the size limits for a batch.
27-
type SizeConfig struct {
28-
Sizer SizerType `mapstructure:"sizer"`
19+
// Deprecated: [v0.123.0] use exporterhelper.RequestSizerTypeRequests
20+
var SizerTypeRequests = exporterhelper.RequestSizerTypeRequests
2921

30-
// MinSize defines the configuration for the minimum size of a batch.
31-
MinSize int `mapstructure:"min_size"`
32-
// MaxSize defines the configuration for the maximum size of a batch.
33-
MaxSize int `mapstructure:"max_size"`
34-
}
22+
// Deprecated: [v0.123.0] use exporterhelper.RequestSizerTypeItems
23+
var SizerTypeItems = exporterhelper.RequestSizerTypeItems
3524

36-
func (c *Config) Validate() error {
37-
if c.FlushTimeout <= 0 {
38-
return errors.New("`flush_timeout` must be greater than zero")
39-
}
25+
// Deprecated: [v0.123.0] use exporterhelper.RequestSizerTypeRequests
26+
var SizerTypeBytes = exporterhelper.RequestSizerTypeBytes
4027

41-
return nil
42-
}
43-
44-
func (c SizeConfig) Validate() error {
45-
if c.Sizer != SizerTypeItems {
46-
return fmt.Errorf("unsupported sizer type: %q", c.Sizer)
47-
}
48-
if c.MinSize < 0 {
49-
return errors.New("`min_size` must be greater than or equal to zero")
50-
}
51-
if c.MaxSize < 0 {
52-
return errors.New("`max_size` must be greater than or equal to zero")
53-
}
54-
if c.MaxSize != 0 && c.MaxSize < c.MinSize {
55-
return errors.New("`max_size` must be greater than or equal to mix_size")
56-
}
57-
return nil
58-
}
59-
60-
func NewDefaultConfig() Config {
61-
return Config{
62-
Enabled: true,
63-
FlushTimeout: 200 * time.Millisecond,
64-
SizeConfig: SizeConfig{
65-
Sizer: SizerTypeItems,
66-
MinSize: 8192,
67-
},
68-
}
69-
}
28+
// Deprecated: [v0.123.0] use exporterhelper.NewDefaultBatcherConfig
29+
var NewDefaultConfig = exporterhelper.NewDefaultBatcherConfig

exporter/exporterbatcher/config_test.go

-49
This file was deleted.

exporter/exporterhelper/common.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"go.opentelemetry.io/collector/component"
88
"go.opentelemetry.io/collector/config/configretry"
99
"go.opentelemetry.io/collector/consumer"
10-
"go.opentelemetry.io/collector/exporter/exporterbatcher"
1110
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
1211
)
1312

@@ -57,6 +56,6 @@ func WithCapabilities(capabilities consumer.Capabilities) Option {
5756
// WithRequestBatchFuncs provided.
5857
// This API is at the early stage of development and may change without backward compatibility
5958
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
60-
func WithBatcher(cfg exporterbatcher.Config) Option {
59+
func WithBatcher(cfg BatcherConfig) Option {
6160
return internal.WithBatcher(cfg)
6261
}

exporter/exporterhelper/internal/base_exporter.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ 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"
1817
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
1918
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
2019
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/sender"
@@ -50,7 +49,7 @@ type BaseExporter struct {
5049

5150
queueBatchSettings QueueBatchSettings[request.Request]
5251
queueCfg exporterqueue.Config
53-
batcherCfg exporterbatcher.Config
52+
batcherCfg BatcherConfig
5453
}
5554

5655
func NewBaseExporter(set exporter.Settings, signal pipeline.Signal, pusher sender.SendFunc[request.Request], options ...Option) (*BaseExporter, error) {
@@ -238,7 +237,7 @@ func WithCapabilities(capabilities consumer.Capabilities) Option {
238237
// WithRequestBatchFuncs provided.
239238
// This API is at the early stage of development and may change without backward compatibility
240239
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
241-
func WithBatcher(cfg exporterbatcher.Config) Option {
240+
func WithBatcher(cfg BatcherConfig) Option {
242241
return func(o *BaseExporter) error {
243242
o.batcherCfg = cfg
244243
return nil

exporter/exporterhelper/internal/base_exporter_test.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"go.opentelemetry.io/collector/component"
1717
"go.opentelemetry.io/collector/component/componenttest"
1818
"go.opentelemetry.io/collector/config/configretry"
19-
"go.opentelemetry.io/collector/exporter/exporterbatcher"
20-
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
2119
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
2220
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/requesttest"
2321
"go.opentelemetry.io/collector/exporter/exporterqueue"
@@ -75,7 +73,7 @@ func TestBaseExporterLogging(t *testing.T) {
7573
bs, err := NewBaseExporter(set, pipeline.SignalMetrics, errExport,
7674
WithQueueBatchSettings(newFakeQueueBatch()),
7775
WithQueue(qCfg),
78-
WithBatcher(exporterbatcher.NewDefaultConfig()),
76+
WithBatcher(NewDefaultBatcherConfig()),
7977
WithRetry(rCfg))
8078
require.NoError(t, err)
8179
require.NoError(t, bs.Start(context.Background(), componenttest.NewNopHost()))
@@ -105,7 +103,7 @@ func TestQueueRetryWithDisabledQueue(t *testing.T) {
105103
return WithQueue(qs)
106104
}(),
107105
func() Option {
108-
bs := exporterbatcher.NewDefaultConfig()
106+
bs := NewDefaultBatcherConfig()
109107
bs.Enabled = false
110108
return WithBatcher(bs)
111109
}(),
@@ -120,7 +118,7 @@ func TestQueueRetryWithDisabledQueue(t *testing.T) {
120118
return WithQueueBatch(qs, newFakeQueueBatch())
121119
}(),
122120
func() Option {
123-
bs := exporterbatcher.NewDefaultConfig()
121+
bs := NewDefaultBatcherConfig()
124122
bs.Enabled = false
125123
return WithBatcher(bs)
126124
}(),
@@ -156,8 +154,8 @@ func noopExport(context.Context, request.Request) error {
156154
func newFakeQueueBatch() QueueBatchSettings[request.Request] {
157155
return QueueBatchSettings[request.Request]{
158156
Encoding: fakeEncoding{},
159-
Sizers: map[exporterbatcher.SizerType]queuebatch.Sizer[request.Request]{
160-
exporterbatcher.SizerTypeRequests: queuebatch.RequestsSizer[request.Request]{},
157+
Sizers: map[request.SizerType]request.Sizer[request.Request]{
158+
request.SizerTypeRequests: request.RequestsSizer[request.Request]{},
161159
},
162160
}
163161
}

exporter/exporterhelper/internal/queue_sender.go

+67-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ package internal // import "go.opentelemetry.io/collector/exporter/exporterhelpe
55

66
import (
77
"context"
8+
"errors"
9+
"fmt"
10+
"time"
811

912
"go.uber.org/zap"
1013

11-
"go.opentelemetry.io/collector/exporter/exporterbatcher"
1214
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
1315
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
1416
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/sender"
@@ -17,14 +19,14 @@ import (
1719

1820
// QueueBatchSettings is a subset of the queuebatch.Settings that are needed when used within an Exporter.
1921
type QueueBatchSettings[K any] struct {
20-
Encoding exporterqueue.Encoding[K]
21-
Sizers map[exporterbatcher.SizerType]queuebatch.Sizer[K]
22+
Encoding queuebatch.Encoding[K]
23+
Sizers map[request.SizerType]request.Sizer[K]
2224
}
2325

2426
func NewQueueSender(
2527
qSet queuebatch.Settings[request.Request],
2628
qCfg exporterqueue.Config,
27-
bCfg exporterbatcher.Config,
29+
bCfg BatcherConfig,
2830
exportFailureMessage string,
2931
next sender.Sender[request.Request],
3032
) (sender.Sender[request.Request], error) {
@@ -43,11 +45,11 @@ func NewQueueSender(
4345
return queuebatch.NewQueueBatch(qSet, newQueueBatchConfig(qCfg, bCfg), exportFunc)
4446
}
4547

46-
func newQueueBatchConfig(qCfg exporterqueue.Config, bCfg exporterbatcher.Config) queuebatch.Config {
48+
func newQueueBatchConfig(qCfg exporterqueue.Config, bCfg BatcherConfig) queuebatch.Config {
4749
qbCfg := queuebatch.Config{
4850
Enabled: true,
4951
WaitForResult: !qCfg.Enabled,
50-
Sizer: exporterbatcher.SizerTypeRequests,
52+
Sizer: request.SizerTypeRequests,
5153
QueueSize: qCfg.QueueSize,
5254
NumConsumers: qCfg.NumConsumers,
5355
BlockOnOverflow: qCfg.Blocking,
@@ -65,3 +67,62 @@ func newQueueBatchConfig(qCfg exporterqueue.Config, bCfg exporterbatcher.Config)
6567
}
6668
return qbCfg
6769
}
70+
71+
// BatcherConfig defines a configuration for batching requests based on a timeout and a minimum number of items.
72+
// Experimental: This API is at the early stage of development and may change without backward compatibility
73+
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
74+
type BatcherConfig struct {
75+
// Enabled indicates whether to not enqueue batches before sending to the consumerSender.
76+
Enabled bool `mapstructure:"enabled"`
77+
78+
// FlushTimeout sets the time after which a batch will be sent regardless of its size.
79+
FlushTimeout time.Duration `mapstructure:"flush_timeout"`
80+
81+
// SizeConfig sets the size limits for a batch.
82+
SizeConfig `mapstructure:",squash"`
83+
}
84+
85+
// SizeConfig sets the size limits for a batch.
86+
type SizeConfig struct {
87+
Sizer request.SizerType `mapstructure:"sizer"`
88+
89+
// MinSize defines the configuration for the minimum size of a batch.
90+
MinSize int `mapstructure:"min_size"`
91+
// MaxSize defines the configuration for the maximum size of a batch.
92+
MaxSize int `mapstructure:"max_size"`
93+
}
94+
95+
func (c *BatcherConfig) Validate() error {
96+
if c.FlushTimeout <= 0 {
97+
return errors.New("`flush_timeout` must be greater than zero")
98+
}
99+
100+
return nil
101+
}
102+
103+
func (c SizeConfig) Validate() error {
104+
if c.Sizer != request.SizerTypeItems {
105+
return fmt.Errorf("unsupported sizer type: %q", c.Sizer)
106+
}
107+
if c.MinSize < 0 {
108+
return errors.New("`min_size` must be greater than or equal to zero")
109+
}
110+
if c.MaxSize < 0 {
111+
return errors.New("`max_size` must be greater than or equal to zero")
112+
}
113+
if c.MaxSize != 0 && c.MaxSize < c.MinSize {
114+
return errors.New("`max_size` must be greater than or equal to mix_size")
115+
}
116+
return nil
117+
}
118+
119+
func NewDefaultBatcherConfig() BatcherConfig {
120+
return BatcherConfig{
121+
Enabled: true,
122+
FlushTimeout: 200 * time.Millisecond,
123+
SizeConfig: SizeConfig{
124+
Sizer: request.SizerTypeItems,
125+
MinSize: 8192,
126+
},
127+
}
128+
}

0 commit comments

Comments
 (0)