Skip to content

Commit abcee1f

Browse files
authored
Deprecated everything in exporterbatcher, alias from exporterhelper (open-telemetry#12707)
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 2bc783c commit abcee1f

39 files changed

+393
-366
lines changed
Lines changed: 26 additions & 0 deletions
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

Lines changed: 15 additions & 55 deletions
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

Lines changed: 0 additions & 49 deletions
This file was deleted.

exporter/exporterhelper/internal/base_exporter.go

Lines changed: 2 additions & 3 deletions
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"
@@ -49,7 +48,7 @@ type BaseExporter struct {
4948

5049
queueBatchSettings QueueBatchSettings[request.Request]
5150
queueCfg QueueConfig
52-
batcherCfg exporterbatcher.Config
51+
batcherCfg BatcherConfig
5352
}
5453

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

exporter/exporterhelper/internal/base_exporter_test.go

Lines changed: 5 additions & 7 deletions
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/exportertest"
@@ -74,7 +72,7 @@ func TestBaseExporterLogging(t *testing.T) {
7472
bs, err := NewBaseExporter(set, pipeline.SignalMetrics, errExport,
7573
WithQueueBatchSettings(newFakeQueueBatch()),
7674
WithQueue(qCfg),
77-
WithBatcher(exporterbatcher.NewDefaultConfig()),
75+
WithBatcher(NewDefaultBatcherConfig()),
7876
WithRetry(rCfg))
7977
require.NoError(t, err)
8078
require.NoError(t, bs.Start(context.Background(), componenttest.NewNopHost()))
@@ -104,7 +102,7 @@ func TestQueueRetryWithDisabledQueue(t *testing.T) {
104102
return WithQueue(qs)
105103
}(),
106104
func() Option {
107-
bs := exporterbatcher.NewDefaultConfig()
105+
bs := NewDefaultBatcherConfig()
108106
bs.Enabled = false
109107
return WithBatcher(bs)
110108
}(),
@@ -119,7 +117,7 @@ func TestQueueRetryWithDisabledQueue(t *testing.T) {
119117
return WithQueueBatch(qs, newFakeQueueBatch())
120118
}(),
121119
func() Option {
122-
bs := exporterbatcher.NewDefaultConfig()
120+
bs := NewDefaultBatcherConfig()
123121
bs.Enabled = false
124122
return WithBatcher(bs)
125123
}(),
@@ -155,8 +153,8 @@ func noopExport(context.Context, request.Request) error {
155153
func newFakeQueueBatch() QueueBatchSettings[request.Request] {
156154
return QueueBatchSettings[request.Request]{
157155
Encoding: fakeEncoding{},
158-
Sizers: map[exporterbatcher.SizerType]queuebatch.Sizer[request.Request]{
159-
exporterbatcher.SizerTypeRequests: queuebatch.RequestsSizer[request.Request]{},
156+
Sizers: map[request.SizerType]request.Sizer[request.Request]{
157+
request.SizerTypeRequests: request.RequestsSizer[request.Request]{},
160158
},
161159
}
162160
}

exporter/exporterhelper/internal/queue_sender.go

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ package internal // import "go.opentelemetry.io/collector/exporter/exporterhelpe
66
import (
77
"context"
88
"errors"
9+
"fmt"
10+
"time"
911

1012
"go.uber.org/zap"
1113

1214
"go.opentelemetry.io/collector/component"
13-
"go.opentelemetry.io/collector/exporter/exporterbatcher"
1415
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
1516
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
1617
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/sender"
@@ -19,7 +20,7 @@ import (
1920
// QueueBatchSettings is a subset of the queuebatch.Settings that are needed when used within an Exporter.
2021
type QueueBatchSettings[K any] struct {
2122
Encoding queuebatch.Encoding[K]
22-
Sizers map[exporterbatcher.SizerType]queuebatch.Sizer[K]
23+
Sizers map[request.SizerType]request.Sizer[K]
2324
}
2425

2526
// NewDefaultQueueConfig returns the default config for QueueConfig.
@@ -72,7 +73,7 @@ func (qCfg *QueueConfig) Validate() error {
7273
func NewQueueSender(
7374
qSet queuebatch.Settings[request.Request],
7475
qCfg QueueConfig,
75-
bCfg exporterbatcher.Config,
76+
bCfg BatcherConfig,
7677
exportFailureMessage string,
7778
next sender.Sender[request.Request],
7879
) (sender.Sender[request.Request], error) {
@@ -91,11 +92,11 @@ func NewQueueSender(
9192
return queuebatch.NewQueueBatch(qSet, newQueueBatchConfig(qCfg, bCfg), exportFunc)
9293
}
9394

94-
func newQueueBatchConfig(qCfg QueueConfig, bCfg exporterbatcher.Config) queuebatch.Config {
95+
func newQueueBatchConfig(qCfg QueueConfig, bCfg BatcherConfig) queuebatch.Config {
9596
qbCfg := queuebatch.Config{
9697
Enabled: true,
9798
WaitForResult: !qCfg.Enabled,
98-
Sizer: exporterbatcher.SizerTypeRequests,
99+
Sizer: request.SizerTypeRequests,
99100
QueueSize: qCfg.QueueSize,
100101
NumConsumers: qCfg.NumConsumers,
101102
BlockOnOverflow: qCfg.Blocking,
@@ -110,3 +111,62 @@ func newQueueBatchConfig(qCfg QueueConfig, bCfg exporterbatcher.Config) queuebat
110111
}
111112
return qbCfg
112113
}
114+
115+
// BatcherConfig defines a configuration for batching requests based on a timeout and a minimum number of items.
116+
// Experimental: This API is at the early stage of development and may change without backward compatibility
117+
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
118+
type BatcherConfig struct {
119+
// Enabled indicates whether to not enqueue batches before sending to the consumerSender.
120+
Enabled bool `mapstructure:"enabled"`
121+
122+
// FlushTimeout sets the time after which a batch will be sent regardless of its size.
123+
FlushTimeout time.Duration `mapstructure:"flush_timeout"`
124+
125+
// SizeConfig sets the size limits for a batch.
126+
SizeConfig `mapstructure:",squash"`
127+
}
128+
129+
// SizeConfig sets the size limits for a batch.
130+
type SizeConfig struct {
131+
Sizer request.SizerType `mapstructure:"sizer"`
132+
133+
// MinSize defines the configuration for the minimum size of a batch.
134+
MinSize int `mapstructure:"min_size"`
135+
// MaxSize defines the configuration for the maximum size of a batch.
136+
MaxSize int `mapstructure:"max_size"`
137+
}
138+
139+
func (c *BatcherConfig) Validate() error {
140+
if c.FlushTimeout <= 0 {
141+
return errors.New("`flush_timeout` must be greater than zero")
142+
}
143+
144+
return nil
145+
}
146+
147+
func (c SizeConfig) Validate() error {
148+
if c.Sizer != request.SizerTypeItems {
149+
return fmt.Errorf("unsupported sizer type: %q", c.Sizer)
150+
}
151+
if c.MinSize < 0 {
152+
return errors.New("`min_size` must be greater than or equal to zero")
153+
}
154+
if c.MaxSize < 0 {
155+
return errors.New("`max_size` must be greater than or equal to zero")
156+
}
157+
if c.MaxSize != 0 && c.MaxSize < c.MinSize {
158+
return errors.New("`max_size` must be greater than or equal to mix_size")
159+
}
160+
return nil
161+
}
162+
163+
func NewDefaultBatcherConfig() BatcherConfig {
164+
return BatcherConfig{
165+
Enabled: true,
166+
FlushTimeout: 200 * time.Millisecond,
167+
SizeConfig: SizeConfig{
168+
Sizer: request.SizerTypeItems,
169+
MinSize: 8192,
170+
},
171+
}
172+
}

0 commit comments

Comments
 (0)