Skip to content

Deprecate BatcherConfig and WithBatcher in favor of the new QueueBatchConfig #12748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/codeboten_deprecate-batcher-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: otlpexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Mark BatcherConfig as deprecated, use `sending_queue::batch` instead

# One or more tracking issues or pull requests related to the change
issues: [12726]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
25 changes: 25 additions & 0 deletions .chloggen/deprecate-batcher-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: exporterhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate BatcherConfig and WithBatcher in favor of the new QueueBatchConfig.

# One or more tracking issues or pull requests related to the change
issues: [12748]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
4 changes: 2 additions & 2 deletions exporter/exporterbatcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// Deprecated: [v0.123.0] use exporterhelper.BatcherConfig
type Config = exporterhelper.BatcherConfig
type Config = exporterhelper.BatcherConfig //nolint:staticcheck

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

// Deprecated: [v0.123.0] use exporterhelper.NewDefaultBatcherConfig
var NewDefaultConfig = exporterhelper.NewDefaultBatcherConfig
var NewDefaultConfig = exporterhelper.NewDefaultBatcherConfig //nolint:staticcheck
8 changes: 4 additions & 4 deletions exporter/exporterhelper/internal/queue_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@
}

func (c *BatcherConfig) Validate() error {
if !c.Enabled {
return nil
}

Check warning on line 130 in exporter/exporterhelper/internal/queue_sender.go

View check run for this annotation

Codecov / codecov/patch

exporter/exporterhelper/internal/queue_sender.go#L129-L130

Added lines #L129 - L130 were not covered by tests

if c.FlushTimeout <= 0 {
return errors.New("`flush_timeout` must be greater than zero")
}

return nil
}

func (c SizeConfig) Validate() error {
if c.Sizer != request.SizerTypeItems {
return fmt.Errorf("unsupported sizer type: %q", c.Sizer)
}
Expand Down
49 changes: 33 additions & 16 deletions exporter/exporterhelper/internal/queue_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -71,31 +72,47 @@ func TestBatcherConfig_Validate(t *testing.T) {
}

func TestSizeConfig_Validate(t *testing.T) {
cfg := SizeConfig{
Sizer: request.SizerTypeBytes,
MaxSize: 10,
MinSize: 100,
cfg := BatcherConfig{
Enabled: true,
FlushTimeout: 200 * time.Millisecond,
SizeConfig: SizeConfig{
Sizer: request.SizerTypeBytes,
MinSize: 100,
MaxSize: 1000,
},
}
require.EqualError(t, cfg.Validate(), "unsupported sizer type: {\"bytes\"}")

cfg = SizeConfig{
Sizer: request.SizerTypeItems,
MaxSize: -100,
MinSize: 100,
cfg = BatcherConfig{
Enabled: true,
FlushTimeout: 200 * time.Millisecond,
SizeConfig: SizeConfig{
Sizer: request.SizerTypeItems,
MinSize: 100,
MaxSize: -1000,
},
}
require.EqualError(t, cfg.Validate(), "`max_size` must be greater than or equal to zero")

cfg = SizeConfig{
Sizer: request.SizerTypeItems,
MaxSize: 100,
MinSize: -100,
cfg = BatcherConfig{
Enabled: true,
FlushTimeout: 200 * time.Millisecond,
SizeConfig: SizeConfig{
Sizer: request.SizerTypeItems,
MinSize: -100,
MaxSize: 1000,
},
}
require.EqualError(t, cfg.Validate(), "`min_size` must be greater than or equal to zero")

cfg = SizeConfig{
Sizer: request.SizerTypeItems,
MaxSize: 100,
MinSize: 200,
cfg = BatcherConfig{
Enabled: true,
FlushTimeout: 200 * time.Millisecond,
SizeConfig: SizeConfig{
Sizer: request.SizerTypeItems,
MinSize: 1000,
MaxSize: 100,
},
}
require.EqualError(t, cfg.Validate(), "`max_size` must be greater than or equal to mix_size")
}
14 changes: 6 additions & 8 deletions exporter/exporterhelper/queue_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ func WithQueue(config QueueBatchConfig) Option {
return internal.WithQueue(config)
}

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

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

// BatchConfig defines a configuration for batching requests based on a timeout and a minimum number of items.
type BatchConfig = queuebatch.BatchConfig

// QueueBatchEncoding defines the encoding to be used if persistent queue is configured.
// Duplicate definition with queuebatch.Encoding since aliasing generics is not supported by default.
type QueueBatchEncoding[T any] interface {
Expand Down Expand Up @@ -63,14 +62,13 @@ func WithQueueBatch(cfg QueueBatchConfig, set QueueBatchSettings) Option {
// By default, the queue stores 1000 items of telemetry and is non-blocking when full.
var NewDefaultQueueConfig = internal.NewDefaultQueueConfig

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

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

// Deprecated: [v0.123.0] use WithQueueBatch.
var NewDefaultBatcherConfig = internal.NewDefaultBatcherConfig
22 changes: 21 additions & 1 deletion exporter/otlpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

Expand All @@ -26,7 +27,26 @@

// Experimental: This configuration is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved
BatcherConfig exporterhelper.BatcherConfig `mapstructure:"batcher"`
//
// Deprecated: [v0.123.0] batch configuration moving to queue configuration.
BatcherConfig exporterhelper.BatcherConfig `mapstructure:"batcher"` //nolint:staticcheck

// remove at the same time as BatcherConfig
hasBatcher bool
}

func (c *Config) Unmarshal(conf *confmap.Conf) error {
if conf.IsSet("batcher") {
c.BatcherConfig = exporterhelper.NewDefaultBatcherConfig() //nolint:staticcheck
c.BatcherConfig.Enabled = false
c.hasBatcher = true
}

Check warning on line 43 in exporter/otlpexporter/config.go

View check run for this annotation

Codecov / codecov/patch

exporter/otlpexporter/config.go#L40-L43

Added lines #L40 - L43 were not covered by tests

if err := conf.Unmarshal(c); err != nil {
return err
}

Check warning on line 47 in exporter/otlpexporter/config.go

View check run for this annotation

Codecov / codecov/patch

exporter/otlpexporter/config.go#L46-L47

Added lines #L46 - L47 were not covered by tests

return nil
}

func (c *Config) Validate() error {
Expand Down
16 changes: 6 additions & 10 deletions exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@ func TestUnmarshalConfig(t *testing.T) {
},
QueueConfig: exporterhelper.QueueBatchConfig{
Enabled: true,
Sizer: exporterhelper.RequestSizerTypeRequests,
Sizer: exporterhelper.RequestSizerTypeItems,
NumConsumers: 2,
QueueSize: 10,
},
BatcherConfig: exporterhelper.BatcherConfig{
Enabled: true,
FlushTimeout: 200 * time.Millisecond,
SizeConfig: exporterhelper.SizeConfig{
Sizer: exporterhelper.RequestSizerTypeItems,
MinSize: 1000,
MaxSize: 10000,
QueueSize: 100000,
Batch: &exporterhelper.BatchConfig{
FlushTimeout: 200 * time.Millisecond,
MinSize: 1000,
MaxSize: 10000,
},
},
ClientConfig: configgrpc.ClientConfig{
Expand Down
12 changes: 4 additions & 8 deletions exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ func NewFactory() exporter.Factory {
}

func createDefaultConfig() component.Config {
batcherCfg := exporterhelper.NewDefaultBatcherConfig()
batcherCfg.Enabled = false

clientCfg := *configgrpc.NewDefaultClientConfig()
// Default to gzip compression
clientCfg.Compression = configcompression.TypeGzip
Expand All @@ -47,7 +44,6 @@ func createDefaultConfig() component.Config {
TimeoutConfig: exporterhelper.NewDefaultTimeoutConfig(),
RetryConfig: configretry.NewDefaultBackOffConfig(),
QueueConfig: exporterhelper.NewDefaultQueueConfig(),
BatcherConfig: batcherCfg,
ClientConfig: clientCfg,
}
}
Expand All @@ -65,7 +61,7 @@ func createTraces(
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
exporterhelper.WithRetry(oCfg.RetryConfig),
exporterhelper.WithQueue(oCfg.QueueConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown),
)
Expand All @@ -84,7 +80,7 @@ func createMetrics(
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
exporterhelper.WithRetry(oCfg.RetryConfig),
exporterhelper.WithQueue(oCfg.QueueConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown),
)
Expand All @@ -103,7 +99,7 @@ func createLogs(
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
exporterhelper.WithRetry(oCfg.RetryConfig),
exporterhelper.WithQueue(oCfg.QueueConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown),
)
Expand All @@ -122,7 +118,7 @@ func createProfilesExporter(
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
exporterhelper.WithRetry(oCfg.RetryConfig),
exporterhelper.WithQueue(oCfg.QueueConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown),
)
Expand Down
4 changes: 4 additions & 0 deletions exporter/otlpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
func newExporter(cfg component.Config, set exporter.Settings) *baseExporter {
oCfg := cfg.(*Config)

if oCfg.hasBatcher {
set.TelemetrySettings.Logger.Warn("using deprecated field: batcher")
}

Check warning on line 58 in exporter/otlpexporter/otlp.go

View check run for this annotation

Codecov / codecov/patch

exporter/otlpexporter/otlp.go#L57-L58

Added lines #L57 - L58 were not covered by tests

userAgent := fmt.Sprintf("%s/%s (%s/%s)",
set.BuildInfo.Description, set.BuildInfo.Version, runtime.GOOS, runtime.GOARCH)

Expand Down
13 changes: 6 additions & 7 deletions exporter/otlpexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ tls:
timeout: 10s
sending_queue:
enabled: true
sizer: "items"
num_consumers: 2
queue_size: 10
queue_size: 100000
batch:
flush_timeout: 200ms
min_size: 1000
max_size: 10000
retry_on_failure:
enabled: true
initial_interval: 10s
randomization_factor: 0.7
multiplier: 1.3
max_interval: 60s
max_elapsed_time: 10m
batcher:
enabled: true
flush_timeout: 200ms
sizer: "items"
min_size: 1000
max_size: 10000
auth:
authenticator: nop
headers:
Expand Down
Loading