Skip to content

Commit

Permalink
Enable batch sender in oltpexporter (#10846)
Browse files Browse the repository at this point in the history
#### Description

This PR adds opt-in support to oltp exporter for the experimental batch
sender
(#8122).
By default batch sender is not enabled.

Similar:
*
open-telemetry/opentelemetry-collector-contrib#34238
*
open-telemetry/opentelemetry-collector-contrib#32563

#### Link to tracking issue

Resolves
#10834

#### Testing

`exporter/otlpexporter/config_test.go`

#### Documentation

Updated the `oltpexporter` README to point to `exporterhelper` README
for batching.

---------

Co-authored-by: Dmitrii Anoshin <[email protected]>
  • Loading branch information
sfc-gh-sili and dmitryax authored Aug 17, 2024
1 parent 8506809 commit d2ed276
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .chloggen/add-batching-option-to-otlp-exporter.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: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add batching option to otlp exporter"

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

# (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]
2 changes: 1 addition & 1 deletion exporter/otlpexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ Several helper files are leveraged to provide additional capabilities automatica

- [gRPC settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configgrpc/README.md)
- [TLS and mTLS settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/README.md)
- [Queuing, retry and timeout settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md)
- [Queuing, batching, retry and timeout settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md)
5 changes: 5 additions & 0 deletions exporter/otlpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter/exporterbatcher"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

Expand All @@ -23,6 +24,10 @@ type Config struct {
QueueConfig exporterhelper.QueueSettings `mapstructure:"sending_queue"`
RetryConfig configretry.BackOffConfig `mapstructure:"retry_on_failure"`

// 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 exporterbatcher.Config `mapstructure:"batcher"`

configgrpc.ClientConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
}

Expand Down
11 changes: 11 additions & 0 deletions exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/exporter/exporterbatcher"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

Expand Down Expand Up @@ -53,6 +54,16 @@ func TestUnmarshalConfig(t *testing.T) {
NumConsumers: 2,
QueueSize: 10,
},
BatcherConfig: exporterbatcher.Config{
Enabled: true,
FlushTimeout: 200 * time.Millisecond,
MinSizeConfig: exporterbatcher.MinSizeConfig{
MinSizeItems: 1000,
},
MaxSizeConfig: exporterbatcher.MaxSizeConfig{
MaxSizeItems: 10000,
},
},
ClientConfig: configgrpc.ClientConfig{
Headers: map[string]configopaque.String{
"can you have a . here?": "F0000000-0000-0000-0000-000000000000",
Expand Down
11 changes: 10 additions & 1 deletion exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterbatcher"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/otlpexporter/internal/metadata"
)
Expand All @@ -29,10 +30,14 @@ func NewFactory() exporter.Factory {
}

func createDefaultConfig() component.Config {
batcherCfg := exporterbatcher.NewDefaultConfig()
batcherCfg.Enabled = false

return &Config{
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
RetryConfig: configretry.NewDefaultBackOffConfig(),
QueueConfig: exporterhelper.NewDefaultQueueSettings(),
BatcherConfig: batcherCfg,
ClientConfig: configgrpc.ClientConfig{
Headers: map[string]configopaque.String{},
// Default to gzip compression
Expand All @@ -56,8 +61,10 @@ func createTracesExporter(
exporterhelper.WithTimeout(oCfg.TimeoutSettings),
exporterhelper.WithRetry(oCfg.RetryConfig),
exporterhelper.WithQueue(oCfg.QueueConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown))
exporterhelper.WithShutdown(oce.shutdown),
)
}

func createMetricsExporter(
Expand All @@ -73,6 +80,7 @@ func createMetricsExporter(
exporterhelper.WithTimeout(oCfg.TimeoutSettings),
exporterhelper.WithRetry(oCfg.RetryConfig),
exporterhelper.WithQueue(oCfg.QueueConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown),
)
Expand All @@ -91,6 +99,7 @@ func createLogsExporter(
exporterhelper.WithTimeout(oCfg.TimeoutSettings),
exporterhelper.WithRetry(oCfg.RetryConfig),
exporterhelper.WithQueue(oCfg.QueueConfig),
exporterhelper.WithBatcher(oCfg.BatcherConfig),
exporterhelper.WithStart(oce.start),
exporterhelper.WithShutdown(oce.shutdown),
)
Expand Down
5 changes: 5 additions & 0 deletions exporter/otlpexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ retry_on_failure:
multiplier: 1.3
max_interval: 60s
max_elapsed_time: 10m
batcher:
enabled: true
flush_timeout: 200ms
min_size_items: 1000
max_size_items: 10000
auth:
authenticator: nop
headers:
Expand Down

0 comments on commit d2ed276

Please sign in to comment.